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(DWORD
);
1225 if( RegQueryValueExW( hKey
, reg_start_x
, NULL
, &type
,
1226 (LPBYTE
) &opts
.start_x
, &size
) != ERROR_SUCCESS
)
1227 opts
.start_x
= CW_USEDEFAULT
;
1229 if( RegQueryValueExW( hKey
, reg_start_y
, NULL
, &type
,
1230 (LPBYTE
) &opts
.start_y
, &size
) != ERROR_SUCCESS
)
1231 opts
.start_y
= CW_USEDEFAULT
;
1233 if( RegQueryValueExW( hKey
, reg_width
, NULL
, &type
,
1234 (LPBYTE
) &opts
.width
, &size
) != ERROR_SUCCESS
)
1235 opts
.width
= CW_USEDEFAULT
;
1237 if( RegQueryValueExW( hKey
, reg_height
, NULL
, &type
,
1238 (LPBYTE
) &opts
.height
, &size
) != ERROR_SUCCESS
)
1239 opts
.height
= CW_USEDEFAULT
;
1240 size
=sizeof(logfont
);
1241 if( RegQueryValueExW( hKey
, reg_logfont
, NULL
, &type
,
1242 (LPBYTE
) &logfont
, &size
) != ERROR_SUCCESS
)
1243 GetObjectW(GetStockObject(DEFAULT_GUI_FONT
),sizeof(logfont
),&logfont
);
1245 RegCloseKey( hKey
);
1247 Globals
.hfont
= CreateFontIndirectW(&logfont
);
1251 static void save_registry_settings(void)
1258 wi
.cbSize
= sizeof( WINDOWINFO
);
1259 GetWindowInfo(Globals
.hMainWnd
, &wi
);
1260 width
= wi
.rcWindow
.right
- wi
.rcWindow
.left
;
1261 height
= wi
.rcWindow
.bottom
- wi
.rcWindow
.top
;
1263 if ( RegOpenKeyExW( HKEY_CURRENT_USER
, registry_key
,
1264 0, KEY_SET_VALUE
, &hKey
) != ERROR_SUCCESS
)
1266 /* Unable to save registry settings - try to create key */
1267 if ( RegCreateKeyExW( HKEY_CURRENT_USER
, registry_key
,
1268 0, NULL
, REG_OPTION_NON_VOLATILE
,
1269 KEY_SET_VALUE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
1271 /* FIXME: Cannot create key */
1275 /* Save all of the settings */
1276 RegSetValueExW( hKey
, reg_start_x
, 0, REG_DWORD
,
1277 (LPBYTE
) &wi
.rcWindow
.left
, sizeof(DWORD
) );
1278 RegSetValueExW( hKey
, reg_start_y
, 0, REG_DWORD
,
1279 (LPBYTE
) &wi
.rcWindow
.top
, sizeof(DWORD
) );
1280 RegSetValueExW( hKey
, reg_width
, 0, REG_DWORD
,
1281 (LPBYTE
) &width
, sizeof(DWORD
) );
1282 RegSetValueExW( hKey
, reg_height
, 0, REG_DWORD
,
1283 (LPBYTE
) &height
, sizeof(DWORD
) );
1284 GetObjectW(Globals
.hfont
, sizeof(logfont
), &logfont
);
1285 RegSetValueExW( hKey
, reg_logfont
, 0, REG_BINARY
,
1286 (LPBYTE
)&logfont
, sizeof(LOGFONTW
) );
1288 /* TODO: Save more settings here (List vs. Detailed View, etc.) */
1289 RegCloseKey( hKey
);
1292 static void resize_frame_rect(HWND hwnd
, PRECT prect
)
1297 if (IsWindowVisible(Globals
.htoolbar
)) {
1298 SendMessageW(Globals
.htoolbar
, WM_SIZE
, 0, 0);
1299 GetClientRect(Globals
.htoolbar
, &rt
);
1300 prect
->top
= rt
.bottom
+3;
1301 prect
->bottom
-= rt
.bottom
+3;
1304 if (IsWindowVisible(Globals
.hdrivebar
)) {
1305 SendMessageW(Globals
.hdrivebar
, WM_SIZE
, 0, 0);
1306 GetClientRect(Globals
.hdrivebar
, &rt
);
1307 new_top
= --prect
->top
+ rt
.bottom
+3;
1308 MoveWindow(Globals
.hdrivebar
, 0, prect
->top
, rt
.right
, new_top
, TRUE
);
1309 prect
->top
= new_top
;
1310 prect
->bottom
-= rt
.bottom
+2;
1313 if (IsWindowVisible(Globals
.hstatusbar
)) {
1314 int parts
[] = {300, 500};
1316 SendMessageW(Globals
.hstatusbar
, WM_SIZE
, 0, 0);
1317 SendMessageW(Globals
.hstatusbar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
1318 GetClientRect(Globals
.hstatusbar
, &rt
);
1319 prect
->bottom
-= rt
.bottom
;
1322 MoveWindow(Globals
.hmdiclient
, prect
->left
-1,prect
->top
-1,prect
->right
+2,prect
->bottom
+1, TRUE
);
1325 static void resize_frame(HWND hwnd
, int cx
, int cy
)
1334 resize_frame_rect(hwnd
, &rect
);
1337 static void resize_frame_client(HWND hwnd
)
1341 GetClientRect(hwnd
, &rect
);
1343 resize_frame_rect(hwnd
, &rect
);
1347 static HHOOK hcbthook
;
1348 static ChildWnd
* newchild
= NULL
;
1350 static LRESULT CALLBACK
CBTProc(int code
, WPARAM wparam
, LPARAM lparam
)
1352 if (code
==HCBT_CREATEWND
&& newchild
) {
1353 ChildWnd
* child
= newchild
;
1356 child
->hwnd
= (HWND
) wparam
;
1357 SetWindowLongPtrW(child
->hwnd
, GWLP_USERDATA
, (LPARAM
)child
);
1360 return CallNextHookEx(hcbthook
, code
, wparam
, lparam
);
1363 static HWND
create_child_window(ChildWnd
* child
)
1365 MDICREATESTRUCTW mcs
;
1368 mcs
.szClass
= sWINEFILETREE
;
1369 mcs
.szTitle
= child
->path
;
1370 mcs
.hOwner
= Globals
.hInstance
;
1371 mcs
.x
= child
->pos
.rcNormalPosition
.left
;
1372 mcs
.y
= child
->pos
.rcNormalPosition
.top
;
1373 mcs
.cx
= child
->pos
.rcNormalPosition
.right
-child
->pos
.rcNormalPosition
.left
;
1374 mcs
.cy
= child
->pos
.rcNormalPosition
.bottom
-child
->pos
.rcNormalPosition
.top
;
1378 hcbthook
= SetWindowsHookExW(WH_CBT
, CBTProc
, 0, GetCurrentThreadId());
1381 child
->hwnd
= (HWND
)SendMessageW(Globals
.hmdiclient
, WM_MDICREATE
, 0, (LPARAM
)&mcs
);
1383 UnhookWindowsHookEx(hcbthook
);
1387 UnhookWindowsHookEx(hcbthook
);
1389 SendMessageW(child
->left
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1390 SendMessageW(child
->right
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1392 idx
= SendMessageW(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)child
->left
.cur
);
1393 SendMessageW(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
1398 #define RFF_NODEFAULT 0x02 /* No default item selected. */
1400 static void WineFile_OnRun( HWND hwnd
)
1402 static const WCHAR shell32_dll
[] = {'S','H','E','L','L','3','2','.','D','L','L',0};
1403 void (WINAPI
*pRunFileDlgAW
)(HWND
, HICON
, LPWSTR
, LPWSTR
, LPWSTR
, DWORD
);
1404 HMODULE hshell
= GetModuleHandleW( shell32_dll
);
1405 HICON hIcon
= LoadIconW(Globals
.hInstance
, MAKEINTRESOURCEW(IDI_WINEFILE
));
1407 pRunFileDlgAW
= (void*)GetProcAddress(hshell
, (LPCSTR
)61);
1408 if (pRunFileDlgAW
) pRunFileDlgAW( hwnd
, hIcon
, NULL
, NULL
, NULL
, RFF_NODEFAULT
);
1411 static INT_PTR CALLBACK
DestinationDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1413 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1417 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, lparam
);
1418 SetWindowTextW(GetDlgItem(hwnd
, 201), (LPCWSTR
)lparam
);
1422 int id
= (int)wparam
;
1426 LPWSTR dest
= (LPWSTR
)GetWindowLongPtrW(hwnd
, GWLP_USERDATA
);
1427 GetWindowTextW(GetDlgItem(hwnd
, 201), dest
, MAX_PATH
);
1428 EndDialog(hwnd
, id
);
1432 EndDialog(hwnd
, id
);
1436 MessageBoxW(hwnd
, RS(b1
,IDS_NO_IMPL
), RS(b2
,IDS_WINEFILE
), MB_OK
);
1448 struct FilterDialog
{
1449 WCHAR pattern
[MAX_PATH
];
1453 static INT_PTR CALLBACK
FilterDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1455 static struct FilterDialog
* dlg
;
1459 dlg
= (struct FilterDialog
*) lparam
;
1460 SetWindowTextW(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
);
1461 set_check(hwnd
, IDC_VIEW_TYPE_DIRECTORIES
, dlg
->flags
&TF_DIRECTORIES
);
1462 set_check(hwnd
, IDC_VIEW_TYPE_PROGRAMS
, dlg
->flags
&TF_PROGRAMS
);
1463 set_check(hwnd
, IDC_VIEW_TYPE_DOCUMENTS
, dlg
->flags
&TF_DOCUMENTS
);
1464 set_check(hwnd
, IDC_VIEW_TYPE_OTHERS
, dlg
->flags
&TF_OTHERS
);
1465 set_check(hwnd
, IDC_VIEW_TYPE_HIDDEN
, dlg
->flags
&TF_HIDDEN
);
1469 int id
= (int)wparam
;
1474 GetWindowTextW(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
, MAX_PATH
);
1476 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_DIRECTORIES
) ? TF_DIRECTORIES
: 0;
1477 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_PROGRAMS
) ? TF_PROGRAMS
: 0;
1478 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_DOCUMENTS
) ? TF_DOCUMENTS
: 0;
1479 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_OTHERS
) ? TF_OTHERS
: 0;
1480 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_HIDDEN
) ? TF_HIDDEN
: 0;
1484 EndDialog(hwnd
, id
);
1485 } else if (id
== IDCANCEL
)
1486 EndDialog(hwnd
, id
);
1495 struct PropertiesDialog
{
1496 WCHAR path
[MAX_PATH
];
1501 /* Structure used to store enumerated languages and code pages. */
1502 struct LANGANDCODEPAGE
{
1507 static LPCSTR InfoStrings
[] = {
1523 static void PropDlg_DisplayValue(HWND hlbox
, HWND hedit
)
1525 int idx
= SendMessageW(hlbox
, LB_GETCURSEL
, 0, 0);
1527 if (idx
!= LB_ERR
) {
1528 LPCWSTR pValue
= (LPCWSTR
)SendMessageW(hlbox
, LB_GETITEMDATA
, idx
, 0);
1531 SetWindowTextW(hedit
, pValue
);
1535 static void CheckForFileInfo(struct PropertiesDialog
* dlg
, HWND hwnd
, LPCWSTR strFilename
)
1537 static const WCHAR sBackSlash
[] = {'\\','\0'};
1538 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'};
1539 static const WCHAR sStringFileInfo
[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1540 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1541 static const WCHAR sFmt
[] = {'%','d','.','%','d','.','%','d','.','%','d','\0'};
1542 DWORD dwVersionDataLen
= GetFileVersionInfoSizeW(strFilename
, NULL
);
1544 if (dwVersionDataLen
) {
1545 dlg
->pVersionData
= HeapAlloc(GetProcessHeap(), 0, dwVersionDataLen
);
1547 if (GetFileVersionInfoW(strFilename
, 0, dwVersionDataLen
, dlg
->pVersionData
)) {
1551 if (VerQueryValueW(dlg
->pVersionData
, sBackSlash
, &pVal
, &nValLen
)) {
1552 if (nValLen
== sizeof(VS_FIXEDFILEINFO
)) {
1553 VS_FIXEDFILEINFO
* pFixedFileInfo
= (VS_FIXEDFILEINFO
*)pVal
;
1554 WCHAR buffer
[BUFFER_LEN
];
1556 swprintf(buffer
, ARRAY_SIZE(buffer
), sFmt
,
1557 HIWORD(pFixedFileInfo
->dwFileVersionMS
), LOWORD(pFixedFileInfo
->dwFileVersionMS
),
1558 HIWORD(pFixedFileInfo
->dwFileVersionLS
), LOWORD(pFixedFileInfo
->dwFileVersionLS
));
1560 SetDlgItemTextW(hwnd
, IDC_STATIC_PROP_VERSION
, buffer
);
1564 /* Read the list of languages and code pages. */
1565 if (VerQueryValueW(dlg
->pVersionData
, sTranslation
, &pVal
, &nValLen
)) {
1566 struct LANGANDCODEPAGE
* pTranslate
= (struct LANGANDCODEPAGE
*)pVal
;
1567 struct LANGANDCODEPAGE
* pEnd
= (struct LANGANDCODEPAGE
*)((LPBYTE
)pVal
+nValLen
);
1569 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
1571 /* Read the file description for each language and code page. */
1572 for(; pTranslate
<pEnd
; ++pTranslate
) {
1575 for(p
=InfoStrings
; *p
; ++p
) {
1576 WCHAR subblock
[200];
1581 LPCSTR pInfoString
= *p
;
1582 MultiByteToWideChar(CP_ACP
, 0, pInfoString
, -1, infoStr
, 100);
1583 wsprintfW(subblock
, sStringFileInfo
, pTranslate
->wLanguage
, pTranslate
->wCodePage
, infoStr
);
1585 /* Retrieve file description for language and code page */
1586 if (VerQueryValueW(dlg
->pVersionData
, subblock
, (PVOID
)&pTxt
, &nValLen
)) {
1587 int idx
= SendMessageW(hlbox
, LB_ADDSTRING
, 0L, (LPARAM
)infoStr
);
1588 SendMessageW(hlbox
, LB_SETITEMDATA
, idx
, (LPARAM
)pTxt
);
1593 SendMessageW(hlbox
, LB_SETCURSEL
, 0, 0);
1595 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
1601 static INT_PTR CALLBACK
PropertiesDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1603 static struct PropertiesDialog
* dlg
;
1606 case WM_INITDIALOG
: {
1607 static const WCHAR sByteFmt
[] = {'%','s',' ','B','y','t','e','s','\0'};
1608 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1609 LPWIN32_FIND_DATAW pWFD
;
1611 dlg
= (struct PropertiesDialog
*) lparam
;
1612 pWFD
= (LPWIN32_FIND_DATAW
)&dlg
->entry
.data
;
1614 GetWindowTextW(hwnd
, b1
, MAX_PATH
);
1615 wsprintfW(b2
, b1
, pWFD
->cFileName
);
1616 SetWindowTextW(hwnd
, b2
);
1618 format_date(&pWFD
->ftLastWriteTime
, b1
, COL_DATE
|COL_TIME
);
1619 SetWindowTextW(GetDlgItem(hwnd
, IDC_STATIC_PROP_LASTCHANGE
), b1
);
1621 format_longlong( b1
, ((ULONGLONG
)pWFD
->nFileSizeHigh
<< 32) | pWFD
->nFileSizeLow
);
1622 wsprintfW(b2
, sByteFmt
, b1
);
1623 SetWindowTextW(GetDlgItem(hwnd
, IDC_STATIC_PROP_SIZE
), b2
);
1625 SetWindowTextW(GetDlgItem(hwnd
, IDC_STATIC_PROP_FILENAME
), pWFD
->cFileName
);
1626 SetWindowTextW(GetDlgItem(hwnd
, IDC_STATIC_PROP_PATH
), dlg
->path
);
1628 set_check(hwnd
, IDC_CHECK_READONLY
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_READONLY
);
1629 set_check(hwnd
, IDC_CHECK_ARCHIVE
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_ARCHIVE
);
1630 set_check(hwnd
, IDC_CHECK_COMPRESSED
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_COMPRESSED
);
1631 set_check(hwnd
, IDC_CHECK_HIDDEN
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_HIDDEN
);
1632 set_check(hwnd
, IDC_CHECK_SYSTEM
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_SYSTEM
);
1634 CheckForFileInfo(dlg
, hwnd
, dlg
->path
);
1638 int id
= (int)wparam
;
1640 switch(HIWORD(wparam
)) {
1641 case LBN_SELCHANGE
: {
1642 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
1643 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
1648 if (id
==IDOK
|| id
==IDCANCEL
)
1649 EndDialog(hwnd
, id
);
1655 HeapFree(GetProcessHeap(), 0, dlg
->pVersionData
);
1656 dlg
->pVersionData
= NULL
;
1663 static void show_properties_dlg(Entry
* entry
, HWND hwnd
)
1665 struct PropertiesDialog dlg
;
1667 memset(&dlg
, 0, sizeof(struct PropertiesDialog
));
1668 get_path(entry
, dlg
.path
);
1669 memcpy(&dlg
.entry
, entry
, sizeof(Entry
));
1671 DialogBoxParamW(Globals
.hInstance
, MAKEINTRESOURCEW(IDD_DIALOG_PROPERTIES
), hwnd
, PropertiesDialogDlgProc
, (LPARAM
)&dlg
);
1674 static struct FullScreenParameters
{
1684 static void frame_get_clientspace(HWND hwnd
, PRECT prect
)
1688 if (!IsIconic(hwnd
))
1689 GetClientRect(hwnd
, prect
);
1693 wp
.length
= sizeof(wp
);
1694 GetWindowPlacement(hwnd
, &wp
);
1696 prect
->left
= prect
->top
= 0;
1697 prect
->right
= wp
.rcNormalPosition
.right
-wp
.rcNormalPosition
.left
-
1698 2*(GetSystemMetrics(SM_CXSIZEFRAME
)+GetSystemMetrics(SM_CXEDGE
));
1699 prect
->bottom
= wp
.rcNormalPosition
.bottom
-wp
.rcNormalPosition
.top
-
1700 2*(GetSystemMetrics(SM_CYSIZEFRAME
)+GetSystemMetrics(SM_CYEDGE
))-
1701 GetSystemMetrics(SM_CYCAPTION
)-GetSystemMetrics(SM_CYMENUSIZE
);
1704 if (IsWindowVisible(Globals
.htoolbar
)) {
1705 GetClientRect(Globals
.htoolbar
, &rt
);
1706 prect
->top
+= rt
.bottom
+2;
1709 if (IsWindowVisible(Globals
.hdrivebar
)) {
1710 GetClientRect(Globals
.hdrivebar
, &rt
);
1711 prect
->top
+= rt
.bottom
+2;
1714 if (IsWindowVisible(Globals
.hstatusbar
)) {
1715 GetClientRect(Globals
.hstatusbar
, &rt
);
1716 prect
->bottom
-= rt
.bottom
;
1720 static BOOL
toggle_fullscreen(HWND hwnd
)
1724 if ((g_fullscreen
.mode
=!g_fullscreen
.mode
)) {
1725 GetWindowRect(hwnd
, &g_fullscreen
.orgPos
);
1726 g_fullscreen
.wasZoomed
= IsZoomed(hwnd
);
1728 Frame_CalcFrameClient(hwnd
, &rt
);
1729 MapWindowPoints( hwnd
, 0, (POINT
*)&rt
, 2 );
1731 rt
.left
= g_fullscreen
.orgPos
.left
-rt
.left
;
1732 rt
.top
= g_fullscreen
.orgPos
.top
-rt
.top
;
1733 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+g_fullscreen
.orgPos
.right
-rt
.right
;
1734 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+g_fullscreen
.orgPos
.bottom
-rt
.bottom
;
1736 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
1738 MoveWindow(hwnd
, g_fullscreen
.orgPos
.left
, g_fullscreen
.orgPos
.top
,
1739 g_fullscreen
.orgPos
.right
-g_fullscreen
.orgPos
.left
,
1740 g_fullscreen
.orgPos
.bottom
-g_fullscreen
.orgPos
.top
, TRUE
);
1742 if (g_fullscreen
.wasZoomed
)
1743 ShowWindow(hwnd
, WS_MAXIMIZE
);
1746 return g_fullscreen
.mode
;
1749 static void fullscreen_move(HWND hwnd
)
1752 GetWindowRect(hwnd
, &pos
);
1754 Frame_CalcFrameClient(hwnd
, &rt
);
1755 MapWindowPoints( hwnd
, 0, (POINT
*)&rt
, 2 );
1757 rt
.left
= pos
.left
-rt
.left
;
1758 rt
.top
= pos
.top
-rt
.top
;
1759 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+pos
.right
-rt
.right
;
1760 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+pos
.bottom
-rt
.bottom
;
1762 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
1765 static void toggle_child(HWND hwnd
, UINT cmd
, HWND hchild
)
1767 BOOL vis
= IsWindowVisible(hchild
);
1769 CheckMenuItem(Globals
.hMenuOptions
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
1771 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
1773 if (g_fullscreen
.mode
)
1774 fullscreen_move(hwnd
);
1776 resize_frame_client(hwnd
);
1779 static BOOL
activate_drive_window(LPCWSTR path
)
1781 WCHAR drv1
[_MAX_DRIVE
], drv2
[_MAX_DRIVE
];
1784 _wsplitpath(path
, drv1
, 0, 0, 0);
1786 /* search for an already open window for the same drive */
1787 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
1788 ChildWnd
* child
= (ChildWnd
*)GetWindowLongPtrW(child_wnd
, GWLP_USERDATA
);
1791 _wsplitpath(child
->root
.path
, drv2
, 0, 0, 0);
1793 if (!lstrcmpiW(drv2
, drv1
)) {
1794 SendMessageW(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
1796 if (IsIconic(child_wnd
))
1797 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
1807 static BOOL
activate_fs_window(LPCWSTR filesys
)
1811 /* search for an already open window of the given file system name */
1812 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
1813 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtrW(child_wnd
, GWLP_USERDATA
);
1816 if (!lstrcmpiW(child
->root
.fs
, filesys
)) {
1817 SendMessageW(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
1819 if (IsIconic(child_wnd
))
1820 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
1830 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1832 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1836 if (Globals
.saveSettings
)
1837 save_registry_settings();
1839 DestroyWindow(hwnd
);
1841 /* clear handle variables */
1842 Globals
.hMenuFrame
= 0;
1843 Globals
.hMenuView
= 0;
1844 Globals
.hMenuOptions
= 0;
1845 Globals
.hMainWnd
= 0;
1846 Globals
.hmdiclient
= 0;
1847 Globals
.hdrivebar
= 0;
1854 case WM_INITMENUPOPUP
: {
1855 HWND hwndClient
= (HWND
)SendMessageW(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
1857 if (!SendMessageW(hwndClient
, WM_INITMENUPOPUP
, wparam
, lparam
))
1862 UINT cmd
= LOWORD(wparam
);
1863 HWND hwndClient
= (HWND
)SendMessageW(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
1865 if (SendMessageW(hwndClient
, WM_DISPATCH_COMMAND
, wparam
, lparam
))
1868 if (cmd
>=ID_DRIVE_FIRST
&& cmd
<=ID_DRIVE_FIRST
+0xFF) {
1869 WCHAR drv
[_MAX_DRIVE
], path
[MAX_PATH
];
1871 LPCWSTR root
= Globals
.drives
;
1874 for(i
=cmd
-ID_DRIVE_FIRST
; i
--; root
++)
1878 if (activate_drive_window(root
))
1881 _wsplitpath(root
, drv
, 0, 0, 0);
1883 if (!SetCurrentDirectoryW(drv
)) {
1884 display_error(hwnd
, GetLastError());
1888 GetCurrentDirectoryW(MAX_PATH
, path
); /*TODO: store last directory per drive */
1889 child
= alloc_child_window(path
, NULL
, hwnd
);
1891 if (!create_child_window(child
))
1892 HeapFree(GetProcessHeap(), 0, child
);
1893 } else switch(cmd
) {
1895 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
1898 case ID_WINDOW_NEW
: {
1899 WCHAR path
[MAX_PATH
];
1902 GetCurrentDirectoryW(MAX_PATH
, path
);
1903 child
= alloc_child_window(path
, NULL
, hwnd
);
1905 if (!create_child_window(child
))
1906 HeapFree(GetProcessHeap(), 0, child
);
1913 case ID_WINDOW_CASCADE
:
1914 SendMessageW(Globals
.hmdiclient
, WM_MDICASCADE
, 0, 0);
1917 case ID_WINDOW_TILE_HORZ
:
1918 SendMessageW(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
1921 case ID_WINDOW_TILE_VERT
:
1922 SendMessageW(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
1925 case ID_WINDOW_ARRANGE
:
1926 SendMessageW(Globals
.hmdiclient
, WM_MDIICONARRANGE
, 0, 0);
1929 case ID_SELECT_FONT
:
1933 case ID_VIEW_TOOL_BAR
:
1934 toggle_child(hwnd
, cmd
, Globals
.htoolbar
);
1937 case ID_VIEW_DRIVE_BAR
:
1938 toggle_child(hwnd
, cmd
, Globals
.hdrivebar
);
1941 case ID_VIEW_STATUSBAR
:
1942 toggle_child(hwnd
, cmd
, Globals
.hstatusbar
);
1945 case ID_VIEW_SAVESETTINGS
:
1946 Globals
.saveSettings
= !Globals
.saveSettings
;
1947 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_SAVESETTINGS
,
1948 Globals
.saveSettings
? MF_CHECKED
: MF_UNCHECKED
);
1952 WineFile_OnRun( hwnd
);
1955 case ID_CONNECT_NETWORK_DRIVE
: {
1956 DWORD ret
= WNetConnectionDialog(hwnd
, RESOURCETYPE_DISK
);
1957 if (ret
== NO_ERROR
)
1959 else if (ret
!= (DWORD
)-1) {
1960 if (ret
== ERROR_EXTENDED_ERROR
)
1961 display_network_error(hwnd
);
1963 display_error(hwnd
, ret
);
1967 case ID_DISCONNECT_NETWORK_DRIVE
: {
1968 DWORD ret
= WNetDisconnectDialog(hwnd
, RESOURCETYPE_DISK
);
1969 if (ret
== NO_ERROR
)
1971 else if (ret
!= (DWORD
)-1) {
1972 if (ret
== ERROR_EXTENDED_ERROR
)
1973 display_network_error(hwnd
);
1975 display_error(hwnd
, ret
);
1980 WinHelpW(hwnd
, RS(b1
,IDS_WINEFILE
), HELP_INDEX
, 0);
1983 case ID_VIEW_FULLSCREEN
:
1984 CheckMenuItem(Globals
.hMenuOptions
, cmd
, toggle_fullscreen(hwnd
)?MF_CHECKED
:0);
1987 case ID_DRIVE_SHELL_NS
: {
1988 WCHAR path
[MAX_PATH
];
1991 if (activate_fs_window(RS(b1
,IDS_SHELL
)))
1994 GetCurrentDirectoryW(MAX_PATH
, path
);
1995 child
= alloc_child_window(path
, get_path_pidl(path
,hwnd
), hwnd
);
1997 if (!create_child_window(child
))
1998 HeapFree(GetProcessHeap(), 0, child
);
2001 /*TODO: There are even more menu items! */
2004 ShellAboutW(hwnd
, RS(b1
,IDS_WINEFILE
), NULL
,
2005 LoadImageW( Globals
.hInstance
, MAKEINTRESOURCEW(IDI_WINEFILE
),
2006 IMAGE_ICON
, 48, 48, LR_SHARED
));
2010 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2011 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2012 else */if ((cmd
<IDW_FIRST_CHILD
|| cmd
>=IDW_FIRST_CHILD
+0x100) &&
2013 (cmd
<SC_SIZE
|| cmd
>SC_RESTORE
))
2014 MessageBoxW(hwnd
, RS(b2
,IDS_NO_IMPL
), RS(b1
,IDS_WINEFILE
), MB_OK
);
2016 return DefFrameProcW(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2021 resize_frame(hwnd
, LOWORD(lparam
), HIWORD(lparam
));
2022 break; /* do not pass message to DefFrameProcW */
2024 case WM_DEVICECHANGE
:
2025 SendMessageW(hwnd
, WM_COMMAND
, MAKELONG(ID_REFRESH
,0), 0);
2028 case WM_GETMINMAXINFO
: {
2029 LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
2031 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2032 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2035 case FRM_CALC_CLIENT
:
2036 frame_get_clientspace(hwnd
, (PRECT
)lparam
);
2040 return DefFrameProcW(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2047 static WCHAR g_pos_names
[COLUMNS
][40] = {
2051 static const int g_pos_align
[] = {
2053 HDF_LEFT
, /* Name */
2054 HDF_RIGHT
, /* Size */
2055 HDF_LEFT
, /* CDate */
2056 HDF_LEFT
, /* ADate */
2057 HDF_LEFT
, /* MDate */
2058 HDF_LEFT
, /* Index */
2059 HDF_CENTER
, /* Links */
2060 HDF_CENTER
, /* Attributes */
2061 HDF_LEFT
/* Security */
2064 static void resize_tree(ChildWnd
* child
, int cx
, int cy
)
2066 HDWP hdwp
= BeginDeferWindowPos(4);
2076 cx
= child
->split_pos
+ SPLIT_WIDTH
/2;
2080 SendMessageW(child
->left
.hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hdl
);
2082 DeferWindowPos(hdwp
, child
->left
.hwndHeader
, wp
.hwndInsertAfter
,
2083 wp
.x
-1, wp
.y
, child
->split_pos
-SPLIT_WIDTH
/2+1, wp
.cy
, wp
.flags
);
2084 DeferWindowPos(hdwp
, child
->right
.hwndHeader
, wp
.hwndInsertAfter
,
2085 rt
.left
+cx
+1, wp
.y
, wp
.cx
-cx
+2, wp
.cy
, wp
.flags
);
2086 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
);
2087 DeferWindowPos(hdwp
, child
->right
.hwnd
, 0, rt
.left
+cx
+1, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
2089 EndDeferWindowPos(hdwp
);
2092 static HWND
create_header(HWND parent
, Pane
* pane
, UINT id
)
2097 HWND hwnd
= CreateWindowW(WC_HEADERW
, 0, WS_CHILD
|WS_VISIBLE
|HDS_HORZ
|HDS_FULLDRAG
/*TODO: |HDS_BUTTONS + sort orders*/,
2098 0, 0, 0, 0, parent
, (HMENU
)ULongToHandle(id
), Globals
.hInstance
, 0);
2102 SendMessageW(hwnd
, WM_SETFONT
, (WPARAM
)GetStockObject(DEFAULT_GUI_FONT
), FALSE
);
2104 hdi
.mask
= HDI_TEXT
|HDI_WIDTH
|HDI_FORMAT
;
2106 for(idx
=0; idx
<COLUMNS
; idx
++) {
2107 hdi
.pszText
= g_pos_names
[idx
];
2108 hdi
.fmt
= HDF_STRING
| g_pos_align
[idx
];
2109 hdi
.cxy
= pane
->widths
[idx
];
2110 pane
->widths_shown
[idx
] = hdi
.cxy
;
2111 SendMessageW(hwnd
, HDM_INSERTITEMW
, idx
, (LPARAM
)&hdi
);
2117 static void init_output(HWND hwnd
)
2119 static const WCHAR s1000
[] = {'1','0','0','0','\0'};
2122 HDC hdc
= GetDC(hwnd
);
2124 if (GetNumberFormatW(LOCALE_USER_DEFAULT
, 0, s1000
, 0, b
, 16) > 4)
2125 Globals
.num_sep
= b
[1];
2127 Globals
.num_sep
= '.';
2129 old_font
= SelectObject(hdc
, Globals
.hfont
);
2130 GetTextExtentPoint32W(hdc
, sSpace
, 1, &Globals
.spaceSize
);
2131 SelectObject(hdc
, old_font
);
2132 ReleaseDC(hwnd
, hdc
);
2135 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
);
2138 /* calculate preferred width for all visible columns */
2140 static BOOL
calc_widths(Pane
* pane
, BOOL anyway
)
2142 int col
, x
, cx
, spc
=3*Globals
.spaceSize
.cx
;
2143 int entries
= SendMessageW(pane
->hwnd
, LB_GETCOUNT
, 0, 0);
2144 int orgWidths
[COLUMNS
];
2145 int orgPositions
[COLUMNS
+1];
2151 memcpy(orgWidths
, pane
->widths
, sizeof(orgWidths
));
2152 memcpy(orgPositions
, pane
->positions
, sizeof(orgPositions
));
2155 for(col
=0; col
<COLUMNS
; col
++)
2156 pane
->widths
[col
] = 0;
2158 hdc
= GetDC(pane
->hwnd
);
2159 hfontOld
= SelectObject(hdc
, Globals
.hfont
);
2161 for(cnt
=0; cnt
<entries
; cnt
++) {
2162 Entry
* entry
= (Entry
*)SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, cnt
, 0);
2171 dis
.hwndItem
= pane
->hwnd
;
2173 SetRectEmpty(&dis
.rcItem
);
2174 /*dis.itemData = 0; */
2176 draw_item(pane
, &dis
, entry
, COLUMNS
);
2179 SelectObject(hdc
, hfontOld
);
2180 ReleaseDC(pane
->hwnd
, hdc
);
2183 for(col
=0; col
<COLUMNS
; col
++) {
2184 pane
->positions
[col
] = x
;
2185 cx
= pane
->widths
[col
];
2190 if (cx
< IMAGE_WIDTH
)
2193 pane
->widths
[col
] = cx
;
2199 pane
->positions
[COLUMNS
] = x
;
2201 SendMessageW(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, x
, 0);
2204 if (!anyway
&& !memcmp(orgWidths
, pane
->widths
, sizeof(orgWidths
)))
2207 /* don't move, if only collapsing an entry */
2208 if (!anyway
&& pane
->widths
[0]<orgWidths
[0] &&
2209 !memcmp(orgWidths
+1, pane
->widths
+1, sizeof(orgWidths
)-sizeof(int))) {
2210 pane
->widths
[0] = orgWidths
[0];
2211 memcpy(pane
->positions
, orgPositions
, sizeof(orgPositions
));
2216 InvalidateRect(pane
->hwnd
, 0, TRUE
);
2221 /* calculate one preferred column width */
2222 static void calc_single_width(Pane
* pane
, int col
)
2226 int entries
= SendMessageW(pane
->hwnd
, LB_GETCOUNT
, 0, 0);
2230 pane
->widths
[col
] = 0;
2232 hdc
= GetDC(pane
->hwnd
);
2233 hfontOld
= SelectObject(hdc
, Globals
.hfont
);
2235 for(cnt
=0; cnt
<entries
; cnt
++) {
2236 Entry
* entry
= (Entry
*)SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, cnt
, 0);
2244 dis
.hwndItem
= pane
->hwnd
;
2246 SetRectEmpty(&dis
.rcItem
);
2247 /*dis.itemData = 0; */
2249 draw_item(pane
, &dis
, entry
, col
);
2252 SelectObject(hdc
, hfontOld
);
2253 ReleaseDC(pane
->hwnd
, hdc
);
2255 cx
= pane
->widths
[col
];
2258 cx
+= 3*Globals
.spaceSize
.cx
;
2260 if (cx
< IMAGE_WIDTH
)
2264 pane
->widths
[col
] = cx
;
2266 x
= pane
->positions
[col
] + cx
;
2268 for(; col
<COLUMNS
-1; ) {
2269 pane
->positions
[++col
] = x
;
2270 x
+= pane
->widths
[col
];
2273 SendMessageW(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, x
, 0);
2276 static BOOL
pattern_match(LPCWSTR str
, LPCWSTR pattern
)
2278 for( ; *str
&&*pattern
; str
++,pattern
++) {
2279 if (*pattern
== '*') {
2281 while(*pattern
== '*');
2287 if (*str
==*pattern
&& pattern_match(str
, pattern
))
2292 else if (*str
!=*pattern
&& *pattern
!='?')
2296 if (*str
|| *pattern
)
2297 if (*pattern
!='*' || pattern
[1]!='\0')
2303 static BOOL
pattern_imatch(LPCWSTR str
, LPCWSTR pattern
)
2305 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2308 lstrcpyW(b2
, pattern
);
2312 return pattern_match(b1
, b2
);
2322 static enum FILE_TYPE
get_file_type(LPCWSTR filename
);
2325 /* insert listbox entries after index idx */
2327 static int insert_entries(Pane
* pane
, Entry
* dir
, LPCWSTR pattern
, int filter_flags
, int idx
)
2334 ShowWindow(pane
->hwnd
, SW_HIDE
);
2336 for(; entry
; entry
=entry
->next
) {
2337 if (pane
->treePane
&& !(entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
2340 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
2341 /* don't display entries "." and ".." in the left pane */
2342 if (pane
->treePane
&& entry
->data
.cFileName
[0] == '.')
2343 if (entry
->data
.cFileName
[1] == '\0' ||
2344 (entry
->data
.cFileName
[1] == '.' &&
2345 entry
->data
.cFileName
[2] == '\0'))
2348 /* filter directories in right pane */
2349 if (!pane
->treePane
&& !(filter_flags
&TF_DIRECTORIES
))
2353 /* filter using the file name pattern */
2355 if (!pattern_imatch(entry
->data
.cFileName
, pattern
))
2358 /* filter system and hidden files */
2359 if (!(filter_flags
&TF_HIDDEN
) && (entry
->data
.dwFileAttributes
&(FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
)))
2362 /* filter looking at the file type */
2363 if ((filter_flags
&(TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
)) != (TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
))
2364 switch(get_file_type(entry
->data
.cFileName
)) {
2366 if (!(filter_flags
& TF_PROGRAMS
))
2371 if (!(filter_flags
& TF_DOCUMENTS
))
2375 default: /* TF_OTHERS */
2376 if (!(filter_flags
& TF_OTHERS
))
2383 SendMessageW(pane
->hwnd
, LB_INSERTSTRING
, idx
, (LPARAM
)entry
);
2385 if (pane
->treePane
&& entry
->expanded
)
2386 idx
= insert_entries(pane
, entry
->down
, pattern
, filter_flags
, idx
);
2389 ShowWindow(pane
->hwnd
, SW_SHOW
);
2394 static void set_space_status(void)
2396 ULARGE_INTEGER ulFreeBytesToCaller
, ulTotalBytes
, ulFreeBytes
;
2397 WCHAR fmt
[64], b1
[64], b2
[64], buffer
[BUFFER_LEN
];
2399 if (GetDiskFreeSpaceExW(NULL
, &ulFreeBytesToCaller
, &ulTotalBytes
, &ulFreeBytes
)) {
2402 args
[0] = (DWORD_PTR
)StrFormatByteSizeW(ulFreeBytesToCaller
.QuadPart
, b1
, ARRAY_SIZE(b1
));
2403 args
[1] = (DWORD_PTR
)StrFormatByteSizeW(ulTotalBytes
.QuadPart
, b2
, ARRAY_SIZE(b2
));
2405 FormatMessageW(FORMAT_MESSAGE_FROM_STRING
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
2406 RS(fmt
,IDS_FREE_SPACE_FMT
), 0, 0, buffer
, ARRAY_SIZE(buffer
),
2407 (__ms_va_list
*)args
);
2409 lstrcpyW(buffer
, sQMarks
);
2411 SendMessageW(Globals
.hstatusbar
, SB_SETTEXTW
, 0, (LPARAM
)buffer
);
2415 static WNDPROC g_orgTreeWndProc
;
2417 static void create_tree_window(HWND parent
, Pane
* pane
, UINT id
, UINT id_header
, LPCWSTR pattern
, int filter_flags
)
2419 static const WCHAR sListBox
[] = {'L','i','s','t','B','o','x','\0'};
2421 static BOOL s_init
= FALSE
;
2422 Entry
* entry
= pane
->root
;
2424 pane
->hwnd
= CreateWindowW(sListBox
, sEmpty
, WS_CHILD
|WS_VISIBLE
|WS_HSCROLL
|WS_VSCROLL
|
2425 LBS_DISABLENOSCROLL
|LBS_NOINTEGRALHEIGHT
|LBS_OWNERDRAWFIXED
|LBS_NOTIFY
,
2426 0, 0, 0, 0, parent
, (HMENU
)ULongToHandle(id
), Globals
.hInstance
, 0);
2428 SetWindowLongPtrW(pane
->hwnd
, GWLP_USERDATA
, (LPARAM
)pane
);
2429 g_orgTreeWndProc
= (WNDPROC
)SetWindowLongPtrW(pane
->hwnd
, GWLP_WNDPROC
, (LPARAM
)TreeWndProc
);
2431 SendMessageW(pane
->hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, FALSE
);
2433 /* insert entries into listbox */
2435 insert_entries(pane
, entry
, pattern
, filter_flags
, -1);
2437 /* calculate column widths */
2440 init_output(pane
->hwnd
);
2443 calc_widths(pane
, TRUE
);
2445 pane
->hwndHeader
= create_header(parent
, pane
, id_header
);
2449 static void InitChildWindow(ChildWnd
* child
)
2451 create_tree_window(child
->hwnd
, &child
->left
, IDW_TREE_LEFT
, IDW_HEADER_LEFT
, NULL
, TF_ALL
);
2452 create_tree_window(child
->hwnd
, &child
->right
, IDW_TREE_RIGHT
, IDW_HEADER_RIGHT
, child
->filter_pattern
, child
->filter_flags
);
2456 static void format_date(const FILETIME
* ft
, WCHAR
* buffer
, int visible_cols
)
2464 if (!ft
->dwLowDateTime
&& !ft
->dwHighDateTime
)
2467 if (!FileTimeToLocalFileTime(ft
, &lft
))
2468 {err
: lstrcpyW(buffer
,sQMarks
); return;}
2470 if (!FileTimeToSystemTime(&lft
, &systime
))
2473 if (visible_cols
& COL_DATE
) {
2474 len
= GetDateFormatW(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
, BUFFER_LEN
);
2479 if (visible_cols
& COL_TIME
) {
2481 buffer
[len
-1] = ' ';
2483 buffer
[len
++] = ' ';
2485 if (!GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
+len
, BUFFER_LEN
-len
))
2491 static void calc_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
)
2493 RECT rt
= {0, 0, 0, 0};
2495 DrawTextW(dis
->hDC
, str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
2497 if (rt
.right
> pane
->widths
[col
])
2498 pane
->widths
[col
] = rt
.right
;
2501 static void calc_tabbed_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
)
2503 RECT rt
= {0, 0, 0, 0};
2505 DrawTextW(dis
->hDC
, str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2506 /*FIXME rt (0,0) ??? */
2508 if (rt
.right
> pane
->widths
[col
])
2509 pane
->widths
[col
] = rt
.right
;
2513 static void output_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
, DWORD flags
)
2515 int x
= dis
->rcItem
.left
;
2518 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2519 rt
.top
= dis
->rcItem
.top
;
2520 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2521 rt
.bottom
= dis
->rcItem
.bottom
;
2523 DrawTextW(dis
->hDC
, str
, -1, &rt
, DT_SINGLELINE
|DT_NOPREFIX
|flags
);
2526 static void output_tabbed_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
)
2528 int x
= dis
->rcItem
.left
;
2531 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2532 rt
.top
= dis
->rcItem
.top
;
2533 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2534 rt
.bottom
= dis
->rcItem
.bottom
;
2536 DrawTextW(dis
->hDC
, str
, -1, &rt
, DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2539 static void output_number(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
)
2541 int x
= dis
->rcItem
.left
;
2548 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2549 rt
.top
= dis
->rcItem
.top
;
2550 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2551 rt
.bottom
= dis
->rcItem
.bottom
;
2556 /* insert number separator characters */
2557 pos
= lstrlenW(s
) % 3;
2563 *d
++ = Globals
.num_sep
;
2567 DrawTextW(dis
->hDC
, b
, d
-b
, &rt
, DT_RIGHT
|DT_SINGLELINE
|DT_NOPREFIX
|DT_END_ELLIPSIS
);
2571 static BOOL
is_exe_file(LPCWSTR ext
)
2573 static const WCHAR executable_extensions
[][4] = {
2584 WCHAR ext_buffer
[_MAX_EXT
];
2585 const WCHAR (*p
)[4];
2589 for(s
=ext
+1,d
=ext_buffer
; (*d
=tolower(*s
)); s
++)
2592 for(p
=executable_extensions
; (*p
)[0]; p
++)
2593 if (!lstrcmpiW(ext_buffer
, *p
))
2599 static BOOL
is_registered_type(LPCWSTR ext
)
2601 /* check if there exists a classname for this file extension in the registry */
2602 if (!RegQueryValueW(HKEY_CLASSES_ROOT
, ext
, NULL
, NULL
))
2608 static enum FILE_TYPE
get_file_type(LPCWSTR filename
)
2610 LPCWSTR ext
= wcsrchr(filename
, '.');
2614 if (is_exe_file(ext
))
2615 return FT_EXECUTABLE
;
2616 else if (is_registered_type(ext
))
2623 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
)
2625 WCHAR buffer
[BUFFER_LEN
];
2627 int visible_cols
= pane
->visible_cols
;
2628 COLORREF bkcolor
, textcolor
;
2629 RECT focusRect
= dis
->rcItem
;
2636 attrs
= entry
->data
.dwFileAttributes
;
2638 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) {
2639 if (entry
->data
.cFileName
[0] == '.' && entry
->data
.cFileName
[1] == '.'
2640 && entry
->data
.cFileName
[2] == '\0')
2641 img
= IMG_FOLDER_UP
;
2642 else if (entry
->data
.cFileName
[0] == '.' && entry
->data
.cFileName
[1] == '\0')
2643 img
= IMG_FOLDER_CUR
;
2644 else if (pane
->treePane
&& (dis
->itemState
&ODS_FOCUS
))
2645 img
= IMG_OPEN_FOLDER
;
2649 switch(get_file_type(entry
->data
.cFileName
)) {
2650 case FT_EXECUTABLE
: img
= IMG_EXECUTABLE
; break;
2651 case FT_DOCUMENT
: img
= IMG_DOCUMENT
; break;
2652 default: img
= IMG_FILE
;
2660 if (pane
->treePane
) {
2662 img_pos
= dis
->rcItem
.left
+ entry
->level
*(IMAGE_WIDTH
+TREE_LINE_DX
);
2664 if (calcWidthCol
== -1) {
2666 int y
= dis
->rcItem
.top
+ IMAGE_HEIGHT
/2;
2669 HRGN hrgn_org
= CreateRectRgn(0, 0, 0, 0);
2672 rt_clip
.left
= dis
->rcItem
.left
;
2673 rt_clip
.top
= dis
->rcItem
.top
;
2674 rt_clip
.right
= dis
->rcItem
.left
+pane
->widths
[col
];
2675 rt_clip
.bottom
= dis
->rcItem
.bottom
;
2677 hrgn
= CreateRectRgnIndirect(&rt_clip
);
2679 if (!GetClipRgn(dis
->hDC
, hrgn_org
)) {
2680 DeleteObject(hrgn_org
);
2684 ExtSelectClipRgn(dis
->hDC
, hrgn
, RGN_AND
);
2687 if ((up
=entry
->up
) != NULL
) {
2688 MoveToEx(dis
->hDC
, img_pos
-IMAGE_WIDTH
/2, y
, 0);
2689 LineTo(dis
->hDC
, img_pos
-2, y
);
2691 x
= img_pos
- IMAGE_WIDTH
/2;
2694 x
-= IMAGE_WIDTH
+TREE_LINE_DX
;
2697 && (up
->next
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
2699 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
2700 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
2702 } while((up
=up
->up
) != NULL
);
2705 x
= img_pos
- IMAGE_WIDTH
/2;
2707 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
2708 LineTo(dis
->hDC
, x
, y
);
2711 && (entry
->next
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
2712 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
2714 SelectClipRgn(dis
->hDC
, hrgn_org
);
2715 if (hrgn_org
) DeleteObject(hrgn_org
);
2716 } else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
) {
2717 int right
= img_pos
+ IMAGE_WIDTH
- TREE_LINE_DX
;
2719 if (right
> pane
->widths
[col
])
2720 pane
->widths
[col
] = right
;
2723 img_pos
= dis
->rcItem
.left
;
2726 img_pos
= dis
->rcItem
.left
;
2728 if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2729 pane
->widths
[col
] = IMAGE_WIDTH
;
2732 if (calcWidthCol
== -1) {
2733 focusRect
.left
= img_pos
-2;
2735 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
)
2736 textcolor
= COLOR_COMPRESSED
;
2738 textcolor
= RGB(0,0,0);
2740 if (dis
->itemState
& ODS_FOCUS
) {
2741 textcolor
= RGB(255,255,255);
2742 bkcolor
= COLOR_SELECTION
;
2744 bkcolor
= RGB(255,255,255);
2747 hbrush
= CreateSolidBrush(bkcolor
);
2748 FillRect(dis
->hDC
, &focusRect
, hbrush
);
2749 DeleteObject(hbrush
);
2751 SetBkMode(dis
->hDC
, TRANSPARENT
);
2752 SetTextColor(dis
->hDC
, textcolor
);
2754 cx
= pane
->widths
[col
];
2756 if (cx
&& img
!=IMG_NONE
) {
2757 if (cx
> IMAGE_WIDTH
)
2760 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
2761 DrawIconEx(dis
->hDC
, img_pos
, dis
->rcItem
.top
, entry
->hicon
, cx
, GetSystemMetrics(SM_CYSMICON
), 0, 0, DI_NORMAL
);
2763 ImageList_DrawEx(Globals
.himl
, img
, dis
->hDC
,
2764 img_pos
, dis
->rcItem
.top
, cx
,
2765 IMAGE_HEIGHT
, bkcolor
, CLR_DEFAULT
, ILD_NORMAL
);
2774 /* output file name */
2775 if (calcWidthCol
== -1)
2776 output_text(pane
, dis
, col
, entry
->data
.cFileName
, 0);
2777 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2778 calc_width(pane
, dis
, col
, entry
->data
.cFileName
);
2782 /* display file size */
2783 if (visible_cols
& COL_SIZE
) {
2784 format_longlong( buffer
, ((ULONGLONG
)entry
->data
.nFileSizeHigh
<< 32) | entry
->data
.nFileSizeLow
);
2786 if (calcWidthCol
== -1)
2787 output_number(pane
, dis
, col
, buffer
);
2788 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2789 calc_width(pane
, dis
, col
, buffer
);/*TODO: not ever time enough */
2794 /* display file date */
2795 if (visible_cols
& (COL_DATE
|COL_TIME
)) {
2796 format_date(&entry
->data
.ftCreationTime
, buffer
, visible_cols
);
2797 if (calcWidthCol
== -1)
2798 output_text(pane
, dis
, col
, buffer
, 0);
2799 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2800 calc_width(pane
, dis
, col
, buffer
);
2803 format_date(&entry
->data
.ftLastAccessTime
, buffer
, visible_cols
);
2804 if (calcWidthCol
== -1)
2805 output_text(pane
, dis
, col
, buffer
, 0);
2806 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2807 calc_width(pane
, dis
, col
, buffer
);
2810 format_date(&entry
->data
.ftLastWriteTime
, buffer
, visible_cols
);
2811 if (calcWidthCol
== -1)
2812 output_text(pane
, dis
, col
, buffer
, 0);
2813 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2814 calc_width(pane
, dis
, col
, buffer
);
2818 if (entry
->bhfi_valid
) {
2819 if (visible_cols
& COL_INDEX
) {
2820 static const WCHAR fmtlow
[] = {'%','X',0};
2821 static const WCHAR fmthigh
[] = {'%','X','%','0','8','X',0};
2823 if (entry
->bhfi
.nFileIndexHigh
)
2824 wsprintfW(buffer
, fmthigh
,
2825 entry
->bhfi
.nFileIndexHigh
, entry
->bhfi
.nFileIndexLow
);
2827 wsprintfW(buffer
, fmtlow
, entry
->bhfi
.nFileIndexLow
);
2829 if (calcWidthCol
== -1)
2830 output_text(pane
, dis
, col
, buffer
, DT_RIGHT
);
2831 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2832 calc_width(pane
, dis
, col
, buffer
);
2837 if (visible_cols
& COL_LINKS
) {
2838 wsprintfW(buffer
, sNumFmt
, entry
->bhfi
.nNumberOfLinks
);
2840 if (calcWidthCol
== -1)
2841 output_text(pane
, dis
, col
, buffer
, DT_CENTER
);
2842 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2843 calc_width(pane
, dis
, col
, buffer
);
2850 /* show file attributes */
2851 if (visible_cols
& COL_ATTRIBUTES
) {
2852 static const WCHAR s11Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
2853 lstrcpyW(buffer
, s11Tabs
);
2855 if (attrs
& FILE_ATTRIBUTE_NORMAL
) buffer
[ 0] = 'N';
2857 if (attrs
& FILE_ATTRIBUTE_READONLY
) buffer
[ 2] = 'R';
2858 if (attrs
& FILE_ATTRIBUTE_HIDDEN
) buffer
[ 4] = 'H';
2859 if (attrs
& FILE_ATTRIBUTE_SYSTEM
) buffer
[ 6] = 'S';
2860 if (attrs
& FILE_ATTRIBUTE_ARCHIVE
) buffer
[ 8] = 'A';
2861 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
) buffer
[10] = 'C';
2862 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) buffer
[12] = 'D';
2863 if (attrs
& FILE_ATTRIBUTE_ENCRYPTED
) buffer
[14] = 'E';
2864 if (attrs
& FILE_ATTRIBUTE_TEMPORARY
) buffer
[16] = 'T';
2865 if (attrs
& FILE_ATTRIBUTE_SPARSE_FILE
) buffer
[18] = 'P';
2866 if (attrs
& FILE_ATTRIBUTE_REPARSE_POINT
) buffer
[20] = 'Q';
2867 if (attrs
& FILE_ATTRIBUTE_OFFLINE
) buffer
[22] = 'O';
2868 if (attrs
& FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
) buffer
[24] = 'X';
2871 if (calcWidthCol
== -1)
2872 output_tabbed_text(pane
, dis
, col
, buffer
);
2873 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2874 calc_tabbed_width(pane
, dis
, col
, buffer
);
2880 static void set_header(Pane
* pane
)
2883 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
2886 item
.mask
= HDI_WIDTH
;
2888 for (i
= 0; i
< COLUMNS
; ++i
) {
2889 if (pane
->positions
[i
] >= scroll_pos
) {
2890 item
.cxy
= pane
->widths
[i
];
2891 } else if (pane
->positions
[i
+1] <= scroll_pos
) {
2894 item
.cxy
= pane
->positions
[i
+1] - scroll_pos
;
2896 pane
->widths_shown
[i
] = item
.cxy
;
2897 SendMessageW(pane
->hwndHeader
, HDM_SETITEMW
, i
, (LPARAM
)&item
);
2901 static LRESULT
pane_notify(Pane
* pane
, NMHDR
* pnmh
)
2903 switch(pnmh
->code
) {
2904 case HDN_ITEMCHANGEDW
: {
2905 LPNMHEADERW phdn
= (LPNMHEADERW
)pnmh
;
2906 int idx
= phdn
->iItem
;
2907 int dx
= phdn
->pitem
->cxy
- pane
->widths_shown
[idx
];
2911 GetClientRect(pane
->hwnd
, &clnt
);
2913 pane
->widths
[idx
] += dx
;
2914 pane
->widths_shown
[idx
] += dx
;
2916 for(i
=idx
; ++i
<=COLUMNS
; )
2917 pane
->positions
[i
] += dx
;
2920 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
2924 rt_scr
.left
= pane
->positions
[idx
+1]-scroll_pos
;
2926 rt_scr
.right
= clnt
.right
;
2927 rt_scr
.bottom
= clnt
.bottom
;
2929 rt_clip
.left
= pane
->positions
[idx
]-scroll_pos
;
2931 rt_clip
.right
= clnt
.right
;
2932 rt_clip
.bottom
= clnt
.bottom
;
2934 if (rt_scr
.left
< 0) rt_scr
.left
= 0;
2935 if (rt_clip
.left
< 0) rt_clip
.left
= 0;
2937 ScrollWindowEx(pane
->hwnd
, dx
, 0, &rt_scr
, &rt_clip
, 0, 0, SW_INVALIDATE
);
2939 rt_clip
.right
= pane
->positions
[idx
+1];
2940 RedrawWindow(pane
->hwnd
, &rt_clip
, 0, RDW_INVALIDATE
|RDW_UPDATENOW
);
2942 if (pnmh
->code
== HDN_ENDTRACKW
) {
2943 SendMessageW(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, pane
->positions
[COLUMNS
], 0);
2945 if (GetScrollPos(pane
->hwnd
, SB_HORZ
) != scroll_pos
)
2953 case HDN_DIVIDERDBLCLICKW
: {
2954 LPNMHEADERW phdn
= (LPNMHEADERW
)pnmh
;
2957 calc_single_width(pane
, phdn
->iItem
);
2958 item
.mask
= HDI_WIDTH
;
2959 item
.cxy
= pane
->widths
[phdn
->iItem
];
2961 SendMessageW(pane
->hwndHeader
, HDM_SETITEMW
, phdn
->iItem
, (LPARAM
)&item
);
2962 InvalidateRect(pane
->hwnd
, 0, TRUE
);
2969 static void scan_entry(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
2971 WCHAR path
[MAX_PATH
];
2972 HCURSOR old_cursor
= SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_WAIT
));
2974 /* delete sub entries in left pane */
2976 LRESULT res
= SendMessageW(child
->left
.hwnd
, LB_GETITEMDATA
, idx
+1, 0);
2977 Entry
* sub
= (Entry
*) res
;
2979 if (res
==LB_ERR
|| !sub
|| sub
->level
<=entry
->level
)
2982 SendMessageW(child
->left
.hwnd
, LB_DELETESTRING
, idx
+1, 0);
2985 /* empty right pane */
2986 SendMessageW(child
->right
.hwnd
, LB_RESETCONTENT
, 0, 0);
2988 /* release memory */
2989 free_entries(entry
);
2991 /* read contents from disk */
2992 if (entry
->etype
== ET_SHELL
)
2994 read_directory(entry
, NULL
, child
->sortOrder
, hwnd
);
2998 get_path(entry
, path
);
2999 read_directory(entry
, path
, child
->sortOrder
, hwnd
);
3002 /* insert found entries in right pane */
3003 insert_entries(&child
->right
, entry
->down
, child
->filter_pattern
, child
->filter_flags
, -1);
3004 calc_widths(&child
->right
, FALSE
);
3005 set_header(&child
->right
);
3007 child
->header_wdths_ok
= FALSE
;
3009 SetCursor(old_cursor
);
3013 /* expand a directory entry */
3015 static BOOL
expand_entry(ChildWnd
* child
, Entry
* dir
)
3020 if (!dir
|| dir
->expanded
|| !dir
->down
)
3025 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='\0' && p
->next
) {
3028 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='.' &&
3029 p
->data
.cFileName
[2]=='\0' && p
->next
)
3033 /* no subdirectories ? */
3034 if (!(p
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
3037 idx
= SendMessageW(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)dir
);
3039 dir
->expanded
= TRUE
;
3041 /* insert entries in left pane */
3042 insert_entries(&child
->left
, p
, NULL
, TF_ALL
, idx
);
3044 if (!child
->header_wdths_ok
) {
3045 if (calc_widths(&child
->left
, FALSE
)) {
3046 set_header(&child
->left
);
3048 child
->header_wdths_ok
= TRUE
;
3056 static void collapse_entry(Pane
* pane
, Entry
* dir
)
3061 idx
= SendMessageW(pane
->hwnd
, LB_FINDSTRING
, 0, (LPARAM
)dir
);
3063 ShowWindow(pane
->hwnd
, SW_HIDE
);
3065 /* hide sub entries */
3067 LRESULT res
= SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, idx
+1, 0);
3068 Entry
* sub
= (Entry
*) res
;
3070 if (res
==LB_ERR
|| !sub
|| sub
->level
<=dir
->level
)
3073 SendMessageW(pane
->hwnd
, LB_DELETESTRING
, idx
+1, 0);
3076 dir
->expanded
= FALSE
;
3078 ShowWindow(pane
->hwnd
, SW_SHOW
);
3082 static void refresh_right_pane(ChildWnd
* child
)
3084 SendMessageW(child
->right
.hwnd
, LB_RESETCONTENT
, 0, 0);
3085 insert_entries(&child
->right
, child
->right
.root
, child
->filter_pattern
, child
->filter_flags
, -1);
3086 calc_widths(&child
->right
, FALSE
);
3088 set_header(&child
->right
);
3091 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3093 WCHAR path
[MAX_PATH
];
3100 child
->left
.cur
= entry
;
3102 child
->right
.root
= entry
->down
? entry
->down
: entry
;
3103 child
->right
.cur
= entry
;
3105 if (!entry
->scanned
)
3106 scan_entry(child
, entry
, idx
, hwnd
);
3108 refresh_right_pane(child
);
3110 get_path(entry
, path
);
3111 lstrcpyW(child
->path
, path
);
3113 if (child
->hwnd
) /* only change window title, if the window already exists */
3114 SetWindowTextW(child
->hwnd
, path
);
3117 if (SetCurrentDirectoryW(path
))
3122 static void refresh_child(ChildWnd
* child
)
3124 WCHAR path
[MAX_PATH
], drv
[_MAX_DRIVE
+1];
3128 get_path(child
->left
.cur
, path
);
3129 _wsplitpath(path
, drv
, NULL
, NULL
, NULL
);
3131 child
->right
.root
= NULL
;
3133 scan_entry(child
, &child
->root
.entry
, 0, child
->hwnd
);
3135 if (child
->root
.entry
.etype
== ET_SHELL
)
3137 LPITEMIDLIST local_pidl
= get_path_pidl(path
,child
->hwnd
);
3139 entry
= read_tree(&child
->root
, NULL
, local_pidl
, drv
, child
->sortOrder
, child
->hwnd
);
3144 entry
= read_tree(&child
->root
, path
, NULL
, drv
, child
->sortOrder
, child
->hwnd
);
3147 entry
= &child
->root
.entry
;
3149 insert_entries(&child
->left
, child
->root
.entry
.down
, NULL
, TF_ALL
, 0);
3151 set_curdir(child
, entry
, 0, child
->hwnd
);
3153 idx
= SendMessageW(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)child
->left
.cur
);
3154 SendMessageW(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
3158 static void create_drive_bar(void)
3160 TBBUTTON drivebarBtn
= {0, 0, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0};
3161 WCHAR b1
[BUFFER_LEN
];
3165 GetLogicalDriveStringsW(BUFFER_LEN
, Globals
.drives
);
3167 Globals
.hdrivebar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
,
3168 IDW_DRIVEBAR
, 2, Globals
.hInstance
, IDB_DRIVEBAR
, &drivebarBtn
,
3169 0, 16, 13, 16, 13, sizeof(TBBUTTON
));
3171 /* insert shell namespace button */
3172 load_string(b1
, ARRAY_SIZE(b1
), IDS_SHELL
);
3173 b1
[lstrlenW(b1
)+1] = '\0';
3174 SendMessageW(Globals
.hdrivebar
, TB_ADDSTRINGW
, 0, (LPARAM
)b1
);
3176 drivebarBtn
.idCommand
= ID_DRIVE_SHELL_NS
;
3177 SendMessageW(Globals
.hdrivebar
, TB_INSERTBUTTONW
, btn
++, (LPARAM
)&drivebarBtn
);
3178 drivebarBtn
.iString
++;
3180 /* register windows drive root strings */
3181 SendMessageW(Globals
.hdrivebar
, TB_ADDSTRINGW
, 0, (LPARAM
)Globals
.drives
);
3183 drivebarBtn
.idCommand
= ID_DRIVE_FIRST
;
3185 for(p
=Globals
.drives
; *p
; ) {
3186 switch(GetDriveTypeW(p
)) {
3187 case DRIVE_REMOVABLE
: drivebarBtn
.iBitmap
= 1; break;
3188 case DRIVE_CDROM
: drivebarBtn
.iBitmap
= 3; break;
3189 case DRIVE_REMOTE
: drivebarBtn
.iBitmap
= 4; break;
3190 case DRIVE_RAMDISK
: drivebarBtn
.iBitmap
= 5; break;
3191 default:/*DRIVE_FIXED*/ drivebarBtn
.iBitmap
= 2;
3194 SendMessageW(Globals
.hdrivebar
, TB_INSERTBUTTONW
, btn
++, (LPARAM
)&drivebarBtn
);
3195 drivebarBtn
.idCommand
++;
3196 drivebarBtn
.iString
++;
3202 static void refresh_drives(void)
3206 /* destroy drive bar */
3207 DestroyWindow(Globals
.hdrivebar
);
3208 Globals
.hdrivebar
= 0;
3210 /* re-create drive bar */
3213 /* update window layout */
3214 GetClientRect(Globals
.hMainWnd
, &rect
);
3215 SendMessageW(Globals
.hMainWnd
, WM_SIZE
, 0, MAKELONG(rect
.right
, rect
.bottom
));
3219 static BOOL
launch_file(HWND hwnd
, LPCWSTR cmd
, UINT nCmdShow
)
3221 HINSTANCE hinst
= ShellExecuteW(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3223 if (PtrToUlong(hinst
) <= 32) {
3224 display_error(hwnd
, GetLastError());
3232 static BOOL
launch_entry(Entry
* entry
, HWND hwnd
, UINT nCmdShow
)
3234 WCHAR cmd
[MAX_PATH
];
3236 if (entry
->etype
== ET_SHELL
) {
3239 SHELLEXECUTEINFOW shexinfo
;
3241 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFOW
);
3242 shexinfo
.fMask
= SEE_MASK_IDLIST
;
3243 shexinfo
.hwnd
= hwnd
;
3244 shexinfo
.lpVerb
= NULL
;
3245 shexinfo
.lpFile
= NULL
;
3246 shexinfo
.lpParameters
= NULL
;
3247 shexinfo
.lpDirectory
= NULL
;
3248 shexinfo
.nShow
= nCmdShow
;
3249 shexinfo
.lpIDList
= get_to_absolute_pidl(entry
, hwnd
);
3251 if (!ShellExecuteExW(&shexinfo
)) {
3252 display_error(hwnd
, GetLastError());
3256 if (shexinfo
.lpIDList
!= entry
->pidl
)
3257 IMalloc_Free(Globals
.iMalloc
, shexinfo
.lpIDList
);
3262 get_path(entry
, cmd
);
3264 /* start program, open document... */
3265 return launch_file(hwnd
, cmd
, nCmdShow
);
3269 static void activate_entry(ChildWnd
* child
, Pane
* pane
, HWND hwnd
)
3271 Entry
* entry
= pane
->cur
;
3276 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
3277 int scanned_old
= entry
->scanned
;
3281 int idx
= SendMessageW(child
->left
.hwnd
, LB_GETCURSEL
, 0, 0);
3282 scan_entry(child
, entry
, idx
, hwnd
);
3285 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='\0')
3288 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='.' && entry
->data
.cFileName
[2]=='\0') {
3289 entry
= child
->left
.cur
->up
;
3290 collapse_entry(&child
->left
, entry
);
3292 } else if (entry
->expanded
)
3293 collapse_entry(pane
, child
->left
.cur
);
3295 expand_entry(child
, child
->left
.cur
);
3297 if (!pane
->treePane
) focus_entry
: {
3298 int idxstart
= SendMessageW(child
->left
.hwnd
, LB_GETCURSEL
, 0, 0);
3299 int idx
= SendMessageW(child
->left
.hwnd
, LB_FINDSTRING
, idxstart
, (LPARAM
)entry
);
3300 SendMessageW(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
3301 set_curdir(child
, entry
, idx
, hwnd
);
3306 calc_widths(pane
, FALSE
);
3311 if (GetKeyState(VK_MENU
) < 0)
3312 show_properties_dlg(entry
, child
->hwnd
);
3314 launch_entry(entry
, child
->hwnd
, SW_SHOWNORMAL
);
3319 static BOOL
pane_command(Pane
* pane
, UINT cmd
)
3323 if (pane
->visible_cols
) {
3324 pane
->visible_cols
= 0;
3325 calc_widths(pane
, TRUE
);
3327 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3328 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
|MF_CHECKED
);
3329 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
);
3333 case ID_VIEW_ALL_ATTRIBUTES
:
3334 if (pane
->visible_cols
!= COL_ALL
) {
3335 pane
->visible_cols
= COL_ALL
;
3336 calc_widths(pane
, TRUE
);
3338 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3339 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
);
3340 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
|MF_CHECKED
);
3344 case ID_PREFERRED_SIZES
: {
3345 calc_widths(pane
, TRUE
);
3347 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3350 /* TODO: more command ids... */
3360 static void set_sort_order(ChildWnd
* child
, SORT_ORDER sortOrder
)
3362 if (child
->sortOrder
!= sortOrder
) {
3363 child
->sortOrder
= sortOrder
;
3364 refresh_child(child
);
3368 static void update_view_menu(ChildWnd
* child
)
3370 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_NAME
, child
->sortOrder
==SORT_NAME
? MF_CHECKED
: MF_UNCHECKED
);
3371 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_TYPE
, child
->sortOrder
==SORT_EXT
? MF_CHECKED
: MF_UNCHECKED
);
3372 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_SIZE
, child
->sortOrder
==SORT_SIZE
? MF_CHECKED
: MF_UNCHECKED
);
3373 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_DATE
, child
->sortOrder
==SORT_DATE
? MF_CHECKED
: MF_UNCHECKED
);
3377 static BOOL
is_directory(LPCWSTR target
)
3379 DWORD target_attr
= GetFileAttributesW(target
);
3381 if (target_attr
== INVALID_FILE_ATTRIBUTES
)
3384 return (target_attr
& FILE_ATTRIBUTE_DIRECTORY
) != 0;
3387 static BOOL
prompt_target(Pane
* pane
, LPWSTR source
, LPWSTR target
)
3389 WCHAR path
[MAX_PATH
];
3392 get_path(pane
->cur
, path
);
3394 if (DialogBoxParamW(Globals
.hInstance
, MAKEINTRESOURCEW(IDD_SELECT_DESTINATION
), pane
->hwnd
, DestinationDlgProc
, (LPARAM
)path
) != IDOK
)
3397 get_path(pane
->cur
, source
);
3399 /* convert relative targets to absolute paths */
3400 if (path
[0]!='/' && path
[1]!=':') {
3401 get_path(pane
->cur
->up
, target
);
3402 len
= lstrlenW(target
);
3404 if (target
[len
-1]!='\\' && target
[len
-1]!='/')
3405 target
[len
++] = '/';
3407 lstrcpyW(target
+len
, path
);
3409 lstrcpyW(target
, path
);
3411 /* If the target already exists as directory, create a new target below this. */
3412 if (is_directory(path
)) {
3413 WCHAR fname
[_MAX_FNAME
], ext
[_MAX_EXT
];
3414 static const WCHAR sAppend
[] = {'%','s','/','%','s','%','s','\0'};
3416 _wsplitpath(source
, NULL
, NULL
, fname
, ext
);
3418 wsprintfW(target
, sAppend
, path
, fname
, ext
);
3425 static IContextMenu2
* s_pctxmenu2
= NULL
;
3426 static IContextMenu3
* s_pctxmenu3
= NULL
;
3428 static void CtxMenu_reset(void)
3434 static IContextMenu
* CtxMenu_query_interfaces(IContextMenu
* pcm1
)
3436 IContextMenu
* pcm
= NULL
;
3440 if (IContextMenu_QueryInterface(pcm1
, &IID_IContextMenu3
, (void**)&pcm
) == NOERROR
)
3441 s_pctxmenu3
= (LPCONTEXTMENU3
)pcm
;
3442 else if (IContextMenu_QueryInterface(pcm1
, &IID_IContextMenu2
, (void**)&pcm
) == NOERROR
)
3443 s_pctxmenu2
= (LPCONTEXTMENU2
)pcm
;
3446 IContextMenu_Release(pcm1
);
3452 static BOOL
CtxMenu_HandleMenuMsg(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3455 if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3
, nmsg
, wparam
, lparam
)))
3460 if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2
, nmsg
, wparam
, lparam
)))
3466 static HRESULT
ShellFolderContextMenu(IShellFolder
* shell_folder
, HWND hwndParent
, int cidl
, LPCITEMIDLIST
* apidl
, int x
, int y
)
3469 BOOL executed
= FALSE
;
3471 HRESULT hr
= IShellFolder_GetUIObjectOf(shell_folder
, hwndParent
, cidl
, apidl
, &IID_IContextMenu
, NULL
, (LPVOID
*)&pcm
);
3473 if (SUCCEEDED(hr
)) {
3474 HMENU hmenu
= CreatePopupMenu();
3476 pcm
= CtxMenu_query_interfaces(pcm
);
3479 hr
= IContextMenu_QueryContextMenu(pcm
, hmenu
, 0, FCIDM_SHVIEWFIRST
, FCIDM_SHVIEWLAST
, CMF_NORMAL
);
3481 if (SUCCEEDED(hr
)) {
3482 UINT idCmd
= TrackPopupMenu(hmenu
, TPM_LEFTALIGN
|TPM_RETURNCMD
|TPM_RIGHTBUTTON
, x
, y
, 0, hwndParent
, NULL
);
3487 CMINVOKECOMMANDINFO cmi
;
3489 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFO
);
3491 cmi
.hwnd
= hwndParent
;
3492 cmi
.lpVerb
= (LPCSTR
)(INT_PTR
)(idCmd
- FCIDM_SHVIEWFIRST
);
3493 cmi
.lpParameters
= NULL
;
3494 cmi
.lpDirectory
= NULL
;
3495 cmi
.nShow
= SW_SHOWNORMAL
;
3499 hr
= IContextMenu_InvokeCommand(pcm
, &cmi
);
3506 IContextMenu_Release(pcm
);
3509 return FAILED(hr
)? hr
: executed
? S_OK
: S_FALSE
;
3512 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3514 ChildWnd
* child
= (ChildWnd
*)GetWindowLongPtrW(hwnd
, GWLP_USERDATA
);
3519 LPDRAWITEMSTRUCT dis
= (LPDRAWITEMSTRUCT
)lparam
;
3520 Entry
* entry
= (Entry
*) dis
->itemData
;
3522 if (dis
->CtlID
== IDW_TREE_LEFT
)
3523 draw_item(&child
->left
, dis
, entry
, -1);
3524 else if (dis
->CtlID
== IDW_TREE_RIGHT
)
3525 draw_item(&child
->right
, dis
, entry
, -1);
3527 goto draw_menu_item
;
3532 InitChildWindow(child
);
3536 free_child_window(child
);
3537 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, 0);
3544 GetClientRect(hwnd
, &rt
);
3545 BeginPaint(hwnd
, &ps
);
3546 rt
.left
= child
->split_pos
-SPLIT_WIDTH
/2;
3547 rt
.right
= child
->split_pos
+SPLIT_WIDTH
/2+1;
3548 lastBrush
= SelectObject(ps
.hdc
, GetStockObject(COLOR_SPLITBAR
));
3549 Rectangle(ps
.hdc
, rt
.left
, rt
.top
-1, rt
.right
, rt
.bottom
+1);
3550 SelectObject(ps
.hdc
, lastBrush
);
3551 EndPaint(hwnd
, &ps
);
3555 if (LOWORD(lparam
) == HTCLIENT
) {
3558 ScreenToClient(hwnd
, &pt
);
3560 if (pt
.x
>=child
->split_pos
-SPLIT_WIDTH
/2 && pt
.x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
3561 SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_SIZEWE
));
3567 case WM_LBUTTONDOWN
: {
3569 int x
= (short)LOWORD(lparam
);
3571 GetClientRect(hwnd
, &rt
);
3573 if (x
>=child
->split_pos
-SPLIT_WIDTH
/2 && x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
3574 last_split
= child
->split_pos
;
3581 if (GetCapture() == hwnd
)
3586 if (wparam
== VK_ESCAPE
)
3587 if (GetCapture() == hwnd
) {
3589 child
->split_pos
= last_split
;
3590 GetClientRect(hwnd
, &rt
);
3591 resize_tree(child
, rt
.right
, rt
.bottom
);
3594 SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_ARROW
));
3599 if (GetCapture() == hwnd
) {
3601 int x
= (short)LOWORD(lparam
);
3603 GetClientRect(hwnd
, &rt
);
3605 if (x
>=0 && x
<rt
.right
) {
3606 child
->split_pos
= x
;
3607 resize_tree(child
, rt
.right
, rt
.bottom
);
3608 rt
.left
= x
-SPLIT_WIDTH
/2;
3609 rt
.right
= x
+SPLIT_WIDTH
/2+1;
3610 InvalidateRect(hwnd
, &rt
, FALSE
);
3611 UpdateWindow(child
->left
.hwnd
);
3613 UpdateWindow(child
->right
.hwnd
);
3618 case WM_GETMINMAXINFO
:
3619 DefMDIChildProcW(hwnd
, nmsg
, wparam
, lparam
);
3621 {LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
3623 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
3624 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
3628 if (SetCurrentDirectoryW(child
->path
))
3630 SetFocus(child
->focus_pane
? child
->right
.hwnd
: child
->left
.hwnd
);
3633 case WM_DISPATCH_COMMAND
: {
3634 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
3636 switch(LOWORD(wparam
)) {
3637 case ID_WINDOW_NEW
: {
3638 ChildWnd
* new_child
= alloc_child_window(child
->path
, NULL
, hwnd
);
3640 if (!create_child_window(new_child
))
3641 HeapFree(GetProcessHeap(), 0, new_child
);
3647 refresh_child(child
);
3651 activate_entry(child
, pane
, hwnd
);
3654 case ID_FILE_MOVE
: {
3655 WCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
3657 if (prompt_target(pane
, source
, target
)) {
3658 SHFILEOPSTRUCTW shfo
= {hwnd
, FO_MOVE
, source
, target
};
3660 source
[lstrlenW(source
)+1] = '\0';
3661 target
[lstrlenW(target
)+1] = '\0';
3663 if (!SHFileOperationW(&shfo
))
3664 refresh_child(child
);
3668 case ID_FILE_COPY
: {
3669 WCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
3671 if (prompt_target(pane
, source
, target
)) {
3672 SHFILEOPSTRUCTW shfo
= {hwnd
, FO_COPY
, source
, target
};
3674 source
[lstrlenW(source
)+1] = '\0';
3675 target
[lstrlenW(target
)+1] = '\0';
3677 if (!SHFileOperationW(&shfo
))
3678 refresh_child(child
);
3682 case ID_FILE_DELETE
: {
3683 WCHAR path
[BUFFER_LEN
];
3684 SHFILEOPSTRUCTW shfo
= {hwnd
, FO_DELETE
, path
, NULL
, FOF_ALLOWUNDO
};
3686 get_path(pane
->cur
, path
);
3688 path
[lstrlenW(path
)+1] = '\0';
3690 if (!SHFileOperationW(&shfo
))
3691 refresh_child(child
);
3694 case ID_VIEW_SORT_NAME
:
3695 set_sort_order(child
, SORT_NAME
);
3698 case ID_VIEW_SORT_TYPE
:
3699 set_sort_order(child
, SORT_EXT
);
3702 case ID_VIEW_SORT_SIZE
:
3703 set_sort_order(child
, SORT_SIZE
);
3706 case ID_VIEW_SORT_DATE
:
3707 set_sort_order(child
, SORT_DATE
);
3710 case ID_VIEW_FILTER
: {
3711 struct FilterDialog dlg
;
3713 memset(&dlg
, 0, sizeof(struct FilterDialog
));
3714 lstrcpyW(dlg
.pattern
, child
->filter_pattern
);
3715 dlg
.flags
= child
->filter_flags
;
3717 if (DialogBoxParamW(Globals
.hInstance
, MAKEINTRESOURCEW(IDD_DIALOG_VIEW_TYPE
), hwnd
, FilterDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
3718 lstrcpyW(child
->filter_pattern
, dlg
.pattern
);
3719 child
->filter_flags
= dlg
.flags
;
3720 refresh_right_pane(child
);
3724 case ID_VIEW_SPLIT
: {
3725 last_split
= child
->split_pos
;
3729 case ID_EDIT_PROPERTIES
:
3730 show_properties_dlg(pane
->cur
, child
->hwnd
);
3734 return pane_command(pane
, LOWORD(wparam
));
3740 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
3742 switch(HIWORD(wparam
)) {
3743 case LBN_SELCHANGE
: {
3744 int idx
= SendMessageW(pane
->hwnd
, LB_GETCURSEL
, 0, 0);
3745 Entry
* entry
= (Entry
*)SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, idx
, 0);
3747 if (pane
== &child
->left
)
3748 set_curdir(child
, entry
, idx
, hwnd
);
3754 activate_entry(child
, pane
, hwnd
);
3760 NMHDR
* pnmh
= (NMHDR
*) lparam
;
3761 return pane_notify(pnmh
->idFrom
==IDW_HEADER_LEFT
? &child
->left
: &child
->right
, pnmh
);}
3763 case WM_CONTEXTMENU
: {
3768 /* first select the current item in the listbox */
3769 HWND hpanel
= (HWND
) wparam
;
3770 pt_clnt
.x
= pt
.x
= (short)LOWORD(lparam
);
3771 pt_clnt
.y
= pt
.y
= (short)HIWORD(lparam
);
3772 ScreenToClient(hpanel
, &pt_clnt
);
3773 SendMessageW(hpanel
, WM_LBUTTONDOWN
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
3774 SendMessageW(hpanel
, WM_LBUTTONUP
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
3776 /* now create the popup menu using shell namespace and IContextMenu */
3777 pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
3778 idx
= SendMessageW(pane
->hwnd
, LB_GETCURSEL
, 0, 0);
3781 Entry
* entry
= (Entry
*)SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, idx
, 0);
3783 LPITEMIDLIST pidl_abs
= get_to_absolute_pidl(entry
, hwnd
);
3786 IShellFolder
* parentFolder
;
3787 LPCITEMIDLIST pidlLast
;
3789 /* get and use the parent folder to display correct context menu in all cases */
3790 if (SUCCEEDED(SHBindToParent(pidl_abs
, &IID_IShellFolder
, (LPVOID
*)&parentFolder
, &pidlLast
))) {
3791 if (ShellFolderContextMenu(parentFolder
, hwnd
, 1, &pidlLast
, pt
.x
, pt
.y
) == S_OK
)
3792 refresh_child(child
);
3794 IShellFolder_Release(parentFolder
);
3797 IMalloc_Free(Globals
.iMalloc
, pidl_abs
);
3802 case WM_MEASUREITEM
:
3804 if (!wparam
) /* Is the message menu-related? */
3805 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
3810 case WM_INITMENUPOPUP
:
3811 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
3814 update_view_menu(child
);
3817 case WM_MENUCHAR
: /* only supported by IContextMenu3 */
3819 LRESULT lResult
= 0;
3821 IContextMenu3_HandleMenuMsg2(s_pctxmenu3
, nmsg
, wparam
, lparam
, &lResult
);
3829 if (wparam
!= SIZE_MINIMIZED
)
3830 resize_tree(child
, LOWORD(lparam
), HIWORD(lparam
));
3834 return DefMDIChildProcW(hwnd
, nmsg
, wparam
, lparam
);
3841 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3843 ChildWnd
* child
= (ChildWnd
*)GetWindowLongPtrW(GetParent(hwnd
), GWLP_USERDATA
);
3844 Pane
* pane
= (Pane
*)GetWindowLongPtrW(hwnd
, GWLP_USERDATA
);
3853 child
->focus_pane
= pane
==&child
->right
? 1: 0;
3854 SendMessageW(hwnd
, LB_SETSEL
, TRUE
, 1);
3855 /*TODO: check menu items */
3859 if (wparam
== VK_TAB
) {
3860 /*TODO: SetFocus(Globals.hdrivebar) */
3861 SetFocus(child
->focus_pane
? child
->left
.hwnd
: child
->right
.hwnd
);
3865 return CallWindowProcW(g_orgTreeWndProc
, hwnd
, nmsg
, wparam
, lparam
);
3869 static void InitInstance(HINSTANCE hinstance
)
3871 static const WCHAR sFont
[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
3873 WNDCLASSEXW wcFrame
;
3877 INITCOMMONCONTROLSEX icc
= {
3878 sizeof(INITCOMMONCONTROLSEX
),
3884 setlocale(LC_COLLATE
, ""); /* set collating rules to local settings for compareName */
3886 InitCommonControlsEx(&icc
);
3889 /* register frame window class */
3891 wcFrame
.cbSize
= sizeof(WNDCLASSEXW
);
3893 wcFrame
.lpfnWndProc
= FrameWndProc
;
3894 wcFrame
.cbClsExtra
= 0;
3895 wcFrame
.cbWndExtra
= 0;
3896 wcFrame
.hInstance
= hinstance
;
3897 wcFrame
.hIcon
= LoadIconW(hinstance
, MAKEINTRESOURCEW(IDI_WINEFILE
));
3898 wcFrame
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
3899 wcFrame
.hbrBackground
= 0;
3900 wcFrame
.lpszMenuName
= 0;
3901 wcFrame
.lpszClassName
= sWINEFILEFRAME
;
3902 wcFrame
.hIconSm
= LoadImageW(hinstance
, MAKEINTRESOURCEW(IDI_WINEFILE
), IMAGE_ICON
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
3904 Globals
.hframeClass
= RegisterClassExW(&wcFrame
);
3907 /* register tree windows class */
3909 wcChild
.style
= CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
;
3910 wcChild
.lpfnWndProc
= ChildWndProc
;
3911 wcChild
.cbClsExtra
= 0;
3912 wcChild
.cbWndExtra
= 0;
3913 wcChild
.hInstance
= hinstance
;
3914 wcChild
.hIcon
= LoadIconW(hinstance
, MAKEINTRESOURCEW(IDI_WINEFILE
));
3915 wcChild
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
3916 wcChild
.hbrBackground
= 0;
3917 wcChild
.lpszMenuName
= 0;
3918 wcChild
.lpszClassName
= sWINEFILETREE
;
3920 RegisterClassW(&wcChild
);
3923 Globals
.haccel
= LoadAcceleratorsW(hinstance
, MAKEINTRESOURCEW(IDA_WINEFILE
));
3925 Globals
.hfont
= CreateFontW(-MulDiv(8,GetDeviceCaps(hdc
,LOGPIXELSY
),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont
);
3929 Globals
.hInstance
= hinstance
;
3932 CoGetMalloc(MEMCTX_TASK
, &Globals
.iMalloc
);
3933 SHGetDesktopFolder(&Globals
.iDesktop
);
3934 Globals
.cfStrFName
= RegisterClipboardFormatW(CFSTR_FILENAMEW
);
3936 /* load column strings */
3939 load_string(g_pos_names
[col
++], ARRAY_SIZE(g_pos_names
[col
]), IDS_COL_NAME
);
3940 load_string(g_pos_names
[col
++], ARRAY_SIZE(g_pos_names
[col
]), IDS_COL_SIZE
);
3941 load_string(g_pos_names
[col
++], ARRAY_SIZE(g_pos_names
[col
]), IDS_COL_CDATE
);
3942 load_string(g_pos_names
[col
++], ARRAY_SIZE(g_pos_names
[col
]), IDS_COL_ADATE
);
3943 load_string(g_pos_names
[col
++], ARRAY_SIZE(g_pos_names
[col
]), IDS_COL_MDATE
);
3944 load_string(g_pos_names
[col
++], ARRAY_SIZE(g_pos_names
[col
]), IDS_COL_IDX
);
3945 load_string(g_pos_names
[col
++], ARRAY_SIZE(g_pos_names
[col
]), IDS_COL_LINKS
);
3946 load_string(g_pos_names
[col
++], ARRAY_SIZE(g_pos_names
[col
]), IDS_COL_ATTR
);
3947 load_string(g_pos_names
[col
++], ARRAY_SIZE(g_pos_names
[col
]), IDS_COL_SEC
);
3951 static BOOL
show_frame(HWND hwndParent
, int cmdshow
, LPWSTR path
)
3953 static const WCHAR sMDICLIENT
[] = {'M','D','I','C','L','I','E','N','T','\0'};
3955 WCHAR buffer
[MAX_PATH
], b1
[BUFFER_LEN
];
3957 HMENU hMenuFrame
, hMenuWindow
;
3960 CLIENTCREATESTRUCT ccs
;
3962 if (Globals
.hMainWnd
)
3965 opts
= load_registry_settings();
3966 hMenuFrame
= LoadMenuW(Globals
.hInstance
, MAKEINTRESOURCEW(IDM_WINEFILE
));
3967 hMenuWindow
= GetSubMenu(hMenuFrame
, GetMenuItemCount(hMenuFrame
)-2);
3969 Globals
.hMenuFrame
= hMenuFrame
;
3970 Globals
.hMenuView
= GetSubMenu(hMenuFrame
, 2);
3971 Globals
.hMenuOptions
= GetSubMenu(hMenuFrame
, 3);
3973 ccs
.hWindowMenu
= hMenuWindow
;
3974 ccs
.idFirstChild
= IDW_FIRST_CHILD
;
3977 /* create main window */
3978 Globals
.hMainWnd
= CreateWindowExW(0, MAKEINTRESOURCEW(Globals
.hframeClass
), RS(b1
,IDS_WINEFILE
), WS_OVERLAPPEDWINDOW
,
3979 opts
.start_x
, opts
.start_y
, opts
.width
, opts
.height
,
3980 hwndParent
, Globals
.hMenuFrame
, Globals
.hInstance
, 0/*lpParam*/);
3983 Globals
.hmdiclient
= CreateWindowExW(0, sMDICLIENT
, NULL
,
3984 WS_CHILD
|WS_CLIPCHILDREN
|WS_VSCROLL
|WS_HSCROLL
|WS_VISIBLE
|WS_BORDER
,
3986 Globals
.hMainWnd
, 0, Globals
.hInstance
, &ccs
);
3988 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_DRIVE_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
3989 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_SAVESETTINGS
, MF_BYCOMMAND
);
3994 TBBUTTON toolbarBtns
[] = {
3995 {0, 0, 0, BTNS_SEP
, {0, 0}, 0, 0},
3996 {0, ID_WINDOW_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
3997 {1, ID_WINDOW_CASCADE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
3998 {2, ID_WINDOW_TILE_HORZ
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
3999 {3, ID_WINDOW_TILE_VERT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4002 Globals
.htoolbar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
,
4003 IDW_TOOLBAR
, 2, Globals
.hInstance
, IDB_TOOLBAR
, toolbarBtns
,
4004 ARRAY_SIZE(toolbarBtns
), 16, 15, 16, 15, sizeof(TBBUTTON
));
4005 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_TOOL_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4008 Globals
.hstatusbar
= CreateStatusWindowW(WS_CHILD
|WS_VISIBLE
, 0, Globals
.hMainWnd
, IDW_STATUSBAR
);
4009 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
4011 /*TODO: read paths from registry */
4013 if (!path
|| !*path
) {
4014 GetCurrentDirectoryW(MAX_PATH
, buffer
);
4018 ShowWindow(Globals
.hMainWnd
, cmdshow
);
4020 /* Shell Namespace as default: */
4021 child
= alloc_child_window(path
, get_path_pidl(path
,Globals
.hMainWnd
), Globals
.hMainWnd
);
4023 child
->pos
.showCmd
= SW_SHOWMAXIMIZED
;
4024 child
->pos
.rcNormalPosition
.left
= 0;
4025 child
->pos
.rcNormalPosition
.top
= 0;
4026 child
->pos
.rcNormalPosition
.right
= 320;
4027 child
->pos
.rcNormalPosition
.bottom
= 280;
4029 if (!create_child_window(child
)) {
4030 HeapFree(GetProcessHeap(), 0, child
);
4034 SetWindowPlacement(child
->hwnd
, &child
->pos
);
4036 Globals
.himl
= ImageList_LoadImageW(Globals
.hInstance
, MAKEINTRESOURCEW(IDB_IMAGES
), 16, 0, RGB(0,255,0), IMAGE_BITMAP
, 0);
4038 Globals
.prescan_node
= FALSE
;
4040 UpdateWindow(Globals
.hMainWnd
);
4042 if (child
->hwnd
&& path
&& path
[0])
4045 WCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
4046 WCHAR fullname
[_MAX_FNAME
+_MAX_EXT
+1];
4048 memset(name
,0,sizeof(name
));
4049 memset(name
,0,sizeof(ext
));
4050 _wsplitpath(path
, drv
, dir
, name
, ext
);
4053 count
= SendMessageW(child
->right
.hwnd
, LB_GETCOUNT
, 0, 0);
4054 lstrcpyW(fullname
,name
);
4055 lstrcatW(fullname
,ext
);
4057 for (index
= 0; index
< count
; index
++)
4059 Entry
* entry
= (Entry
*)SendMessageW(child
->right
.hwnd
, LB_GETITEMDATA
, index
, 0);
4060 if (lstrcmpW(entry
->data
.cFileName
,fullname
)==0 ||
4061 lstrcmpW(entry
->data
.cAlternateFileName
,fullname
)==0)
4063 SendMessageW(child
->right
.hwnd
, LB_SETCURSEL
, index
, 0);
4064 SetFocus(child
->right
.hwnd
);
4073 static void ExitInstance(void)
4075 IShellFolder_Release(Globals
.iDesktop
);
4076 IMalloc_Release(Globals
.iMalloc
);
4079 DeleteObject(Globals
.hfont
);
4080 ImageList_Destroy(Globals
.himl
);
4083 int APIENTRY
wWinMain(HINSTANCE hinstance
, HINSTANCE previnstance
, LPWSTR cmdline
, int cmdshow
)
4087 InitInstance(hinstance
);
4089 if( !show_frame(0, cmdshow
, cmdline
) )
4095 while(GetMessageW(&msg
, 0, 0, 0)) {
4096 if (Globals
.hmdiclient
&& TranslateMDISysAccel(Globals
.hmdiclient
, &msg
))
4099 if (Globals
.hMainWnd
&& TranslateAcceleratorW(Globals
.hMainWnd
, Globals
.haccel
, &msg
))
4102 TranslateMessage(&msg
);
4103 DispatchMessageW(&msg
);