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
24 #include "wine/port.h"
26 /* for unix filesystem function calls */
28 #include <sys/types.h>
36 #include "wine/unicode.h"
44 #define _MAX_FNAME 256
45 #define _MAX_DIR _MAX_FNAME
46 #define _MAX_EXT _MAX_FNAME
50 #ifdef NONAMELESSUNION
51 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
53 #define UNION_MEMBER(x) x
58 #define DEFAULT_SPLIT_POS 300
60 #define DEFAULT_SPLIT_POS 200
63 static const WCHAR registry_key
[] = { 'S','o','f','t','w','a','r','e','\\',
65 'W','i','n','e','F','i','l','e','\0'};
66 static const WCHAR reg_start_x
[] = { 's','t','a','r','t','X','\0'};
67 static const WCHAR reg_start_y
[] = { 's','t','a','r','t','Y','\0'};
68 static const WCHAR reg_width
[] = { 'w','i','d','t','h','\0'};
69 static const WCHAR reg_height
[] = { 'h','e','i','g','h','t','\0'};
70 static const WCHAR reg_logfont
[] = { 'l','o','g','f','o','n','t','\0'};
80 typedef struct _Entry
{
89 WIN32_FIND_DATAW data
;
91 #ifndef _NO_EXTENSIONS
92 BY_HANDLE_FILE_INFORMATION bhfi
;
94 enum ENTRY_TYPE etype
;
105 WCHAR path
[MAX_PATH
];
106 WCHAR volname
[_MAX_FNAME
];
116 COL_ATTRIBUTES
= 0x08,
118 #ifdef _NO_EXTENSIONS
119 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
123 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
|COL_INDEX
|COL_LINKS
136 #ifndef _NO_EXTENSIONS
140 #ifndef _NO_EXTENSIONS
146 int positions
[COLUMNS
+1];
158 int focus_pane
; /* 0: left 1: right */
161 BOOL header_wdths_ok
;
163 WCHAR path
[MAX_PATH
];
164 WCHAR filter_pattern
[MAX_PATH
];
168 SORT_ORDER sortOrder
;
173 static void read_directory(Entry
* dir
, LPCWSTR path
, SORT_ORDER sortOrder
, HWND hwnd
);
174 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
);
175 static void refresh_child(ChildWnd
* child
);
176 static void refresh_drives(void);
177 static void get_path(Entry
* dir
, PWSTR path
);
178 static void format_date(const FILETIME
* ft
, WCHAR
* buffer
, int visible_cols
);
180 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
181 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
182 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
186 WINEFILE_GLOBALS Globals
;
188 static int last_split
;
190 /* some common string constants */
191 static const WCHAR sEmpty
[] = {'\0'};
192 static const WCHAR sSpace
[] = {' ', '\0'};
193 static const WCHAR sNumFmt
[] = {'%','d','\0'};
194 static const WCHAR sQMarks
[] = {'?','?','?','\0'};
196 /* window class names */
197 static const WCHAR sWINEFILEFRAME
[] = {'W','F','S','_','F','r','a','m','e','\0'};
198 static const WCHAR sWINEFILETREE
[] = {'W','F','S','_','T','r','e','e','\0'};
200 static void format_longlong(LPWSTR ret
, ULONGLONG val
)
202 WCHAR buffer
[65], *p
= &buffer
[64];
206 *(--p
) = '0' + val
% 10;
213 /* load resource string */
214 static LPWSTR
load_string(LPWSTR buffer
, DWORD size
, UINT id
)
216 LoadStringW(Globals
.hInstance
, id
, buffer
, size
);
220 #define RS(b, i) load_string(b, sizeof(b)/sizeof(b[0]), i)
223 /* display error message for the specified WIN32 error code */
224 static void display_error(HWND hwnd
, DWORD error
)
226 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
229 if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_FROM_SYSTEM
,
230 0, error
, MAKELANGID(LANG_NEUTRAL
,SUBLANG_DEFAULT
), (PWSTR
)&msg
, 0, NULL
))
231 MessageBoxW(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
233 MessageBoxW(hwnd
, RS(b1
,IDS_ERROR
), RS(b2
,IDS_WINEFILE
), MB_OK
);
239 /* display network error message using WNetGetLastErrorW() */
240 static void display_network_error(HWND hwnd
)
242 WCHAR msg
[BUFFER_LEN
], provider
[BUFFER_LEN
], b2
[BUFFER_LEN
];
245 if (WNetGetLastErrorW(&error
, msg
, BUFFER_LEN
, provider
, BUFFER_LEN
) == NO_ERROR
)
246 MessageBoxW(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
249 static inline BOOL
get_check(HWND hwnd
, INT id
)
251 return BST_CHECKED
&SendMessageW(GetDlgItem(hwnd
, id
), BM_GETSTATE
, 0, 0);
254 static inline INT
set_check(HWND hwnd
, INT id
, BOOL on
)
256 return SendMessageW(GetDlgItem(hwnd
, id
), BM_SETCHECK
, on
?BST_CHECKED
:BST_UNCHECKED
, 0);
259 static inline void choose_font(HWND hwnd
)
261 WCHAR dlg_name
[BUFFER_LEN
], dlg_info
[BUFFER_LEN
];
265 HDC hdc
= GetDC(hwnd
);
267 GetObjectW(Globals
.hfont
, sizeof(LOGFONTW
), &lFont
);
269 chFont
.lStructSize
= sizeof(CHOOSEFONTW
);
270 chFont
.hwndOwner
= hwnd
;
272 chFont
.lpLogFont
= &lFont
;
273 chFont
.Flags
= CF_SCREENFONTS
| CF_FORCEFONTEXIST
| CF_LIMITSIZE
| CF_NOSCRIPTSEL
| CF_INITTOLOGFONTSTRUCT
;
274 chFont
.rgbColors
= RGB(0,0,0);
275 chFont
.lCustData
= 0;
276 chFont
.lpfnHook
= NULL
;
277 chFont
.lpTemplateName
= NULL
;
278 chFont
.hInstance
= Globals
.hInstance
;
279 chFont
.lpszStyle
= NULL
;
280 chFont
.nFontType
= SIMULATED_FONTTYPE
;
282 chFont
.nSizeMax
= 24;
284 if (ChooseFontW(&chFont
)) {
288 DeleteObject(Globals
.hfont
);
289 Globals
.hfont
= CreateFontIndirectW(&lFont
);
290 hFontOld
= SelectObject(hdc
, Globals
.hfont
);
291 GetTextExtentPoint32W(hdc
, sSpace
, 1, &Globals
.spaceSize
);
293 /* change font in all open child windows */
294 for(childWnd
=GetWindow(Globals
.hmdiclient
,GW_CHILD
); childWnd
; childWnd
=GetNextWindow(childWnd
,GW_HWNDNEXT
)) {
295 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtrW(childWnd
, GWLP_USERDATA
);
296 SendMessageW(child
->left
.hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, TRUE
);
297 SendMessageW(child
->right
.hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, TRUE
);
298 SendMessageW(child
->left
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
299 SendMessageW(child
->right
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
300 InvalidateRect(child
->left
.hwnd
, NULL
, TRUE
);
301 InvalidateRect(child
->right
.hwnd
, NULL
, TRUE
);
304 SelectObject(hdc
, hFontOld
);
306 else if (CommDlgExtendedError()) {
307 LoadStringW(Globals
.hInstance
, IDS_FONT_SEL_DLG_NAME
, dlg_name
, BUFFER_LEN
);
308 LoadStringW(Globals
.hInstance
, IDS_FONT_SEL_ERROR
, dlg_info
, BUFFER_LEN
);
309 MessageBoxW(hwnd
, dlg_info
, dlg_name
, MB_OK
);
312 ReleaseDC(hwnd
, hdc
);
316 /* allocate and initialise a directory entry */
317 static Entry
* alloc_entry(void)
319 Entry
* entry
= HeapAlloc(GetProcessHeap(), 0, sizeof(Entry
));
321 #ifdef _SHELL_FOLDERS
323 entry
->folder
= NULL
;
330 /* free a directory entry */
331 static void free_entry(Entry
* entry
)
333 #ifdef _SHELL_FOLDERS
334 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
335 DestroyIcon(entry
->hicon
);
337 if (entry
->folder
&& entry
->folder
!=Globals
.iDesktop
)
338 IShellFolder_Release(entry
->folder
);
341 IMalloc_Free(Globals
.iMalloc
, entry
->pidl
);
344 HeapFree(GetProcessHeap(), 0, entry
);
347 /* recursively free all child entries */
348 static void free_entries(Entry
* dir
)
350 Entry
*entry
, *next
=dir
->down
;
366 static void read_directory_win(Entry
* dir
, LPCWSTR path
)
368 Entry
* first_entry
= NULL
;
372 int level
= dir
->level
+ 1;
373 WIN32_FIND_DATAW w32fd
;
375 #ifndef _NO_EXTENSIONS
379 WCHAR buffer
[MAX_PATH
], *p
;
380 for(p
=buffer
; *path
; )
387 hFind
= FindFirstFileW(buffer
, &w32fd
);
389 if (hFind
!= INVALID_HANDLE_VALUE
) {
391 #ifdef _NO_EXTENSIONS
392 /* hide directory entry "." */
393 if (w32fd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
394 LPCWSTR name
= w32fd
.cFileName
;
396 if (name
[0]=='.' && name
[1]=='\0')
400 entry
= alloc_entry();
408 memcpy(&entry
->data
, &w32fd
, sizeof(WIN32_FIND_DATAW
));
411 entry
->expanded
= FALSE
;
412 entry
->scanned
= FALSE
;
413 entry
->level
= level
;
415 #ifndef _NO_EXTENSIONS
416 entry
->etype
= ET_WINDOWS
;
417 entry
->bhfi_valid
= FALSE
;
419 lstrcpyW(p
, entry
->data
.cFileName
);
421 hFile
= CreateFileW(buffer
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
422 0, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0);
424 if (hFile
!= INVALID_HANDLE_VALUE
) {
425 if (GetFileInformationByHandle(hFile
, &entry
->bhfi
))
426 entry
->bhfi_valid
= TRUE
;
433 } while(FindNextFileW(hFind
, &w32fd
));
441 dir
->down
= first_entry
;
446 static Entry
* find_entry_win(Entry
* dir
, LPCWSTR name
)
450 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
452 LPCWSTR q
= entry
->data
.cFileName
;
455 if (!*p
|| *p
== '\\' || *p
== '/')
457 } while(tolower(*p
++) == tolower(*q
++));
460 q
= entry
->data
.cAlternateFileName
;
463 if (!*p
|| *p
== '\\' || *p
== '/')
465 } while(tolower(*p
++) == tolower(*q
++));
472 static Entry
* read_tree_win(Root
* root
, LPCWSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
474 WCHAR buffer
[MAX_PATH
];
475 Entry
* entry
= &root
->entry
;
479 HCURSOR old_cursor
= SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_WAIT
));
481 #ifndef _NO_EXTENSIONS
482 entry
->etype
= ET_WINDOWS
;
486 while(*s
&& *s
!= '\\' && *s
!= '/')
489 while(*s
== '\\' || *s
== '/')
495 read_directory(entry
, buffer
, sortOrder
, hwnd
);
498 entry
->expanded
= TRUE
;
503 entry
= find_entry_win(entry
, s
);
506 SetCursor(old_cursor
);
512 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
514 static BOOL
time_to_filetime(const time_t* t
, FILETIME
* ftime
)
516 struct tm
* tm
= gmtime(t
);
522 stime
.wYear
= tm
->tm_year
+1900;
523 stime
.wMonth
= tm
->tm_mon
+1;
524 /* stime.wDayOfWeek */
525 stime
.wDay
= tm
->tm_mday
;
526 stime
.wHour
= tm
->tm_hour
;
527 stime
.wMinute
= tm
->tm_min
;
528 stime
.wSecond
= tm
->tm_sec
;
529 stime
.wMilliseconds
= 0;
531 return SystemTimeToFileTime(&stime
, ftime
);
534 static void read_directory_unix(Entry
* dir
, LPCWSTR path
)
536 Entry
* first_entry
= NULL
;
541 int level
= dir
->level
+ 1;
542 char cpath
[MAX_PATH
];
544 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, cpath
, MAX_PATH
, NULL
, NULL
);
545 pdir
= opendir(cpath
);
550 char buffer
[MAX_PATH
], *p
;
553 for(p
=buffer
,s
=cpath
; *s
; )
556 if (p
==buffer
|| p
[-1]!='/')
559 while((ent
=readdir(pdir
))) {
560 entry
= alloc_entry();
568 entry
->etype
= ET_UNIX
;
570 strcpy(p
, ent
->d_name
);
571 MultiByteToWideChar(CP_UNIXCP
, 0, p
, -1, entry
->data
.cFileName
, MAX_PATH
);
573 if (!stat(buffer
, &st
)) {
574 entry
->data
.dwFileAttributes
= p
[0]=='.'? FILE_ATTRIBUTE_HIDDEN
: 0;
576 if (S_ISDIR(st
.st_mode
))
577 entry
->data
.dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
579 entry
->data
.nFileSizeLow
= st
.st_size
& 0xFFFFFFFF;
580 entry
->data
.nFileSizeHigh
= st
.st_size
>> 32;
582 memset(&entry
->data
.ftCreationTime
, 0, sizeof(FILETIME
));
583 time_to_filetime(&st
.st_atime
, &entry
->data
.ftLastAccessTime
);
584 time_to_filetime(&st
.st_mtime
, &entry
->data
.ftLastWriteTime
);
586 entry
->bhfi
.nFileIndexLow
= ent
->d_ino
;
587 entry
->bhfi
.nFileIndexHigh
= 0;
589 entry
->bhfi
.nNumberOfLinks
= st
.st_nlink
;
591 entry
->bhfi_valid
= TRUE
;
593 entry
->data
.nFileSizeLow
= 0;
594 entry
->data
.nFileSizeHigh
= 0;
595 entry
->bhfi_valid
= FALSE
;
600 entry
->expanded
= FALSE
;
601 entry
->scanned
= FALSE
;
602 entry
->level
= level
;
613 dir
->down
= first_entry
;
617 static Entry
* find_entry_unix(Entry
* dir
, LPCWSTR name
)
621 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
623 LPCWSTR q
= entry
->data
.cFileName
;
626 if (!*p
|| *p
== '/')
628 } while(*p
++ == *q
++);
634 static Entry
* read_tree_unix(Root
* root
, LPCWSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
636 WCHAR buffer
[MAX_PATH
];
637 Entry
* entry
= &root
->entry
;
641 HCURSOR old_cursor
= SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_WAIT
));
643 entry
->etype
= ET_UNIX
;
646 while(*s
&& *s
!= '/')
655 read_directory(entry
, buffer
, sortOrder
, hwnd
);
658 entry
->expanded
= TRUE
;
663 entry
= find_entry_unix(entry
, s
);
666 SetCursor(old_cursor
);
671 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
674 #ifdef _SHELL_FOLDERS
676 static void free_strret(STRRET
* str
)
678 if (str
->uType
== STRRET_WSTR
)
679 IMalloc_Free(Globals
.iMalloc
, str
->UNION_MEMBER(pOleStr
));
682 static LPWSTR
wcscpyn(LPWSTR dest
, LPCWSTR source
, size_t count
)
687 for(s
=source
; count
&&(*d
++=*s
++); )
693 static void get_strretW(STRRET
* str
, const SHITEMID
* shiid
, LPWSTR buffer
, int len
)
697 wcscpyn(buffer
, str
->UNION_MEMBER(pOleStr
), len
);
701 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), -1, buffer
, len
);
705 MultiByteToWideChar(CP_ACP
, 0, str
->UNION_MEMBER(cStr
), -1, buffer
, len
);
710 static HRESULT
name_from_pidl(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPWSTR buffer
, int len
, SHGDNF flags
)
714 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, flags
, &str
);
717 get_strretW(&str
, &pidl
->mkid
, buffer
, len
);
726 static HRESULT
path_from_pidlW(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPWSTR buffer
, int len
)
730 /* SHGDN_FORPARSING: get full path of id list */
731 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, SHGDN_FORPARSING
, &str
);
734 get_strretW(&str
, &pidl
->mkid
, buffer
, len
);
743 /* create an item id list from a file system path */
745 static LPITEMIDLIST
get_path_pidl(LPWSTR path
, HWND hwnd
)
750 LPWSTR buffer
= path
;
752 hr
= IShellFolder_ParseDisplayName(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
760 /* convert an item id list from relative to absolute (=relative to the desktop) format */
762 static LPITEMIDLIST
get_to_absolute_pidl(Entry
* entry
, HWND hwnd
)
764 if (entry
->up
&& entry
->up
->etype
==ET_SHELL
) {
765 LPITEMIDLIST idl
= NULL
;
768 idl
= ILCombine(ILClone(entry
->pidl
), idl
);
773 } else if (entry
->etype
== ET_WINDOWS
) {
774 WCHAR path
[MAX_PATH
];
776 get_path(entry
, path
);
778 return get_path_pidl(path
, hwnd
);
779 } else if (entry
->pidl
)
780 return ILClone(entry
->pidl
);
786 static HICON
extract_icon(IShellFolder
* folder
, LPCITEMIDLIST pidl
)
788 IExtractIconW
* pExtract
;
790 if (SUCCEEDED(IShellFolder_GetUIObjectOf(folder
, 0, 1, (LPCITEMIDLIST
*)&pidl
, &IID_IExtractIconW
, 0, (LPVOID
*)&pExtract
))) {
791 WCHAR path
[_MAX_PATH
];
796 if (SUCCEEDED(IExtractIconW_GetIconLocation(pExtract
, GIL_FORSHELL
, path
, _MAX_PATH
, &idx
, &flags
))) {
797 if (!(flags
& GIL_NOTFILENAME
)) {
799 idx
= 0; /* special case for some control panel applications */
801 if ((int)ExtractIconExW(path
, idx
, 0, &hicon
, 1) > 0)
802 flags
&= ~GIL_DONTCACHE
;
804 HICON hIconLarge
= 0;
806 HRESULT hr
= IExtractIconW_Extract(pExtract
, path
, idx
, &hIconLarge
, &hicon
, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON
)));
809 DestroyIcon(hIconLarge
);
820 static Entry
* find_entry_shell(Entry
* dir
, LPCITEMIDLIST pidl
)
824 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
825 if (entry
->pidl
->mkid
.cb
== pidl
->mkid
.cb
&&
826 !memcmp(entry
->pidl
, pidl
, entry
->pidl
->mkid
.cb
))
833 static Entry
* read_tree_shell(Root
* root
, LPITEMIDLIST pidl
, SORT_ORDER sortOrder
, HWND hwnd
)
835 Entry
* entry
= &root
->entry
;
837 LPITEMIDLIST next_pidl
= pidl
;
838 IShellFolder
* folder
;
839 IShellFolder
* child
= NULL
;
842 HCURSOR old_cursor
= SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_WAIT
));
844 #ifndef _NO_EXTENSIONS
845 entry
->etype
= ET_SHELL
;
848 folder
= Globals
.iDesktop
;
851 entry
->pidl
= next_pidl
;
852 entry
->folder
= folder
;
857 /* copy first element of item idlist */
858 next_pidl
= IMalloc_Alloc(Globals
.iMalloc
, pidl
->mkid
.cb
+sizeof(USHORT
));
859 memcpy(next_pidl
, pidl
, pidl
->mkid
.cb
);
860 ((LPITEMIDLIST
)((LPBYTE
)next_pidl
+pidl
->mkid
.cb
))->mkid
.cb
= 0;
862 hr
= IShellFolder_BindToObject(folder
, next_pidl
, 0, &IID_IShellFolder
, (void**)&child
);
866 read_directory(entry
, NULL
, sortOrder
, hwnd
);
869 entry
->expanded
= TRUE
;
871 next
= find_entry_shell(entry
, next_pidl
);
878 /* go to next element */
879 pidl
= (LPITEMIDLIST
) ((LPBYTE
)pidl
+pidl
->mkid
.cb
);
882 SetCursor(old_cursor
);
888 static void fill_w32fdata_shell(IShellFolder
* folder
, LPCITEMIDLIST pidl
, SFGAOF attribs
, WIN32_FIND_DATAW
* w32fdata
)
890 if (!(attribs
& SFGAO_FILESYSTEM
) ||
891 FAILED(SHGetDataFromIDListW(folder
, pidl
, SHGDFIL_FINDDATA
, w32fdata
, sizeof(WIN32_FIND_DATAW
)))) {
892 WIN32_FILE_ATTRIBUTE_DATA fad
;
893 IDataObject
* pDataObj
;
895 STGMEDIUM medium
= {0, {0}, 0};
896 FORMATETC fmt
= {Globals
.cfStrFName
, 0, DVASPECT_CONTENT
, -1, TYMED_HGLOBAL
};
898 HRESULT hr
= IShellFolder_GetUIObjectOf(folder
, 0, 1, &pidl
, &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
901 hr
= IDataObject_GetData(pDataObj
, &fmt
, &medium
);
903 IDataObject_Release(pDataObj
);
906 LPCWSTR path
= GlobalLock(medium
.UNION_MEMBER(hGlobal
));
907 UINT sem_org
= SetErrorMode(SEM_FAILCRITICALERRORS
);
909 if (GetFileAttributesExW(path
, GetFileExInfoStandard
, &fad
)) {
910 w32fdata
->dwFileAttributes
= fad
.dwFileAttributes
;
911 w32fdata
->ftCreationTime
= fad
.ftCreationTime
;
912 w32fdata
->ftLastAccessTime
= fad
.ftLastAccessTime
;
913 w32fdata
->ftLastWriteTime
= fad
.ftLastWriteTime
;
915 if (!(fad
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)) {
916 w32fdata
->nFileSizeLow
= fad
.nFileSizeLow
;
917 w32fdata
->nFileSizeHigh
= fad
.nFileSizeHigh
;
921 SetErrorMode(sem_org
);
923 GlobalUnlock(medium
.UNION_MEMBER(hGlobal
));
924 GlobalFree(medium
.UNION_MEMBER(hGlobal
));
929 if (attribs
& (SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
))
930 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
932 if (attribs
& SFGAO_READONLY
)
933 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_READONLY
;
935 if (attribs
& SFGAO_COMPRESSED
)
936 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_COMPRESSED
;
940 static void read_directory_shell(Entry
* dir
, HWND hwnd
)
942 IShellFolder
* folder
= dir
->folder
;
943 int level
= dir
->level
+ 1;
949 Entry
* first_entry
= NULL
;
956 hr
= IShellFolder_EnumObjects(folder
, hwnd
, SHCONTF_FOLDERS
|SHCONTF_NONFOLDERS
|SHCONTF_INCLUDEHIDDEN
|SHCONTF_SHAREABLE
|SHCONTF_STORAGE
, &idlist
);
960 #define FETCH_ITEM_COUNT 32
961 LPITEMIDLIST pidls
[FETCH_ITEM_COUNT
];
966 memset(pidls
, 0, sizeof(pidls
));
968 hr
= IEnumIDList_Next(idlist
, FETCH_ITEM_COUNT
, pidls
, &cnt
);
975 for(n
=0; n
<cnt
; ++n
) {
976 entry
= alloc_entry();
984 memset(&entry
->data
, 0, sizeof(WIN32_FIND_DATAW
));
985 entry
->bhfi_valid
= FALSE
;
987 attribs
= ~SFGAO_FILESYSTEM
; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
989 hr
= IShellFolder_GetAttributesOf(folder
, 1, (LPCITEMIDLIST
*)&pidls
[n
], &attribs
);
992 if (attribs
!= (SFGAOF
)~SFGAO_FILESYSTEM
) {
993 fill_w32fdata_shell(folder
, pidls
[n
], attribs
, &entry
->data
);
995 entry
->bhfi_valid
= TRUE
;
1001 entry
->pidl
= pidls
[n
];
1003 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1004 hr
= IShellFolder_BindToObject(folder
, pidls
[n
], 0, &IID_IShellFolder
, (void**)&child
);
1007 entry
->folder
= child
;
1009 entry
->folder
= NULL
;
1012 entry
->folder
= NULL
;
1014 if (!entry
->data
.cFileName
[0])
1015 /*hr = */name_from_pidl(folder
, pidls
[n
], entry
->data
.cFileName
, MAX_PATH
, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1017 /* get display icons for files and virtual objects */
1018 if (!(entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ||
1019 !(attribs
& SFGAO_FILESYSTEM
)) {
1020 entry
->hicon
= extract_icon(folder
, pidls
[n
]);
1023 entry
->hicon
= (HICON
)-1; /* don't try again later */
1028 entry
->expanded
= FALSE
;
1029 entry
->scanned
= FALSE
;
1030 entry
->level
= level
;
1032 #ifndef _NO_EXTENSIONS
1033 entry
->etype
= ET_SHELL
;
1034 entry
->bhfi_valid
= FALSE
;
1041 IEnumIDList_Release(idlist
);
1047 dir
->down
= first_entry
;
1048 dir
->scanned
= TRUE
;
1051 #endif /* _SHELL_FOLDERS */
1054 /* sort order for different directory/file types */
1063 /* distinguish between ".", ".." and any other directory names */
1064 static int TypeOrderFromDirname(LPCWSTR name
)
1066 if (name
[0] == '.') {
1067 if (name
[1] == '\0')
1068 return TO_DOT
; /* "." */
1070 if (name
[1]=='.' && name
[2]=='\0')
1071 return TO_DOTDOT
; /* ".." */
1074 return TO_OTHER_DIR
; /* anything else */
1077 /* directories first... */
1078 static int compareType(const WIN32_FIND_DATAW
* fd1
, const WIN32_FIND_DATAW
* fd2
)
1080 int order1
= fd1
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1081 int order2
= fd2
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1083 /* Handle "." and ".." as special case and move them at the very first beginning. */
1084 if (order1
==TO_DIR
&& order2
==TO_DIR
) {
1085 order1
= TypeOrderFromDirname(fd1
->cFileName
);
1086 order2
= TypeOrderFromDirname(fd2
->cFileName
);
1089 return order2
==order1
? 0: order1
<order2
? -1: 1;
1093 static int compareName(const void* arg1
, const void* arg2
)
1095 const WIN32_FIND_DATAW
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1096 const WIN32_FIND_DATAW
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1098 int cmp
= compareType(fd1
, fd2
);
1102 return lstrcmpiW(fd1
->cFileName
, fd2
->cFileName
);
1105 static int compareExt(const void* arg1
, const void* arg2
)
1107 const WIN32_FIND_DATAW
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1108 const WIN32_FIND_DATAW
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1109 const WCHAR
*name1
, *name2
, *ext1
, *ext2
;
1111 int cmp
= compareType(fd1
, fd2
);
1115 name1
= fd1
->cFileName
;
1116 name2
= fd2
->cFileName
;
1118 ext1
= strrchrW(name1
, '.');
1119 ext2
= strrchrW(name2
, '.');
1131 cmp
= lstrcmpiW(ext1
, ext2
);
1135 return lstrcmpiW(name1
, name2
);
1138 static int compareSize(const void* arg1
, const void* arg2
)
1140 const WIN32_FIND_DATAW
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1141 const WIN32_FIND_DATAW
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1143 int cmp
= compareType(fd1
, fd2
);
1147 cmp
= fd2
->nFileSizeHigh
- fd1
->nFileSizeHigh
;
1154 cmp
= fd2
->nFileSizeLow
- fd1
->nFileSizeLow
;
1156 return cmp
<0? -1: cmp
>0? 1: 0;
1159 static int compareDate(const void* arg1
, const void* arg2
)
1161 const WIN32_FIND_DATAW
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1162 const WIN32_FIND_DATAW
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1164 int cmp
= compareType(fd1
, fd2
);
1168 return CompareFileTime(&fd2
->ftLastWriteTime
, &fd1
->ftLastWriteTime
);
1172 static int (*sortFunctions
[])(const void* arg1
, const void* arg2
) = {
1173 compareName
, /* SORT_NAME */
1174 compareExt
, /* SORT_EXT */
1175 compareSize
, /* SORT_SIZE */
1176 compareDate
/* SORT_DATE */
1180 static void SortDirectory(Entry
* dir
, SORT_ORDER sortOrder
)
1187 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1191 array
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(Entry
*));
1194 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1197 /* call qsort with the appropriate compare function */
1198 qsort(array
, len
, sizeof(array
[0]), sortFunctions
[sortOrder
]);
1200 dir
->down
= array
[0];
1202 for(p
=array
; --len
; p
++)
1207 HeapFree(GetProcessHeap(), 0, array
);
1212 static void read_directory(Entry
* dir
, LPCWSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
1214 WCHAR buffer
[MAX_PATH
];
1219 #ifdef _SHELL_FOLDERS
1220 if (dir
->etype
== ET_SHELL
)
1222 read_directory_shell(dir
, hwnd
);
1224 if (Globals
.prescan_node
) {
1233 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1234 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1235 read_directory_shell(entry
, hwnd
);
1236 SortDirectory(entry
, sortOrder
);
1242 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1243 if (dir
->etype
== ET_UNIX
)
1245 read_directory_unix(dir
, path
);
1247 if (Globals
.prescan_node
) {
1256 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1257 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1258 lstrcpyW(d
, entry
->data
.cFileName
);
1259 read_directory_unix(entry
, buffer
);
1260 SortDirectory(entry
, sortOrder
);
1267 read_directory_win(dir
, path
);
1269 if (Globals
.prescan_node
) {
1278 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1279 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1280 lstrcpyW(d
, entry
->data
.cFileName
);
1281 read_directory_win(entry
, buffer
);
1282 SortDirectory(entry
, sortOrder
);
1287 SortDirectory(dir
, sortOrder
);
1291 static Entry
* read_tree(Root
* root
, LPCWSTR path
, LPITEMIDLIST pidl
, LPWSTR drv
, SORT_ORDER sortOrder
, HWND hwnd
)
1293 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1294 static const WCHAR sSlash
[] = {'/', '\0'};
1296 static const WCHAR sBackslash
[] = {'\\', '\0'};
1298 #ifdef _SHELL_FOLDERS
1301 /* read shell namespace tree */
1302 root
->drive_type
= DRIVE_UNKNOWN
;
1305 load_string(root
->volname
, sizeof(root
->volname
)/sizeof(root
->volname
[0]), IDS_DESKTOP
);
1307 load_string(root
->fs
, sizeof(root
->fs
)/sizeof(root
->fs
[0]), IDS_SHELL
);
1309 return read_tree_shell(root
, pidl
, sortOrder
, hwnd
);
1313 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1316 /* read unix file system tree */
1317 root
->drive_type
= GetDriveTypeW(path
);
1319 lstrcatW(drv
, sSlash
);
1320 load_string(root
->volname
, sizeof(root
->volname
)/sizeof(root
->volname
[0]), IDS_ROOT_FS
);
1322 load_string(root
->fs
, sizeof(root
->fs
)/sizeof(root
->fs
[0]), IDS_UNIXFS
);
1324 lstrcpyW(root
->path
, sSlash
);
1326 return read_tree_unix(root
, path
, sortOrder
, hwnd
);
1330 /* read WIN32 file system tree */
1331 root
->drive_type
= GetDriveTypeW(path
);
1333 lstrcatW(drv
, sBackslash
);
1334 GetVolumeInformationW(drv
, root
->volname
, _MAX_FNAME
, 0, 0, &root
->fs_flags
, root
->fs
, _MAX_DIR
);
1336 lstrcpyW(root
->path
, drv
);
1338 return read_tree_win(root
, path
, sortOrder
, hwnd
);
1342 /* flags to filter different file types */
1344 TF_DIRECTORIES
= 0x01,
1346 TF_DOCUMENTS
= 0x04,
1353 static ChildWnd
* alloc_child_window(LPCWSTR path
, LPITEMIDLIST pidl
, HWND hwnd
)
1355 WCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
1356 WCHAR dir_path
[MAX_PATH
];
1357 static const WCHAR sAsterics
[] = {'*', '\0'};
1358 static const WCHAR sTitleFmt
[] = {'%','s',' ','-',' ','%','s','\0'};
1360 ChildWnd
* child
= HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd
));
1361 Root
* root
= &child
->root
;
1364 memset(child
, 0, sizeof(ChildWnd
));
1366 child
->left
.treePane
= TRUE
;
1367 child
->left
.visible_cols
= 0;
1369 child
->right
.treePane
= FALSE
;
1370 #ifndef _NO_EXTENSIONS
1371 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_INDEX
|COL_LINKS
;
1373 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
;
1376 child
->pos
.length
= sizeof(WINDOWPLACEMENT
);
1377 child
->pos
.flags
= 0;
1378 child
->pos
.showCmd
= SW_SHOWNORMAL
;
1379 child
->pos
.rcNormalPosition
.left
= CW_USEDEFAULT
;
1380 child
->pos
.rcNormalPosition
.top
= CW_USEDEFAULT
;
1381 child
->pos
.rcNormalPosition
.right
= CW_USEDEFAULT
;
1382 child
->pos
.rcNormalPosition
.bottom
= CW_USEDEFAULT
;
1384 child
->focus_pane
= 0;
1385 child
->split_pos
= DEFAULT_SPLIT_POS
;
1386 child
->sortOrder
= SORT_NAME
;
1387 child
->header_wdths_ok
= FALSE
;
1391 lstrcpyW(child
->path
, path
);
1393 _wsplitpath(path
, drv
, dir
, name
, ext
);
1396 lstrcpyW(child
->filter_pattern
, sAsterics
);
1397 child
->filter_flags
= TF_ALL
;
1399 root
->entry
.level
= 0;
1401 lstrcpyW(dir_path
, drv
);
1402 lstrcatW(dir_path
, dir
);
1403 entry
= read_tree(root
, dir_path
, pidl
, drv
, child
->sortOrder
, hwnd
);
1405 #ifdef _SHELL_FOLDERS
1406 if (root
->entry
.etype
== ET_SHELL
)
1407 load_string(root
->entry
.data
.cFileName
, sizeof(root
->entry
.data
.cFileName
)/sizeof(root
->entry
.data
.cFileName
[0]), IDS_DESKTOP
);
1410 wsprintfW(root
->entry
.data
.cFileName
, sTitleFmt
, drv
, root
->fs
);
1412 root
->entry
.data
.dwFileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1414 child
->left
.root
= &root
->entry
;
1415 child
->right
.root
= NULL
;
1417 set_curdir(child
, entry
, 0, hwnd
);
1423 /* free all memory associated with a child window */
1424 static void free_child_window(ChildWnd
* child
)
1426 free_entries(&child
->root
.entry
);
1427 HeapFree(GetProcessHeap(), 0, child
);
1431 /* get full path of specified directory entry */
1432 static void get_path(Entry
* dir
, PWSTR path
)
1438 #ifdef _SHELL_FOLDERS
1439 if (dir
->etype
== ET_SHELL
)
1449 hr
= IShellFolder_GetAttributesOf(dir
->folder
, 1, (LPCITEMIDLIST
*)&dir
->pidl
, &attribs
);
1451 if (SUCCEEDED(hr
) && (attribs
&SFGAO_FILESYSTEM
)) {
1452 IShellFolder
* parent
= dir
->up
? dir
->up
->folder
: Globals
.iDesktop
;
1454 hr
= path_from_pidlW(parent
, dir
->pidl
, path
, MAX_PATH
);
1460 for(entry
=dir
; entry
; level
++) {
1466 name
= entry
->data
.cFileName
;
1469 for(l
=0; *s
&& *s
!= '/' && *s
!= '\\'; s
++)
1475 memmove(path
+l
+1, path
, len
*sizeof(WCHAR
));
1476 memcpy(path
+1, name
, l
*sizeof(WCHAR
));
1479 #ifndef _NO_EXTENSIONS
1480 if (entry
->etype
== ET_UNIX
)
1489 memmove(path
+l
, path
, len
*sizeof(WCHAR
));
1490 memcpy(path
, name
, l
*sizeof(WCHAR
));
1497 #ifndef _NO_EXTENSIONS
1498 if (entry
->etype
== ET_UNIX
)
1509 static windowOptions
load_registry_settings(void)
1517 RegOpenKeyExW( HKEY_CURRENT_USER
, registry_key
,
1518 0, KEY_QUERY_VALUE
, &hKey
);
1520 size
= sizeof(DWORD
);
1522 if( RegQueryValueExW( hKey
, reg_start_x
, NULL
, &type
,
1523 (LPBYTE
) &opts
.start_x
, &size
) != ERROR_SUCCESS
)
1524 opts
.start_x
= CW_USEDEFAULT
;
1526 if( RegQueryValueExW( hKey
, reg_start_y
, NULL
, &type
,
1527 (LPBYTE
) &opts
.start_y
, &size
) != ERROR_SUCCESS
)
1528 opts
.start_y
= CW_USEDEFAULT
;
1530 if( RegQueryValueExW( hKey
, reg_width
, NULL
, &type
,
1531 (LPBYTE
) &opts
.width
, &size
) != ERROR_SUCCESS
)
1532 opts
.width
= CW_USEDEFAULT
;
1534 if( RegQueryValueExW( hKey
, reg_height
, NULL
, &type
,
1535 (LPBYTE
) &opts
.height
, &size
) != ERROR_SUCCESS
)
1536 opts
.height
= CW_USEDEFAULT
;
1537 size
=sizeof(logfont
);
1538 if( RegQueryValueExW( hKey
, reg_logfont
, NULL
, &type
,
1539 (LPBYTE
) &logfont
, &size
) != ERROR_SUCCESS
)
1540 GetObjectW(GetStockObject(DEFAULT_GUI_FONT
),sizeof(logfont
),&logfont
);
1542 RegCloseKey( hKey
);
1544 Globals
.hfont
= CreateFontIndirectW(&logfont
);
1548 static void save_registry_settings(void)
1555 wi
.cbSize
= sizeof( WINDOWINFO
);
1556 GetWindowInfo(Globals
.hMainWnd
, &wi
);
1557 width
= wi
.rcWindow
.right
- wi
.rcWindow
.left
;
1558 height
= wi
.rcWindow
.bottom
- wi
.rcWindow
.top
;
1560 if ( RegOpenKeyExW( HKEY_CURRENT_USER
, registry_key
,
1561 0, KEY_SET_VALUE
, &hKey
) != ERROR_SUCCESS
)
1563 /* Unable to save registry settings - try to create key */
1564 if ( RegCreateKeyExW( HKEY_CURRENT_USER
, registry_key
,
1565 0, NULL
, REG_OPTION_NON_VOLATILE
,
1566 KEY_SET_VALUE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
1568 /* FIXME: Cannot create key */
1572 /* Save all of the settings */
1573 RegSetValueExW( hKey
, reg_start_x
, 0, REG_DWORD
,
1574 (LPBYTE
) &wi
.rcWindow
.left
, sizeof(DWORD
) );
1575 RegSetValueExW( hKey
, reg_start_y
, 0, REG_DWORD
,
1576 (LPBYTE
) &wi
.rcWindow
.top
, sizeof(DWORD
) );
1577 RegSetValueExW( hKey
, reg_width
, 0, REG_DWORD
,
1578 (LPBYTE
) &width
, sizeof(DWORD
) );
1579 RegSetValueExW( hKey
, reg_height
, 0, REG_DWORD
,
1580 (LPBYTE
) &height
, sizeof(DWORD
) );
1581 GetObjectW(Globals
.hfont
, sizeof(logfont
), &logfont
);
1582 RegSetValueExW( hKey
, reg_logfont
, 0, REG_BINARY
,
1583 (LPBYTE
)&logfont
, sizeof(LOGFONTW
) );
1585 /* TODO: Save more settings here (List vs. Detailed View, etc.) */
1586 RegCloseKey( hKey
);
1589 static void resize_frame_rect(HWND hwnd
, PRECT prect
)
1594 if (IsWindowVisible(Globals
.htoolbar
)) {
1595 SendMessageW(Globals
.htoolbar
, WM_SIZE
, 0, 0);
1596 GetClientRect(Globals
.htoolbar
, &rt
);
1597 prect
->top
= rt
.bottom
+3;
1598 prect
->bottom
-= rt
.bottom
+3;
1601 if (IsWindowVisible(Globals
.hdrivebar
)) {
1602 SendMessageW(Globals
.hdrivebar
, WM_SIZE
, 0, 0);
1603 GetClientRect(Globals
.hdrivebar
, &rt
);
1604 new_top
= --prect
->top
+ rt
.bottom
+3;
1605 MoveWindow(Globals
.hdrivebar
, 0, prect
->top
, rt
.right
, new_top
, TRUE
);
1606 prect
->top
= new_top
;
1607 prect
->bottom
-= rt
.bottom
+2;
1610 if (IsWindowVisible(Globals
.hstatusbar
)) {
1611 int parts
[] = {300, 500};
1613 SendMessageW(Globals
.hstatusbar
, WM_SIZE
, 0, 0);
1614 SendMessageW(Globals
.hstatusbar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
1615 GetClientRect(Globals
.hstatusbar
, &rt
);
1616 prect
->bottom
-= rt
.bottom
;
1619 MoveWindow(Globals
.hmdiclient
, prect
->left
-1,prect
->top
-1,prect
->right
+2,prect
->bottom
+1, TRUE
);
1622 static void resize_frame(HWND hwnd
, int cx
, int cy
)
1631 resize_frame_rect(hwnd
, &rect
);
1634 static void resize_frame_client(HWND hwnd
)
1638 GetClientRect(hwnd
, &rect
);
1640 resize_frame_rect(hwnd
, &rect
);
1644 static HHOOK hcbthook
;
1645 static ChildWnd
* newchild
= NULL
;
1647 static LRESULT CALLBACK
CBTProc(int code
, WPARAM wparam
, LPARAM lparam
)
1649 if (code
==HCBT_CREATEWND
&& newchild
) {
1650 ChildWnd
* child
= newchild
;
1653 child
->hwnd
= (HWND
) wparam
;
1654 SetWindowLongPtrW(child
->hwnd
, GWLP_USERDATA
, (LPARAM
)child
);
1657 return CallNextHookEx(hcbthook
, code
, wparam
, lparam
);
1660 static HWND
create_child_window(ChildWnd
* child
)
1662 MDICREATESTRUCTW mcs
;
1665 mcs
.szClass
= sWINEFILETREE
;
1666 mcs
.szTitle
= child
->path
;
1667 mcs
.hOwner
= Globals
.hInstance
;
1668 mcs
.x
= child
->pos
.rcNormalPosition
.left
;
1669 mcs
.y
= child
->pos
.rcNormalPosition
.top
;
1670 mcs
.cx
= child
->pos
.rcNormalPosition
.right
-child
->pos
.rcNormalPosition
.left
;
1671 mcs
.cy
= child
->pos
.rcNormalPosition
.bottom
-child
->pos
.rcNormalPosition
.top
;
1675 hcbthook
= SetWindowsHookExW(WH_CBT
, CBTProc
, 0, GetCurrentThreadId());
1678 child
->hwnd
= (HWND
)SendMessageW(Globals
.hmdiclient
, WM_MDICREATE
, 0, (LPARAM
)&mcs
);
1680 UnhookWindowsHookEx(hcbthook
);
1684 UnhookWindowsHookEx(hcbthook
);
1686 SendMessageW(child
->left
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1687 SendMessageW(child
->right
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1689 idx
= SendMessageW(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)child
->left
.cur
);
1690 SendMessageW(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
1695 #define RFF_NODEFAULT 0x02 /* No default item selected. */
1697 static void WineFile_OnRun( HWND hwnd
)
1699 static const WCHAR shell32_dll
[] = {'S','H','E','L','L','3','2','.','D','L','L',0};
1700 void (WINAPI
*pRunFileDlgAW
)(HWND
, HICON
, LPWSTR
, LPWSTR
, LPWSTR
, DWORD
);
1701 HMODULE hshell
= GetModuleHandleW( shell32_dll
);
1703 pRunFileDlgAW
= (void*)GetProcAddress(hshell
, (LPCSTR
)61);
1704 if (pRunFileDlgAW
) pRunFileDlgAW( hwnd
, 0, NULL
, NULL
, NULL
, RFF_NODEFAULT
);
1707 static INT_PTR CALLBACK
DestinationDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1709 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1713 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, lparam
);
1714 SetWindowTextW(GetDlgItem(hwnd
, 201), (LPCWSTR
)lparam
);
1718 int id
= (int)wparam
;
1722 LPWSTR dest
= (LPWSTR
)GetWindowLongPtrW(hwnd
, GWLP_USERDATA
);
1723 GetWindowTextW(GetDlgItem(hwnd
, 201), dest
, MAX_PATH
);
1724 EndDialog(hwnd
, id
);
1728 EndDialog(hwnd
, id
);
1732 MessageBoxW(hwnd
, RS(b1
,IDS_NO_IMPL
), RS(b2
,IDS_WINEFILE
), MB_OK
);
1744 struct FilterDialog
{
1745 WCHAR pattern
[MAX_PATH
];
1749 static INT_PTR CALLBACK
FilterDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1751 static struct FilterDialog
* dlg
;
1755 dlg
= (struct FilterDialog
*) lparam
;
1756 SetWindowTextW(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
);
1757 set_check(hwnd
, IDC_VIEW_TYPE_DIRECTORIES
, dlg
->flags
&TF_DIRECTORIES
);
1758 set_check(hwnd
, IDC_VIEW_TYPE_PROGRAMS
, dlg
->flags
&TF_PROGRAMS
);
1759 set_check(hwnd
, IDC_VIEW_TYPE_DOCUMENTS
, dlg
->flags
&TF_DOCUMENTS
);
1760 set_check(hwnd
, IDC_VIEW_TYPE_OTHERS
, dlg
->flags
&TF_OTHERS
);
1761 set_check(hwnd
, IDC_VIEW_TYPE_HIDDEN
, dlg
->flags
&TF_HIDDEN
);
1765 int id
= (int)wparam
;
1770 GetWindowTextW(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
, MAX_PATH
);
1772 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_DIRECTORIES
) ? TF_DIRECTORIES
: 0;
1773 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_PROGRAMS
) ? TF_PROGRAMS
: 0;
1774 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_DOCUMENTS
) ? TF_DOCUMENTS
: 0;
1775 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_OTHERS
) ? TF_OTHERS
: 0;
1776 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_HIDDEN
) ? TF_HIDDEN
: 0;
1780 EndDialog(hwnd
, id
);
1781 } else if (id
== IDCANCEL
)
1782 EndDialog(hwnd
, id
);
1791 struct PropertiesDialog
{
1792 WCHAR path
[MAX_PATH
];
1797 /* Structure used to store enumerated languages and code pages. */
1798 struct LANGANDCODEPAGE
{
1803 static LPCSTR InfoStrings
[] = {
1819 static void PropDlg_DisplayValue(HWND hlbox
, HWND hedit
)
1821 int idx
= SendMessageW(hlbox
, LB_GETCURSEL
, 0, 0);
1823 if (idx
!= LB_ERR
) {
1824 LPCWSTR pValue
= (LPCWSTR
)SendMessageW(hlbox
, LB_GETITEMDATA
, idx
, 0);
1827 SetWindowTextW(hedit
, pValue
);
1831 static void CheckForFileInfo(struct PropertiesDialog
* dlg
, HWND hwnd
, LPCWSTR strFilename
)
1833 static WCHAR sBackSlash
[] = {'\\','\0'};
1834 static WCHAR sTranslation
[] = {'\\','V','a','r','F','i','l','e','I','n','f','o','\\','T','r','a','n','s','l','a','t','i','o','n','\0'};
1835 static WCHAR sStringFileInfo
[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1836 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1837 DWORD dwVersionDataLen
= GetFileVersionInfoSizeW(strFilename
, NULL
);
1839 if (dwVersionDataLen
) {
1840 dlg
->pVersionData
= HeapAlloc(GetProcessHeap(), 0, dwVersionDataLen
);
1842 if (GetFileVersionInfoW(strFilename
, 0, dwVersionDataLen
, dlg
->pVersionData
)) {
1846 if (VerQueryValueW(dlg
->pVersionData
, sBackSlash
, &pVal
, &nValLen
)) {
1847 if (nValLen
== sizeof(VS_FIXEDFILEINFO
)) {
1848 VS_FIXEDFILEINFO
* pFixedFileInfo
= (VS_FIXEDFILEINFO
*)pVal
;
1849 char buffer
[BUFFER_LEN
];
1851 sprintf(buffer
, "%d.%d.%d.%d",
1852 HIWORD(pFixedFileInfo
->dwFileVersionMS
), LOWORD(pFixedFileInfo
->dwFileVersionMS
),
1853 HIWORD(pFixedFileInfo
->dwFileVersionLS
), LOWORD(pFixedFileInfo
->dwFileVersionLS
));
1855 SetDlgItemTextA(hwnd
, IDC_STATIC_PROP_VERSION
, buffer
);
1859 /* Read the list of languages and code pages. */
1860 if (VerQueryValueW(dlg
->pVersionData
, sTranslation
, &pVal
, &nValLen
)) {
1861 struct LANGANDCODEPAGE
* pTranslate
= (struct LANGANDCODEPAGE
*)pVal
;
1862 struct LANGANDCODEPAGE
* pEnd
= (struct LANGANDCODEPAGE
*)((LPBYTE
)pVal
+nValLen
);
1864 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
1866 /* Read the file description for each language and code page. */
1867 for(; pTranslate
<pEnd
; ++pTranslate
) {
1870 for(p
=InfoStrings
; *p
; ++p
) {
1871 WCHAR subblock
[200];
1876 LPCSTR pInfoString
= *p
;
1877 MultiByteToWideChar(CP_ACP
, 0, pInfoString
, -1, infoStr
, 100);
1878 wsprintfW(subblock
, sStringFileInfo
, pTranslate
->wLanguage
, pTranslate
->wCodePage
, infoStr
);
1880 /* Retrieve file description for language and code page */
1881 if (VerQueryValueW(dlg
->pVersionData
, subblock
, (PVOID
)&pTxt
, &nValLen
)) {
1882 int idx
= SendMessageW(hlbox
, LB_ADDSTRING
, 0L, (LPARAM
)infoStr
);
1883 SendMessageW(hlbox
, LB_SETITEMDATA
, idx
, (LPARAM
)pTxt
);
1888 SendMessageW(hlbox
, LB_SETCURSEL
, 0, 0);
1890 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
1896 static INT_PTR CALLBACK
PropertiesDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1898 static struct PropertiesDialog
* dlg
;
1901 case WM_INITDIALOG
: {
1902 static const WCHAR sByteFmt
[] = {'%','s',' ','B','y','t','e','s','\0'};
1903 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1904 LPWIN32_FIND_DATAW pWFD
;
1906 dlg
= (struct PropertiesDialog
*) lparam
;
1907 pWFD
= (LPWIN32_FIND_DATAW
)&dlg
->entry
.data
;
1909 GetWindowTextW(hwnd
, b1
, MAX_PATH
);
1910 wsprintfW(b2
, b1
, pWFD
->cFileName
);
1911 SetWindowTextW(hwnd
, b2
);
1913 format_date(&pWFD
->ftLastWriteTime
, b1
, COL_DATE
|COL_TIME
);
1914 SetWindowTextW(GetDlgItem(hwnd
, IDC_STATIC_PROP_LASTCHANGE
), b1
);
1916 format_longlong( b1
, ((ULONGLONG
)pWFD
->nFileSizeHigh
<< 32) | pWFD
->nFileSizeLow
);
1917 wsprintfW(b2
, sByteFmt
, b1
);
1918 SetWindowTextW(GetDlgItem(hwnd
, IDC_STATIC_PROP_SIZE
), b2
);
1920 SetWindowTextW(GetDlgItem(hwnd
, IDC_STATIC_PROP_FILENAME
), pWFD
->cFileName
);
1921 SetWindowTextW(GetDlgItem(hwnd
, IDC_STATIC_PROP_PATH
), dlg
->path
);
1923 set_check(hwnd
, IDC_CHECK_READONLY
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_READONLY
);
1924 set_check(hwnd
, IDC_CHECK_ARCHIVE
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_ARCHIVE
);
1925 set_check(hwnd
, IDC_CHECK_COMPRESSED
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_COMPRESSED
);
1926 set_check(hwnd
, IDC_CHECK_HIDDEN
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_HIDDEN
);
1927 set_check(hwnd
, IDC_CHECK_SYSTEM
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_SYSTEM
);
1929 CheckForFileInfo(dlg
, hwnd
, dlg
->path
);
1933 int id
= (int)wparam
;
1935 switch(HIWORD(wparam
)) {
1936 case LBN_SELCHANGE
: {
1937 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
1938 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
1943 if (id
==IDOK
|| id
==IDCANCEL
)
1944 EndDialog(hwnd
, id
);
1950 HeapFree(GetProcessHeap(), 0, dlg
->pVersionData
);
1951 dlg
->pVersionData
= NULL
;
1958 static void show_properties_dlg(Entry
* entry
, HWND hwnd
)
1960 struct PropertiesDialog dlg
;
1962 memset(&dlg
, 0, sizeof(struct PropertiesDialog
));
1963 get_path(entry
, dlg
.path
);
1964 memcpy(&dlg
.entry
, entry
, sizeof(Entry
));
1966 DialogBoxParamW(Globals
.hInstance
, MAKEINTRESOURCEW(IDD_DIALOG_PROPERTIES
), hwnd
, PropertiesDialogDlgProc
, (LPARAM
)&dlg
);
1970 #ifndef _NO_EXTENSIONS
1972 static struct FullScreenParameters
{
1982 static void frame_get_clientspace(HWND hwnd
, PRECT prect
)
1986 if (!IsIconic(hwnd
))
1987 GetClientRect(hwnd
, prect
);
1991 GetWindowPlacement(hwnd
, &wp
);
1993 prect
->left
= prect
->top
= 0;
1994 prect
->right
= wp
.rcNormalPosition
.right
-wp
.rcNormalPosition
.left
-
1995 2*(GetSystemMetrics(SM_CXSIZEFRAME
)+GetSystemMetrics(SM_CXEDGE
));
1996 prect
->bottom
= wp
.rcNormalPosition
.bottom
-wp
.rcNormalPosition
.top
-
1997 2*(GetSystemMetrics(SM_CYSIZEFRAME
)+GetSystemMetrics(SM_CYEDGE
))-
1998 GetSystemMetrics(SM_CYCAPTION
)-GetSystemMetrics(SM_CYMENUSIZE
);
2001 if (IsWindowVisible(Globals
.htoolbar
)) {
2002 GetClientRect(Globals
.htoolbar
, &rt
);
2003 prect
->top
+= rt
.bottom
+2;
2006 if (IsWindowVisible(Globals
.hdrivebar
)) {
2007 GetClientRect(Globals
.hdrivebar
, &rt
);
2008 prect
->top
+= rt
.bottom
+2;
2011 if (IsWindowVisible(Globals
.hstatusbar
)) {
2012 GetClientRect(Globals
.hstatusbar
, &rt
);
2013 prect
->bottom
-= rt
.bottom
;
2017 static BOOL
toggle_fullscreen(HWND hwnd
)
2021 if ((g_fullscreen
.mode
=!g_fullscreen
.mode
)) {
2022 GetWindowRect(hwnd
, &g_fullscreen
.orgPos
);
2023 g_fullscreen
.wasZoomed
= IsZoomed(hwnd
);
2025 Frame_CalcFrameClient(hwnd
, &rt
);
2026 MapWindowPoints( hwnd
, 0, (POINT
*)&rt
, 2 );
2028 rt
.left
= g_fullscreen
.orgPos
.left
-rt
.left
;
2029 rt
.top
= g_fullscreen
.orgPos
.top
-rt
.top
;
2030 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+g_fullscreen
.orgPos
.right
-rt
.right
;
2031 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+g_fullscreen
.orgPos
.bottom
-rt
.bottom
;
2033 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
2035 MoveWindow(hwnd
, g_fullscreen
.orgPos
.left
, g_fullscreen
.orgPos
.top
,
2036 g_fullscreen
.orgPos
.right
-g_fullscreen
.orgPos
.left
,
2037 g_fullscreen
.orgPos
.bottom
-g_fullscreen
.orgPos
.top
, TRUE
);
2039 if (g_fullscreen
.wasZoomed
)
2040 ShowWindow(hwnd
, WS_MAXIMIZE
);
2043 return g_fullscreen
.mode
;
2046 static void fullscreen_move(HWND hwnd
)
2049 GetWindowRect(hwnd
, &pos
);
2051 Frame_CalcFrameClient(hwnd
, &rt
);
2052 MapWindowPoints( hwnd
, 0, (POINT
*)&rt
, 2 );
2054 rt
.left
= pos
.left
-rt
.left
;
2055 rt
.top
= pos
.top
-rt
.top
;
2056 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+pos
.right
-rt
.right
;
2057 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+pos
.bottom
-rt
.bottom
;
2059 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
2065 static void toggle_child(HWND hwnd
, UINT cmd
, HWND hchild
)
2067 BOOL vis
= IsWindowVisible(hchild
);
2069 CheckMenuItem(Globals
.hMenuOptions
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
2071 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
2073 #ifndef _NO_EXTENSIONS
2074 if (g_fullscreen
.mode
)
2075 fullscreen_move(hwnd
);
2078 resize_frame_client(hwnd
);
2081 static BOOL
activate_drive_window(LPCWSTR path
)
2083 WCHAR drv1
[_MAX_DRIVE
], drv2
[_MAX_DRIVE
];
2086 _wsplitpath(path
, drv1
, 0, 0, 0);
2088 /* search for a already open window for the same drive */
2089 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2090 ChildWnd
* child
= (ChildWnd
*)GetWindowLongPtrW(child_wnd
, GWLP_USERDATA
);
2093 _wsplitpath(child
->root
.path
, drv2
, 0, 0, 0);
2095 if (!lstrcmpiW(drv2
, drv1
)) {
2096 SendMessageW(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2098 if (IsIconic(child_wnd
))
2099 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2109 #ifndef _NO_EXTENSIONS
2110 static BOOL
activate_fs_window(LPCWSTR filesys
)
2114 /* search for a already open window of the given file system name */
2115 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2116 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtrW(child_wnd
, GWLP_USERDATA
);
2119 if (!lstrcmpiW(child
->root
.fs
, filesys
)) {
2120 SendMessageW(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2122 if (IsIconic(child_wnd
))
2123 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2132 #endif /* _NO_EXTENSIONS */
2134 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
2136 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2140 if (Globals
.saveSettings
)
2141 save_registry_settings();
2143 DestroyWindow(hwnd
);
2145 /* clear handle variables */
2146 Globals
.hMenuFrame
= 0;
2147 Globals
.hMenuView
= 0;
2148 Globals
.hMenuOptions
= 0;
2149 Globals
.hMainWnd
= 0;
2150 Globals
.hmdiclient
= 0;
2151 Globals
.hdrivebar
= 0;
2158 case WM_INITMENUPOPUP
: {
2159 HWND hwndClient
= (HWND
)SendMessageW(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2161 if (!SendMessageW(hwndClient
, WM_INITMENUPOPUP
, wparam
, lparam
))
2166 UINT cmd
= LOWORD(wparam
);
2167 HWND hwndClient
= (HWND
)SendMessageW(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2169 if (SendMessageW(hwndClient
, WM_DISPATCH_COMMAND
, wparam
, lparam
))
2172 if (cmd
>=ID_DRIVE_FIRST
&& cmd
<=ID_DRIVE_FIRST
+0xFF) {
2173 WCHAR drv
[_MAX_DRIVE
], path
[MAX_PATH
];
2175 LPCWSTR root
= Globals
.drives
;
2178 for(i
=cmd
-ID_DRIVE_FIRST
; i
--; root
++)
2182 if (activate_drive_window(root
))
2185 _wsplitpath(root
, drv
, 0, 0, 0);
2187 if (!SetCurrentDirectoryW(drv
)) {
2188 display_error(hwnd
, GetLastError());
2192 GetCurrentDirectoryW(MAX_PATH
, path
); /*TODO: store last directory per drive */
2193 child
= alloc_child_window(path
, NULL
, hwnd
);
2195 if (!create_child_window(child
))
2196 HeapFree(GetProcessHeap(), 0, child
);
2197 } else switch(cmd
) {
2199 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
2202 case ID_WINDOW_NEW
: {
2203 WCHAR path
[MAX_PATH
];
2206 GetCurrentDirectoryW(MAX_PATH
, path
);
2207 child
= alloc_child_window(path
, NULL
, hwnd
);
2209 if (!create_child_window(child
))
2210 HeapFree(GetProcessHeap(), 0, child
);
2217 case ID_WINDOW_CASCADE
:
2218 SendMessageW(Globals
.hmdiclient
, WM_MDICASCADE
, 0, 0);
2221 case ID_WINDOW_TILE_HORZ
:
2222 SendMessageW(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
2225 case ID_WINDOW_TILE_VERT
:
2226 SendMessageW(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
2229 case ID_WINDOW_ARRANGE
:
2230 SendMessageW(Globals
.hmdiclient
, WM_MDIICONARRANGE
, 0, 0);
2233 case ID_SELECT_FONT
:
2237 case ID_VIEW_TOOL_BAR
:
2238 toggle_child(hwnd
, cmd
, Globals
.htoolbar
);
2241 case ID_VIEW_DRIVE_BAR
:
2242 toggle_child(hwnd
, cmd
, Globals
.hdrivebar
);
2245 case ID_VIEW_STATUSBAR
:
2246 toggle_child(hwnd
, cmd
, Globals
.hstatusbar
);
2249 case ID_VIEW_SAVESETTINGS
:
2250 Globals
.saveSettings
= !Globals
.saveSettings
;
2251 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_SAVESETTINGS
,
2252 Globals
.saveSettings
? MF_CHECKED
: MF_UNCHECKED
);
2256 WineFile_OnRun( hwnd
);
2259 case ID_CONNECT_NETWORK_DRIVE
: {
2260 DWORD ret
= WNetConnectionDialog(hwnd
, RESOURCETYPE_DISK
);
2261 if (ret
== NO_ERROR
)
2263 else if (ret
!= (DWORD
)-1) {
2264 if (ret
== ERROR_EXTENDED_ERROR
)
2265 display_network_error(hwnd
);
2267 display_error(hwnd
, ret
);
2271 case ID_DISCONNECT_NETWORK_DRIVE
: {
2272 DWORD ret
= WNetDisconnectDialog(hwnd
, RESOURCETYPE_DISK
);
2273 if (ret
== NO_ERROR
)
2275 else if (ret
!= (DWORD
)-1) {
2276 if (ret
== ERROR_EXTENDED_ERROR
)
2277 display_network_error(hwnd
);
2279 display_error(hwnd
, ret
);
2284 WinHelpW(hwnd
, RS(b1
,IDS_WINEFILE
), HELP_INDEX
, 0);
2287 #ifndef _NO_EXTENSIONS
2288 case ID_VIEW_FULLSCREEN
:
2289 CheckMenuItem(Globals
.hMenuOptions
, cmd
, toggle_fullscreen(hwnd
)?MF_CHECKED
:0);
2293 case ID_DRIVE_UNIX_FS
: {
2294 WCHAR path
[MAX_PATH
];
2295 char cpath
[MAX_PATH
];
2298 if (activate_fs_window(RS(b1
,IDS_UNIXFS
)))
2301 getcwd(cpath
, MAX_PATH
);
2302 MultiByteToWideChar(CP_UNIXCP
, 0, cpath
, -1, path
, MAX_PATH
);
2303 child
= alloc_child_window(path
, NULL
, hwnd
);
2305 if (!create_child_window(child
))
2306 HeapFree(GetProcessHeap(), 0, child
);
2309 #ifdef _SHELL_FOLDERS
2310 case ID_DRIVE_SHELL_NS
: {
2311 WCHAR path
[MAX_PATH
];
2314 if (activate_fs_window(RS(b1
,IDS_SHELL
)))
2317 GetCurrentDirectoryW(MAX_PATH
, path
);
2318 child
= alloc_child_window(path
, get_path_pidl(path
,hwnd
), hwnd
);
2320 if (!create_child_window(child
))
2321 HeapFree(GetProcessHeap(), 0, child
);
2326 /*TODO: There are even more menu items! */
2329 ShellAboutW(hwnd
, RS(b1
,IDS_WINEFILE
), NULL
,
2330 LoadImageW( Globals
.hInstance
, MAKEINTRESOURCEW(IDI_WINEFILE
),
2331 IMAGE_ICON
, 48, 48, LR_SHARED
));
2335 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2336 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2337 else */if ((cmd
<IDW_FIRST_CHILD
|| cmd
>=IDW_FIRST_CHILD
+0x100) &&
2338 (cmd
<SC_SIZE
|| cmd
>SC_RESTORE
))
2339 MessageBoxW(hwnd
, RS(b2
,IDS_NO_IMPL
), RS(b1
,IDS_WINEFILE
), MB_OK
);
2341 return DefFrameProcW(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2346 resize_frame(hwnd
, LOWORD(lparam
), HIWORD(lparam
));
2347 break; /* do not pass message to DefFrameProcW */
2349 case WM_DEVICECHANGE
:
2350 SendMessageW(hwnd
, WM_COMMAND
, MAKELONG(ID_REFRESH
,0), 0);
2353 #ifndef _NO_EXTENSIONS
2354 case WM_GETMINMAXINFO
: {
2355 LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
2357 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2358 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2361 case FRM_CALC_CLIENT
:
2362 frame_get_clientspace(hwnd
, (PRECT
)lparam
);
2364 #endif /* _NO_EXTENSIONS */
2367 return DefFrameProcW(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2374 static WCHAR g_pos_names
[COLUMNS
][20] = {
2378 static const int g_pos_align
[] = {
2380 HDF_LEFT
, /* Name */
2381 HDF_RIGHT
, /* Size */
2382 HDF_LEFT
, /* CDate */
2383 #ifndef _NO_EXTENSIONS
2384 HDF_LEFT
, /* ADate */
2385 HDF_LEFT
, /* MDate */
2386 HDF_LEFT
, /* Index */
2387 HDF_CENTER
, /* Links */
2389 HDF_CENTER
, /* Attributes */
2390 #ifndef _NO_EXTENSIONS
2391 HDF_LEFT
/* Security */
2395 static void resize_tree(ChildWnd
* child
, int cx
, int cy
)
2397 HDWP hdwp
= BeginDeferWindowPos(4);
2405 cx
= child
->split_pos
+ SPLIT_WIDTH
/2;
2407 #ifndef _NO_EXTENSIONS
2415 SendMessageW(child
->left
.hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hdl
);
2417 DeferWindowPos(hdwp
, child
->left
.hwndHeader
, wp
.hwndInsertAfter
,
2418 wp
.x
-1, wp
.y
, child
->split_pos
-SPLIT_WIDTH
/2+1, wp
.cy
, wp
.flags
);
2419 DeferWindowPos(hdwp
, child
->right
.hwndHeader
, wp
.hwndInsertAfter
,
2420 rt
.left
+cx
+1, wp
.y
, wp
.cx
-cx
+2, wp
.cy
, wp
.flags
);
2422 #endif /* _NO_EXTENSIONS */
2424 DeferWindowPos(hdwp
, child
->left
.hwnd
, 0, rt
.left
, rt
.top
, child
->split_pos
-SPLIT_WIDTH
/2-rt
.left
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
2425 DeferWindowPos(hdwp
, child
->right
.hwnd
, 0, rt
.left
+cx
+1, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
2427 EndDeferWindowPos(hdwp
);
2431 #ifndef _NO_EXTENSIONS
2433 static HWND
create_header(HWND parent
, Pane
* pane
, UINT id
)
2438 HWND hwnd
= CreateWindowW(WC_HEADERW
, 0, WS_CHILD
|WS_VISIBLE
|HDS_HORZ
|HDS_FULLDRAG
/*TODO: |HDS_BUTTONS + sort orders*/,
2439 0, 0, 0, 0, parent
, (HMENU
)ULongToHandle(id
), Globals
.hInstance
, 0);
2443 SendMessageW(hwnd
, WM_SETFONT
, (WPARAM
)GetStockObject(DEFAULT_GUI_FONT
), FALSE
);
2445 hdi
.mask
= HDI_TEXT
|HDI_WIDTH
|HDI_FORMAT
;
2447 for(idx
=0; idx
<COLUMNS
; idx
++) {
2448 hdi
.pszText
= g_pos_names
[idx
];
2449 hdi
.fmt
= HDF_STRING
| g_pos_align
[idx
];
2450 hdi
.cxy
= pane
->widths
[idx
];
2451 SendMessageW(hwnd
, HDM_INSERTITEMW
, idx
, (LPARAM
)&hdi
);
2457 #endif /* _NO_EXTENSIONS */
2460 static void init_output(HWND hwnd
)
2462 static const WCHAR s1000
[] = {'1','0','0','0','\0'};
2465 HDC hdc
= GetDC(hwnd
);
2467 if (GetNumberFormatW(LOCALE_USER_DEFAULT
, 0, s1000
, 0, b
, 16) > 4)
2468 Globals
.num_sep
= b
[1];
2470 Globals
.num_sep
= '.';
2472 old_font
= SelectObject(hdc
, Globals
.hfont
);
2473 GetTextExtentPoint32W(hdc
, sSpace
, 1, &Globals
.spaceSize
);
2474 SelectObject(hdc
, old_font
);
2475 ReleaseDC(hwnd
, hdc
);
2478 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
);
2481 /* calculate preferred width for all visible columns */
2483 static BOOL
calc_widths(Pane
* pane
, BOOL anyway
)
2485 int col
, x
, cx
, spc
=3*Globals
.spaceSize
.cx
;
2486 int entries
= SendMessageW(pane
->hwnd
, LB_GETCOUNT
, 0, 0);
2487 int orgWidths
[COLUMNS
];
2488 int orgPositions
[COLUMNS
+1];
2494 memcpy(orgWidths
, pane
->widths
, sizeof(orgWidths
));
2495 memcpy(orgPositions
, pane
->positions
, sizeof(orgPositions
));
2498 for(col
=0; col
<COLUMNS
; col
++)
2499 pane
->widths
[col
] = 0;
2501 hdc
= GetDC(pane
->hwnd
);
2502 hfontOld
= SelectObject(hdc
, Globals
.hfont
);
2504 for(cnt
=0; cnt
<entries
; cnt
++) {
2505 Entry
* entry
= (Entry
*)SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, cnt
, 0);
2514 dis
.hwndItem
= pane
->hwnd
;
2516 dis
.rcItem
.left
= 0;
2518 dis
.rcItem
.right
= 0;
2519 dis
.rcItem
.bottom
= 0;
2520 /*dis.itemData = 0; */
2522 draw_item(pane
, &dis
, entry
, COLUMNS
);
2525 SelectObject(hdc
, hfontOld
);
2526 ReleaseDC(pane
->hwnd
, hdc
);
2529 for(col
=0; col
<COLUMNS
; col
++) {
2530 pane
->positions
[col
] = x
;
2531 cx
= pane
->widths
[col
];
2536 if (cx
< IMAGE_WIDTH
)
2539 pane
->widths
[col
] = cx
;
2545 pane
->positions
[COLUMNS
] = x
;
2547 SendMessageW(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, x
, 0);
2550 if (!anyway
&& !memcmp(orgWidths
, pane
->widths
, sizeof(orgWidths
)))
2553 /* don't move, if only collapsing an entry */
2554 if (!anyway
&& pane
->widths
[0]<orgWidths
[0] &&
2555 !memcmp(orgWidths
+1, pane
->widths
+1, sizeof(orgWidths
)-sizeof(int))) {
2556 pane
->widths
[0] = orgWidths
[0];
2557 memcpy(pane
->positions
, orgPositions
, sizeof(orgPositions
));
2562 InvalidateRect(pane
->hwnd
, 0, TRUE
);
2568 #ifndef _NO_EXTENSIONS
2569 /* calculate one preferred column width */
2571 static void calc_single_width(Pane
* pane
, int col
)
2575 int entries
= SendMessageW(pane
->hwnd
, LB_GETCOUNT
, 0, 0);
2579 pane
->widths
[col
] = 0;
2581 hdc
= GetDC(pane
->hwnd
);
2582 hfontOld
= SelectObject(hdc
, Globals
.hfont
);
2584 for(cnt
=0; cnt
<entries
; cnt
++) {
2585 Entry
* entry
= (Entry
*)SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, cnt
, 0);
2593 dis
.hwndItem
= pane
->hwnd
;
2595 dis
.rcItem
.left
= 0;
2597 dis
.rcItem
.right
= 0;
2598 dis
.rcItem
.bottom
= 0;
2599 /*dis.itemData = 0; */
2601 draw_item(pane
, &dis
, entry
, col
);
2604 SelectObject(hdc
, hfontOld
);
2605 ReleaseDC(pane
->hwnd
, hdc
);
2607 cx
= pane
->widths
[col
];
2610 cx
+= 3*Globals
.spaceSize
.cx
;
2612 if (cx
< IMAGE_WIDTH
)
2616 pane
->widths
[col
] = cx
;
2618 x
= pane
->positions
[col
] + cx
;
2620 for(; col
<COLUMNS
-1; ) {
2621 pane
->positions
[++col
] = x
;
2622 x
+= pane
->widths
[col
];
2625 SendMessageW(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, x
, 0);
2627 #endif /* _NO_EXTENSIONS */
2630 static BOOL
pattern_match(LPCWSTR str
, LPCWSTR pattern
)
2632 for( ; *str
&&*pattern
; str
++,pattern
++) {
2633 if (*pattern
== '*') {
2635 while(*pattern
== '*');
2641 if (*str
==*pattern
&& pattern_match(str
, pattern
))
2646 else if (*str
!=*pattern
&& *pattern
!='?')
2650 if (*str
|| *pattern
)
2651 if (*pattern
!='*' || pattern
[1]!='\0')
2657 static BOOL
pattern_imatch(LPCWSTR str
, LPCWSTR pattern
)
2659 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2662 lstrcpyW(b2
, pattern
);
2666 return pattern_match(b1
, b2
);
2676 static enum FILE_TYPE
get_file_type(LPCWSTR filename
);
2679 /* insert listbox entries after index idx */
2681 static int insert_entries(Pane
* pane
, Entry
* dir
, LPCWSTR pattern
, int filter_flags
, int idx
)
2688 ShowWindow(pane
->hwnd
, SW_HIDE
);
2690 for(; entry
; entry
=entry
->next
) {
2692 if (pane
->treePane
&& !(entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
2696 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
2697 /* don't display entries "." and ".." in the left pane */
2698 if (pane
->treePane
&& entry
->data
.cFileName
[0] == '.')
2700 #ifndef _NO_EXTENSIONS
2701 entry
->data
.cFileName
[1] == '\0' ||
2703 (entry
->data
.cFileName
[1] == '.' && entry
->data
.cFileName
[2] == '\0'))
2706 /* filter directories in right pane */
2707 if (!pane
->treePane
&& !(filter_flags
&TF_DIRECTORIES
))
2711 /* filter using the file name pattern */
2713 if (!pattern_imatch(entry
->data
.cFileName
, pattern
))
2716 /* filter system and hidden files */
2717 if (!(filter_flags
&TF_HIDDEN
) && (entry
->data
.dwFileAttributes
&(FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
)))
2720 /* filter looking at the file type */
2721 if ((filter_flags
&(TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
)) != (TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
))
2722 switch(get_file_type(entry
->data
.cFileName
)) {
2724 if (!(filter_flags
& TF_PROGRAMS
))
2729 if (!(filter_flags
& TF_DOCUMENTS
))
2733 default: /* TF_OTHERS */
2734 if (!(filter_flags
& TF_OTHERS
))
2741 SendMessageW(pane
->hwnd
, LB_INSERTSTRING
, idx
, (LPARAM
)entry
);
2743 if (pane
->treePane
&& entry
->expanded
)
2744 idx
= insert_entries(pane
, entry
->down
, pattern
, filter_flags
, idx
);
2747 ShowWindow(pane
->hwnd
, SW_SHOW
);
2753 static void format_bytes(LPWSTR buffer
, LONGLONG bytes
)
2755 static const WCHAR sFmtSmall
[] = {'%', 'u', 0};
2756 static const WCHAR sFmtBig
[] = {'%', '.', '1', 'f', ' ', '%', 's', '\0'};
2759 sprintfW(buffer
, sFmtSmall
, (DWORD
)bytes
);
2765 if (bytes
>= 1073741824) /* 1 GB */
2767 fBytes
= ((float)bytes
)/1073741824.f
+.5f
;
2768 resid
= IDS_UNIT_GB
;
2770 else if (bytes
>= 1048576) /* 1 MB */
2772 fBytes
= ((float)bytes
)/1048576.f
+.5f
;
2773 resid
= IDS_UNIT_MB
;
2775 else if (bytes
>= 1024) /* 1 kB */
2777 fBytes
= ((float)bytes
)/1024.f
+.5f
;
2778 resid
= IDS_UNIT_KB
;
2780 LoadStringW(Globals
.hInstance
, resid
, unit
, sizeof(unit
)/sizeof(*unit
));
2781 sprintfW(buffer
, sFmtBig
, fBytes
, unit
);
2785 static void set_space_status(void)
2787 ULARGE_INTEGER ulFreeBytesToCaller
, ulTotalBytes
, ulFreeBytes
;
2788 WCHAR fmt
[64], b1
[64], b2
[64], buffer
[BUFFER_LEN
];
2790 if (GetDiskFreeSpaceExW(NULL
, &ulFreeBytesToCaller
, &ulTotalBytes
, &ulFreeBytes
)) {
2792 format_bytes(b1
, ulFreeBytesToCaller
.QuadPart
);
2793 format_bytes(b2
, ulTotalBytes
.QuadPart
);
2794 args
[0] = (DWORD_PTR
)b1
;
2795 args
[1] = (DWORD_PTR
)b2
;
2796 FormatMessageW(FORMAT_MESSAGE_FROM_STRING
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
2797 RS(fmt
,IDS_FREE_SPACE_FMT
), 0, 0, buffer
,
2798 sizeof(buffer
)/sizeof(*buffer
), (__ms_va_list
*)args
);
2800 lstrcpyW(buffer
, sQMarks
);
2802 SendMessageW(Globals
.hstatusbar
, SB_SETTEXTW
, 0, (LPARAM
)buffer
);
2806 static WNDPROC g_orgTreeWndProc
;
2808 static void create_tree_window(HWND parent
, Pane
* pane
, UINT id
, UINT id_header
, LPCWSTR pattern
, int filter_flags
)
2810 static const WCHAR sListBox
[] = {'L','i','s','t','B','o','x','\0'};
2812 static int s_init
= 0;
2813 Entry
* entry
= pane
->root
;
2815 pane
->hwnd
= CreateWindowW(sListBox
, sEmpty
, WS_CHILD
|WS_VISIBLE
|WS_HSCROLL
|WS_VSCROLL
|
2816 LBS_DISABLENOSCROLL
|LBS_NOINTEGRALHEIGHT
|LBS_OWNERDRAWFIXED
|LBS_NOTIFY
,
2817 0, 0, 0, 0, parent
, (HMENU
)ULongToHandle(id
), Globals
.hInstance
, 0);
2819 SetWindowLongPtrW(pane
->hwnd
, GWLP_USERDATA
, (LPARAM
)pane
);
2820 g_orgTreeWndProc
= (WNDPROC
)SetWindowLongPtrW(pane
->hwnd
, GWLP_WNDPROC
, (LPARAM
)TreeWndProc
);
2822 SendMessageW(pane
->hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, FALSE
);
2824 /* insert entries into listbox */
2826 insert_entries(pane
, entry
, pattern
, filter_flags
, -1);
2828 /* calculate column widths */
2831 init_output(pane
->hwnd
);
2834 calc_widths(pane
, TRUE
);
2836 #ifndef _NO_EXTENSIONS
2837 pane
->hwndHeader
= create_header(parent
, pane
, id_header
);
2842 static void InitChildWindow(ChildWnd
* child
)
2844 create_tree_window(child
->hwnd
, &child
->left
, IDW_TREE_LEFT
, IDW_HEADER_LEFT
, NULL
, TF_ALL
);
2845 create_tree_window(child
->hwnd
, &child
->right
, IDW_TREE_RIGHT
, IDW_HEADER_RIGHT
, child
->filter_pattern
, child
->filter_flags
);
2849 static void format_date(const FILETIME
* ft
, WCHAR
* buffer
, int visible_cols
)
2857 if (!ft
->dwLowDateTime
&& !ft
->dwHighDateTime
)
2860 if (!FileTimeToLocalFileTime(ft
, &lft
))
2861 {err
: lstrcpyW(buffer
,sQMarks
); return;}
2863 if (!FileTimeToSystemTime(&lft
, &systime
))
2866 if (visible_cols
& COL_DATE
) {
2867 len
= GetDateFormatW(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
, BUFFER_LEN
);
2872 if (visible_cols
& COL_TIME
) {
2874 buffer
[len
-1] = ' ';
2876 buffer
[len
++] = ' ';
2878 if (!GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
+len
, BUFFER_LEN
-len
))
2884 static void calc_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
)
2886 RECT rt
= {0, 0, 0, 0};
2888 DrawTextW(dis
->hDC
, str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
2890 if (rt
.right
> pane
->widths
[col
])
2891 pane
->widths
[col
] = rt
.right
;
2894 static void calc_tabbed_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
)
2896 RECT rt
= {0, 0, 0, 0};
2898 DrawTextW(dis
->hDC
, str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2899 /*FIXME rt (0,0) ??? */
2901 if (rt
.right
> pane
->widths
[col
])
2902 pane
->widths
[col
] = rt
.right
;
2906 static void output_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
, DWORD flags
)
2908 int x
= dis
->rcItem
.left
;
2911 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2912 rt
.top
= dis
->rcItem
.top
;
2913 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2914 rt
.bottom
= dis
->rcItem
.bottom
;
2916 DrawTextW(dis
->hDC
, str
, -1, &rt
, DT_SINGLELINE
|DT_NOPREFIX
|flags
);
2919 static void output_tabbed_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
)
2921 int x
= dis
->rcItem
.left
;
2924 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2925 rt
.top
= dis
->rcItem
.top
;
2926 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2927 rt
.bottom
= dis
->rcItem
.bottom
;
2929 DrawTextW(dis
->hDC
, str
, -1, &rt
, DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2932 static void output_number(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
)
2934 int x
= dis
->rcItem
.left
;
2941 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2942 rt
.top
= dis
->rcItem
.top
;
2943 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2944 rt
.bottom
= dis
->rcItem
.bottom
;
2949 /* insert number separator characters */
2950 pos
= lstrlenW(s
) % 3;
2956 *d
++ = Globals
.num_sep
;
2960 DrawTextW(dis
->hDC
, b
, d
-b
, &rt
, DT_RIGHT
|DT_SINGLELINE
|DT_NOPREFIX
|DT_END_ELLIPSIS
);
2964 static BOOL
is_exe_file(LPCWSTR ext
)
2966 static const WCHAR executable_extensions
[][4] = {
2971 #ifndef _NO_EXTENSIONS
2975 #endif /* _NO_EXTENSIONS */
2979 WCHAR ext_buffer
[_MAX_EXT
];
2980 const WCHAR (*p
)[4];
2984 for(s
=ext
+1,d
=ext_buffer
; (*d
=tolower(*s
)); s
++)
2987 for(p
=executable_extensions
; (*p
)[0]; p
++)
2988 if (!lstrcmpiW(ext_buffer
, *p
))
2994 static BOOL
is_registered_type(LPCWSTR ext
)
2996 /* check if there exists a classname for this file extension in the registry */
2997 if (!RegQueryValueW(HKEY_CLASSES_ROOT
, ext
, NULL
, NULL
))
3003 static enum FILE_TYPE
get_file_type(LPCWSTR filename
)
3005 LPCWSTR ext
= strrchrW(filename
, '.');
3009 if (is_exe_file(ext
))
3010 return FT_EXECUTABLE
;
3011 else if (is_registered_type(ext
))
3018 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
)
3020 WCHAR buffer
[BUFFER_LEN
];
3022 int visible_cols
= pane
->visible_cols
;
3023 COLORREF bkcolor
, textcolor
;
3024 RECT focusRect
= dis
->rcItem
;
3031 attrs
= entry
->data
.dwFileAttributes
;
3033 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) {
3034 if (entry
->data
.cFileName
[0] == '.' && entry
->data
.cFileName
[1] == '.'
3035 && entry
->data
.cFileName
[2] == '\0')
3036 img
= IMG_FOLDER_UP
;
3037 #ifndef _NO_EXTENSIONS
3038 else if (entry
->data
.cFileName
[0] == '.' && entry
->data
.cFileName
[1] == '\0')
3039 img
= IMG_FOLDER_CUR
;
3042 #ifdef _NO_EXTENSIONS
3045 (pane
->treePane
&& (dis
->itemState
&ODS_FOCUS
)))
3046 img
= IMG_OPEN_FOLDER
;
3050 switch(get_file_type(entry
->data
.cFileName
)) {
3051 case FT_EXECUTABLE
: img
= IMG_EXECUTABLE
; break;
3052 case FT_DOCUMENT
: img
= IMG_DOCUMENT
; break;
3053 default: img
= IMG_FILE
;
3061 if (pane
->treePane
) {
3063 img_pos
= dis
->rcItem
.left
+ entry
->level
*(IMAGE_WIDTH
+TREE_LINE_DX
);
3065 if (calcWidthCol
== -1) {
3067 int y
= dis
->rcItem
.top
+ IMAGE_HEIGHT
/2;
3070 HRGN hrgn_org
= CreateRectRgn(0, 0, 0, 0);
3073 rt_clip
.left
= dis
->rcItem
.left
;
3074 rt_clip
.top
= dis
->rcItem
.top
;
3075 rt_clip
.right
= dis
->rcItem
.left
+pane
->widths
[col
];
3076 rt_clip
.bottom
= dis
->rcItem
.bottom
;
3078 hrgn
= CreateRectRgnIndirect(&rt_clip
);
3080 if (!GetClipRgn(dis
->hDC
, hrgn_org
)) {
3081 DeleteObject(hrgn_org
);
3085 ExtSelectClipRgn(dis
->hDC
, hrgn
, RGN_AND
);
3088 if ((up
=entry
->up
) != NULL
) {
3089 MoveToEx(dis
->hDC
, img_pos
-IMAGE_WIDTH
/2, y
, 0);
3090 LineTo(dis
->hDC
, img_pos
-2, y
);
3092 x
= img_pos
- IMAGE_WIDTH
/2;
3095 x
-= IMAGE_WIDTH
+TREE_LINE_DX
;
3099 && (up
->next
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
3102 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
3103 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
3105 } while((up
=up
->up
) != NULL
);
3108 x
= img_pos
- IMAGE_WIDTH
/2;
3110 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
3111 LineTo(dis
->hDC
, x
, y
);
3115 && (entry
->next
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
)
3118 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
3120 SelectClipRgn(dis
->hDC
, hrgn_org
);
3121 if (hrgn_org
) DeleteObject(hrgn_org
);
3122 } else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
) {
3123 int right
= img_pos
+ IMAGE_WIDTH
- TREE_LINE_DX
;
3125 if (right
> pane
->widths
[col
])
3126 pane
->widths
[col
] = right
;
3129 img_pos
= dis
->rcItem
.left
;
3132 img_pos
= dis
->rcItem
.left
;
3134 if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3135 pane
->widths
[col
] = IMAGE_WIDTH
;
3138 if (calcWidthCol
== -1) {
3139 focusRect
.left
= img_pos
-2;
3141 #ifdef _NO_EXTENSIONS
3142 if (pane
->treePane
&& entry
) {
3145 DrawTextW(dis
->hDC
, entry
->data
.cFileName
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
3147 focusRect
.right
= dis
->rcItem
.left
+pane
->positions
[col
+1]+TREE_LINE_DX
+ rt
.right
+2;
3151 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
)
3152 textcolor
= COLOR_COMPRESSED
;
3154 #endif /* _NO_EXTENSIONS */
3155 textcolor
= RGB(0,0,0);
3157 if (dis
->itemState
& ODS_FOCUS
) {
3158 textcolor
= RGB(255,255,255);
3159 bkcolor
= COLOR_SELECTION
;
3161 bkcolor
= RGB(255,255,255);
3164 hbrush
= CreateSolidBrush(bkcolor
);
3165 FillRect(dis
->hDC
, &focusRect
, hbrush
);
3166 DeleteObject(hbrush
);
3168 SetBkMode(dis
->hDC
, TRANSPARENT
);
3169 SetTextColor(dis
->hDC
, textcolor
);
3171 cx
= pane
->widths
[col
];
3173 if (cx
&& img
!=IMG_NONE
) {
3174 if (cx
> IMAGE_WIDTH
)
3177 #ifdef _SHELL_FOLDERS
3178 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
3179 DrawIconEx(dis
->hDC
, img_pos
, dis
->rcItem
.top
, entry
->hicon
, cx
, GetSystemMetrics(SM_CYSMICON
), 0, 0, DI_NORMAL
);
3182 ImageList_DrawEx(Globals
.himl
, img
, dis
->hDC
,
3183 img_pos
, dis
->rcItem
.top
, cx
,
3184 IMAGE_HEIGHT
, bkcolor
, CLR_DEFAULT
, ILD_NORMAL
);
3191 #ifdef _NO_EXTENSIONS
3192 if (img
>= IMG_FOLDER_UP
)
3198 /* output file name */
3199 if (calcWidthCol
== -1)
3200 output_text(pane
, dis
, col
, entry
->data
.cFileName
, 0);
3201 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3202 calc_width(pane
, dis
, col
, entry
->data
.cFileName
);
3206 #ifdef _NO_EXTENSIONS
3207 if (!pane
->treePane
) {
3210 /* display file size */
3211 if (visible_cols
& COL_SIZE
) {
3212 #ifdef _NO_EXTENSIONS
3213 if (!(attrs
&FILE_ATTRIBUTE_DIRECTORY
))
3216 format_longlong( buffer
, ((ULONGLONG
)entry
->data
.nFileSizeHigh
<< 32) | entry
->data
.nFileSizeLow
);
3218 if (calcWidthCol
== -1)
3219 output_number(pane
, dis
, col
, buffer
);
3220 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3221 calc_width(pane
, dis
, col
, buffer
);/*TODO: not ever time enough */
3227 /* display file date */
3228 if (visible_cols
& (COL_DATE
|COL_TIME
)) {
3229 #ifndef _NO_EXTENSIONS
3230 format_date(&entry
->data
.ftCreationTime
, buffer
, visible_cols
);
3231 if (calcWidthCol
== -1)
3232 output_text(pane
, dis
, col
, buffer
, 0);
3233 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3234 calc_width(pane
, dis
, col
, buffer
);
3237 format_date(&entry
->data
.ftLastAccessTime
, buffer
, visible_cols
);
3238 if (calcWidthCol
== -1)
3239 output_text(pane
, dis
, col
, buffer
, 0);
3240 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3241 calc_width(pane
, dis
, col
, buffer
);
3243 #endif /* _NO_EXTENSIONS */
3245 format_date(&entry
->data
.ftLastWriteTime
, buffer
, visible_cols
);
3246 if (calcWidthCol
== -1)
3247 output_text(pane
, dis
, col
, buffer
, 0);
3248 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3249 calc_width(pane
, dis
, col
, buffer
);
3253 #ifndef _NO_EXTENSIONS
3254 if (entry
->bhfi_valid
) {
3255 if (visible_cols
& COL_INDEX
) {
3256 static const WCHAR fmtlow
[] = {'%','X',0};
3257 static const WCHAR fmthigh
[] = {'%','X','%','0','8','X',0};
3259 if (entry
->bhfi
.nFileIndexHigh
)
3260 wsprintfW(buffer
, fmthigh
,
3261 entry
->bhfi
.nFileIndexHigh
, entry
->bhfi
.nFileIndexLow
);
3263 wsprintfW(buffer
, fmtlow
, entry
->bhfi
.nFileIndexLow
);
3265 if (calcWidthCol
== -1)
3266 output_text(pane
, dis
, col
, buffer
, DT_RIGHT
);
3267 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3268 calc_width(pane
, dis
, col
, buffer
);
3273 if (visible_cols
& COL_LINKS
) {
3274 wsprintfW(buffer
, sNumFmt
, entry
->bhfi
.nNumberOfLinks
);
3276 if (calcWidthCol
== -1)
3277 output_text(pane
, dis
, col
, buffer
, DT_CENTER
);
3278 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3279 calc_width(pane
, dis
, col
, buffer
);
3285 #endif /* _NO_EXTENSIONS */
3287 /* show file attributes */
3288 if (visible_cols
& COL_ATTRIBUTES
) {
3289 #ifdef _NO_EXTENSIONS
3290 static const WCHAR s4Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3291 lstrcpyW(buffer
, s4Tabs
);
3293 static const WCHAR s11Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3294 lstrcpyW(buffer
, s11Tabs
);
3297 if (attrs
& FILE_ATTRIBUTE_NORMAL
) buffer
[ 0] = 'N';
3299 if (attrs
& FILE_ATTRIBUTE_READONLY
) buffer
[ 2] = 'R';
3300 if (attrs
& FILE_ATTRIBUTE_HIDDEN
) buffer
[ 4] = 'H';
3301 if (attrs
& FILE_ATTRIBUTE_SYSTEM
) buffer
[ 6] = 'S';
3302 if (attrs
& FILE_ATTRIBUTE_ARCHIVE
) buffer
[ 8] = 'A';
3303 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
) buffer
[10] = 'C';
3304 #ifndef _NO_EXTENSIONS
3305 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) buffer
[12] = 'D';
3306 if (attrs
& FILE_ATTRIBUTE_ENCRYPTED
) buffer
[14] = 'E';
3307 if (attrs
& FILE_ATTRIBUTE_TEMPORARY
) buffer
[16] = 'T';
3308 if (attrs
& FILE_ATTRIBUTE_SPARSE_FILE
) buffer
[18] = 'P';
3309 if (attrs
& FILE_ATTRIBUTE_REPARSE_POINT
) buffer
[20] = 'Q';
3310 if (attrs
& FILE_ATTRIBUTE_OFFLINE
) buffer
[22] = 'O';
3311 if (attrs
& FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
) buffer
[24] = 'X';
3312 #endif /* _NO_EXTENSIONS */
3315 if (calcWidthCol
== -1)
3316 output_tabbed_text(pane
, dis
, col
, buffer
);
3317 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3318 calc_tabbed_width(pane
, dis
, col
, buffer
);
3323 #ifdef _NO_EXTENSIONS
3326 /* draw focus frame */
3327 if ((dis
->itemState
&ODS_FOCUS
) && calcWidthCol
==-1) {
3328 /* Currently [04/2000] Wine neither behaves exactly the same */
3329 /* way as WIN 95 nor like Windows NT... */
3334 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
3335 LOGBRUSH lb
= {PS_SOLID
, RGB(255,255,255)};
3336 hpen
= ExtCreatePen(PS_COSMETIC
|PS_ALTERNATE
, 1, &lb
, 0, 0);
3338 hpen
= CreatePen(PS_DOT
, 0, RGB(255,255,255));
3340 lastPen
= SelectObject(dis
->hDC
, hpen
);
3341 lastBrush
= SelectObject(dis
->hDC
, GetStockObject(HOLLOW_BRUSH
));
3342 SetROP2(dis
->hDC
, R2_XORPEN
);
3343 Rectangle(dis
->hDC
, focusRect
.left
, focusRect
.top
, focusRect
.right
, focusRect
.bottom
);
3344 SelectObject(dis
->hDC
, lastBrush
);
3345 SelectObject(dis
->hDC
, lastPen
);
3348 #endif /* _NO_EXTENSIONS */
3352 #ifdef _NO_EXTENSIONS
3354 static void draw_splitbar(HWND hwnd
, int x
)
3357 HDC hdc
= GetDC(hwnd
);
3359 GetClientRect(hwnd
, &rt
);
3361 rt
.left
= x
- SPLIT_WIDTH
/2;
3362 rt
.right
= x
+ SPLIT_WIDTH
/2+1;
3364 InvertRect(hdc
, &rt
);
3366 ReleaseDC(hwnd
, hdc
);
3369 #endif /* _NO_EXTENSIONS */
3372 #ifndef _NO_EXTENSIONS
3374 static void set_header(Pane
* pane
)
3377 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3380 item
.mask
= HDI_WIDTH
;
3383 for(; x
+pane
->widths
[i
]<scroll_pos
&& i
<COLUMNS
; i
++) {
3384 x
+= pane
->widths
[i
];
3385 SendMessageW(pane
->hwndHeader
, HDM_SETITEMW
, i
, (LPARAM
)&item
);
3389 x
+= pane
->widths
[i
];
3390 item
.cxy
= x
- scroll_pos
;
3391 SendMessageW(pane
->hwndHeader
, HDM_SETITEMW
, i
++, (LPARAM
)&item
);
3393 for(; i
<COLUMNS
; i
++) {
3394 item
.cxy
= pane
->widths
[i
];
3395 x
+= pane
->widths
[i
];
3396 SendMessageW(pane
->hwndHeader
, HDM_SETITEMW
, i
, (LPARAM
)&item
);
3401 static LRESULT
pane_notify(Pane
* pane
, NMHDR
* pnmh
)
3403 switch(pnmh
->code
) {
3404 case HDN_ITEMCHANGEDW
: {
3405 LPNMHEADERW phdn
= (LPNMHEADERW
)pnmh
;
3406 int idx
= phdn
->iItem
;
3407 int dx
= phdn
->pitem
->cxy
- pane
->widths
[idx
];
3411 GetClientRect(pane
->hwnd
, &clnt
);
3413 pane
->widths
[idx
] += dx
;
3415 for(i
=idx
; ++i
<=COLUMNS
; )
3416 pane
->positions
[i
] += dx
;
3419 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3423 rt_scr
.left
= pane
->positions
[idx
+1]-scroll_pos
;
3425 rt_scr
.right
= clnt
.right
;
3426 rt_scr
.bottom
= clnt
.bottom
;
3428 rt_clip
.left
= pane
->positions
[idx
]-scroll_pos
;
3430 rt_clip
.right
= clnt
.right
;
3431 rt_clip
.bottom
= clnt
.bottom
;
3433 if (rt_scr
.left
< 0) rt_scr
.left
= 0;
3434 if (rt_clip
.left
< 0) rt_clip
.left
= 0;
3436 ScrollWindowEx(pane
->hwnd
, dx
, 0, &rt_scr
, &rt_clip
, 0, 0, SW_INVALIDATE
);
3438 rt_clip
.right
= pane
->positions
[idx
+1];
3439 RedrawWindow(pane
->hwnd
, &rt_clip
, 0, RDW_INVALIDATE
|RDW_UPDATENOW
);
3441 if (pnmh
->code
== HDN_ENDTRACKW
) {
3442 SendMessageW(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, pane
->positions
[COLUMNS
], 0);
3444 if (GetScrollPos(pane
->hwnd
, SB_HORZ
) != scroll_pos
)
3452 case HDN_DIVIDERDBLCLICKW
: {
3453 LPNMHEADERW phdn
= (LPNMHEADERW
)pnmh
;
3456 calc_single_width(pane
, phdn
->iItem
);
3457 item
.mask
= HDI_WIDTH
;
3458 item
.cxy
= pane
->widths
[phdn
->iItem
];
3460 SendMessageW(pane
->hwndHeader
, HDM_SETITEMW
, phdn
->iItem
, (LPARAM
)&item
);
3461 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3468 #endif /* _NO_EXTENSIONS */
3471 static void scan_entry(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3473 WCHAR path
[MAX_PATH
];
3474 HCURSOR old_cursor
= SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_WAIT
));
3476 /* delete sub entries in left pane */
3478 LRESULT res
= SendMessageW(child
->left
.hwnd
, LB_GETITEMDATA
, idx
+1, 0);
3479 Entry
* sub
= (Entry
*) res
;
3481 if (res
==LB_ERR
|| !sub
|| sub
->level
<=entry
->level
)
3484 SendMessageW(child
->left
.hwnd
, LB_DELETESTRING
, idx
+1, 0);
3487 /* empty right pane */
3488 SendMessageW(child
->right
.hwnd
, LB_RESETCONTENT
, 0, 0);
3490 /* release memory */
3491 free_entries(entry
);
3493 /* read contents from disk */
3494 #ifdef _SHELL_FOLDERS
3495 if (entry
->etype
== ET_SHELL
)
3497 read_directory(entry
, NULL
, child
->sortOrder
, hwnd
);
3502 get_path(entry
, path
);
3503 read_directory(entry
, path
, child
->sortOrder
, hwnd
);
3506 /* insert found entries in right pane */
3507 insert_entries(&child
->right
, entry
->down
, child
->filter_pattern
, child
->filter_flags
, -1);
3508 calc_widths(&child
->right
, FALSE
);
3509 #ifndef _NO_EXTENSIONS
3510 set_header(&child
->right
);
3513 child
->header_wdths_ok
= FALSE
;
3515 SetCursor(old_cursor
);
3519 /* expand a directory entry */
3521 static BOOL
expand_entry(ChildWnd
* child
, Entry
* dir
)
3526 if (!dir
|| dir
->expanded
|| !dir
->down
)
3531 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='\0' && p
->next
) {
3534 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='.' &&
3535 p
->data
.cFileName
[2]=='\0' && p
->next
)
3539 /* no subdirectories ? */
3540 if (!(p
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
3543 idx
= SendMessageW(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)dir
);
3545 dir
->expanded
= TRUE
;
3547 /* insert entries in left pane */
3548 insert_entries(&child
->left
, p
, NULL
, TF_ALL
, idx
);
3550 if (!child
->header_wdths_ok
) {
3551 if (calc_widths(&child
->left
, FALSE
)) {
3552 #ifndef _NO_EXTENSIONS
3553 set_header(&child
->left
);
3556 child
->header_wdths_ok
= TRUE
;
3564 static void collapse_entry(Pane
* pane
, Entry
* dir
)
3566 int idx
= SendMessageW(pane
->hwnd
, LB_FINDSTRING
, 0, (LPARAM
)dir
);
3568 ShowWindow(pane
->hwnd
, SW_HIDE
);
3570 /* hide sub entries */
3572 LRESULT res
= SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, idx
+1, 0);
3573 Entry
* sub
= (Entry
*) res
;
3575 if (res
==LB_ERR
|| !sub
|| sub
->level
<=dir
->level
)
3578 SendMessageW(pane
->hwnd
, LB_DELETESTRING
, idx
+1, 0);
3581 dir
->expanded
= FALSE
;
3583 ShowWindow(pane
->hwnd
, SW_SHOW
);
3587 static void refresh_right_pane(ChildWnd
* child
)
3589 SendMessageW(child
->right
.hwnd
, LB_RESETCONTENT
, 0, 0);
3590 insert_entries(&child
->right
, child
->right
.root
, child
->filter_pattern
, child
->filter_flags
, -1);
3591 calc_widths(&child
->right
, FALSE
);
3593 #ifndef _NO_EXTENSIONS
3594 set_header(&child
->right
);
3598 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3600 WCHAR path
[MAX_PATH
];
3607 child
->left
.cur
= entry
;
3609 child
->right
.root
= entry
->down
? entry
->down
: entry
;
3610 child
->right
.cur
= entry
;
3612 if (!entry
->scanned
)
3613 scan_entry(child
, entry
, idx
, hwnd
);
3615 refresh_right_pane(child
);
3617 get_path(entry
, path
);
3618 lstrcpyW(child
->path
, path
);
3620 if (child
->hwnd
) /* only change window title, if the window already exists */
3621 SetWindowTextW(child
->hwnd
, path
);
3624 if (SetCurrentDirectoryW(path
))
3629 static void refresh_child(ChildWnd
* child
)
3631 WCHAR path
[MAX_PATH
], drv
[_MAX_DRIVE
+1];
3635 get_path(child
->left
.cur
, path
);
3636 _wsplitpath(path
, drv
, NULL
, NULL
, NULL
);
3638 child
->right
.root
= NULL
;
3640 scan_entry(child
, &child
->root
.entry
, 0, child
->hwnd
);
3642 #ifdef _SHELL_FOLDERS
3644 if (child
->root
.entry
.etype
== ET_SHELL
)
3646 LPITEMIDLIST local_pidl
= get_path_pidl(path
,child
->hwnd
);
3648 entry
= read_tree(&child
->root
, NULL
, local_pidl
, drv
, child
->sortOrder
, child
->hwnd
);
3654 entry
= read_tree(&child
->root
, path
, NULL
, drv
, child
->sortOrder
, child
->hwnd
);
3657 entry
= &child
->root
.entry
;
3659 insert_entries(&child
->left
, child
->root
.entry
.down
, NULL
, TF_ALL
, 0);
3661 set_curdir(child
, entry
, 0, child
->hwnd
);
3663 idx
= SendMessageW(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)child
->left
.cur
);
3664 SendMessageW(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
3668 static void create_drive_bar(void)
3670 TBBUTTON drivebarBtn
= {0, 0, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0};
3671 #ifndef _NO_EXTENSIONS
3672 WCHAR b1
[BUFFER_LEN
];
3677 GetLogicalDriveStringsW(BUFFER_LEN
, Globals
.drives
);
3679 Globals
.hdrivebar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
,
3680 IDW_DRIVEBAR
, 2, Globals
.hInstance
, IDB_DRIVEBAR
, &drivebarBtn
,
3681 0, 16, 13, 16, 13, sizeof(TBBUTTON
));
3683 #ifndef _NO_EXTENSIONS
3685 /* insert unix file system button */
3689 SendMessageW(Globals
.hdrivebar
, TB_ADDSTRINGW
, 0, (LPARAM
)b1
);
3691 drivebarBtn
.idCommand
= ID_DRIVE_UNIX_FS
;
3692 SendMessageW(Globals
.hdrivebar
, TB_INSERTBUTTONW
, btn
++, (LPARAM
)&drivebarBtn
);
3693 drivebarBtn
.iString
++;
3695 #ifdef _SHELL_FOLDERS
3696 /* insert shell namespace button */
3697 load_string(b1
, sizeof(b1
)/sizeof(b1
[0]), IDS_SHELL
);
3698 b1
[lstrlenW(b1
)+1] = '\0';
3699 SendMessageW(Globals
.hdrivebar
, TB_ADDSTRINGW
, 0, (LPARAM
)b1
);
3701 drivebarBtn
.idCommand
= ID_DRIVE_SHELL_NS
;
3702 SendMessageW(Globals
.hdrivebar
, TB_INSERTBUTTONW
, btn
++, (LPARAM
)&drivebarBtn
);
3703 drivebarBtn
.iString
++;
3706 /* register windows drive root strings */
3707 SendMessageW(Globals
.hdrivebar
, TB_ADDSTRINGW
, 0, (LPARAM
)Globals
.drives
);
3710 drivebarBtn
.idCommand
= ID_DRIVE_FIRST
;
3712 for(p
=Globals
.drives
; *p
; ) {
3713 #ifdef _NO_EXTENSIONS
3714 /* insert drive letter */
3715 WCHAR b
[3] = {tolower(*p
)};
3716 SendMessageW(Globals
.hdrivebar
, TB_ADDSTRINGW
, 0, (LPARAM
)b
);
3718 switch(GetDriveTypeW(p
)) {
3719 case DRIVE_REMOVABLE
: drivebarBtn
.iBitmap
= 1; break;
3720 case DRIVE_CDROM
: drivebarBtn
.iBitmap
= 3; break;
3721 case DRIVE_REMOTE
: drivebarBtn
.iBitmap
= 4; break;
3722 case DRIVE_RAMDISK
: drivebarBtn
.iBitmap
= 5; break;
3723 default:/*DRIVE_FIXED*/ drivebarBtn
.iBitmap
= 2;
3726 SendMessageW(Globals
.hdrivebar
, TB_INSERTBUTTONW
, btn
++, (LPARAM
)&drivebarBtn
);
3727 drivebarBtn
.idCommand
++;
3728 drivebarBtn
.iString
++;
3734 static void refresh_drives(void)
3738 /* destroy drive bar */
3739 DestroyWindow(Globals
.hdrivebar
);
3740 Globals
.hdrivebar
= 0;
3742 /* re-create drive bar */
3745 /* update window layout */
3746 GetClientRect(Globals
.hMainWnd
, &rect
);
3747 SendMessageW(Globals
.hMainWnd
, WM_SIZE
, 0, MAKELONG(rect
.right
, rect
.bottom
));
3751 static BOOL
launch_file(HWND hwnd
, LPCWSTR cmd
, UINT nCmdShow
)
3753 HINSTANCE hinst
= ShellExecuteW(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3755 if (PtrToUlong(hinst
) <= 32) {
3756 display_error(hwnd
, GetLastError());
3764 static BOOL
launch_entry(Entry
* entry
, HWND hwnd
, UINT nCmdShow
)
3766 WCHAR cmd
[MAX_PATH
];
3768 #ifdef _SHELL_FOLDERS
3769 if (entry
->etype
== ET_SHELL
) {
3772 SHELLEXECUTEINFOW shexinfo
;
3774 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFOW
);
3775 shexinfo
.fMask
= SEE_MASK_IDLIST
;
3776 shexinfo
.hwnd
= hwnd
;
3777 shexinfo
.lpVerb
= NULL
;
3778 shexinfo
.lpFile
= NULL
;
3779 shexinfo
.lpParameters
= NULL
;
3780 shexinfo
.lpDirectory
= NULL
;
3781 shexinfo
.nShow
= nCmdShow
;
3782 shexinfo
.lpIDList
= get_to_absolute_pidl(entry
, hwnd
);
3784 if (!ShellExecuteExW(&shexinfo
)) {
3785 display_error(hwnd
, GetLastError());
3789 if (shexinfo
.lpIDList
!= entry
->pidl
)
3790 IMalloc_Free(Globals
.iMalloc
, shexinfo
.lpIDList
);
3796 get_path(entry
, cmd
);
3798 /* start program, open document... */
3799 return launch_file(hwnd
, cmd
, nCmdShow
);
3803 static void activate_entry(ChildWnd
* child
, Pane
* pane
, HWND hwnd
)
3805 Entry
* entry
= pane
->cur
;
3810 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
3811 int scanned_old
= entry
->scanned
;
3815 int idx
= SendMessageW(child
->left
.hwnd
, LB_GETCURSEL
, 0, 0);
3816 scan_entry(child
, entry
, idx
, hwnd
);
3819 #ifndef _NO_EXTENSIONS
3820 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='\0')
3824 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='.' && entry
->data
.cFileName
[2]=='\0') {
3825 entry
= child
->left
.cur
->up
;
3826 collapse_entry(&child
->left
, entry
);
3828 } else if (entry
->expanded
)
3829 collapse_entry(pane
, child
->left
.cur
);
3831 expand_entry(child
, child
->left
.cur
);
3833 if (!pane
->treePane
) focus_entry
: {
3834 int idxstart
= SendMessageW(child
->left
.hwnd
, LB_GETCURSEL
, 0, 0);
3835 int idx
= SendMessageW(child
->left
.hwnd
, LB_FINDSTRING
, idxstart
, (LPARAM
)entry
);
3836 SendMessageW(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
3837 set_curdir(child
, entry
, idx
, hwnd
);
3842 calc_widths(pane
, FALSE
);
3844 #ifndef _NO_EXTENSIONS
3849 if (GetKeyState(VK_MENU
) < 0)
3850 show_properties_dlg(entry
, child
->hwnd
);
3852 launch_entry(entry
, child
->hwnd
, SW_SHOWNORMAL
);
3857 static BOOL
pane_command(Pane
* pane
, UINT cmd
)
3861 if (pane
->visible_cols
) {
3862 pane
->visible_cols
= 0;
3863 calc_widths(pane
, TRUE
);
3864 #ifndef _NO_EXTENSIONS
3867 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3868 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
|MF_CHECKED
);
3869 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
);
3873 case ID_VIEW_ALL_ATTRIBUTES
:
3874 if (pane
->visible_cols
!= COL_ALL
) {
3875 pane
->visible_cols
= COL_ALL
;
3876 calc_widths(pane
, TRUE
);
3877 #ifndef _NO_EXTENSIONS
3880 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3881 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
);
3882 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
|MF_CHECKED
);
3886 #ifndef _NO_EXTENSIONS
3887 case ID_PREFERRED_SIZES
: {
3888 calc_widths(pane
, TRUE
);
3890 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3894 /* TODO: more command ids... */
3904 static void set_sort_order(ChildWnd
* child
, SORT_ORDER sortOrder
)
3906 if (child
->sortOrder
!= sortOrder
) {
3907 child
->sortOrder
= sortOrder
;
3908 refresh_child(child
);
3912 static void update_view_menu(ChildWnd
* child
)
3914 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_NAME
, child
->sortOrder
==SORT_NAME
? MF_CHECKED
: MF_UNCHECKED
);
3915 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_TYPE
, child
->sortOrder
==SORT_EXT
? MF_CHECKED
: MF_UNCHECKED
);
3916 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_SIZE
, child
->sortOrder
==SORT_SIZE
? MF_CHECKED
: MF_UNCHECKED
);
3917 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_DATE
, child
->sortOrder
==SORT_DATE
? MF_CHECKED
: MF_UNCHECKED
);
3921 static BOOL
is_directory(LPCWSTR target
)
3923 /*TODO correctly handle UNIX paths */
3924 DWORD target_attr
= GetFileAttributesW(target
);
3926 if (target_attr
== INVALID_FILE_ATTRIBUTES
)
3929 return target_attr
&FILE_ATTRIBUTE_DIRECTORY
? TRUE
: FALSE
;
3932 static BOOL
prompt_target(Pane
* pane
, LPWSTR source
, LPWSTR target
)
3934 WCHAR path
[MAX_PATH
];
3937 get_path(pane
->cur
, path
);
3939 if (DialogBoxParamW(Globals
.hInstance
, MAKEINTRESOURCEW(IDD_SELECT_DESTINATION
), pane
->hwnd
, DestinationDlgProc
, (LPARAM
)path
) != IDOK
)
3942 get_path(pane
->cur
, source
);
3944 /* convert relative targets to absolute paths */
3945 if (path
[0]!='/' && path
[1]!=':') {
3946 get_path(pane
->cur
->up
, target
);
3947 len
= lstrlenW(target
);
3949 if (target
[len
-1]!='\\' && target
[len
-1]!='/')
3950 target
[len
++] = '/';
3952 lstrcpyW(target
+len
, path
);
3954 lstrcpyW(target
, path
);
3956 /* If the target already exists as directory, create a new target below this. */
3957 if (is_directory(path
)) {
3958 WCHAR fname
[_MAX_FNAME
], ext
[_MAX_EXT
];
3959 static const WCHAR sAppend
[] = {'%','s','/','%','s','%','s','\0'};
3961 _wsplitpath(source
, NULL
, NULL
, fname
, ext
);
3963 wsprintfW(target
, sAppend
, path
, fname
, ext
);
3970 static IContextMenu2
* s_pctxmenu2
= NULL
;
3971 static IContextMenu3
* s_pctxmenu3
= NULL
;
3973 static void CtxMenu_reset(void)
3979 static IContextMenu
* CtxMenu_query_interfaces(IContextMenu
* pcm1
)
3981 IContextMenu
* pcm
= NULL
;
3985 if (IContextMenu_QueryInterface(pcm1
, &IID_IContextMenu3
, (void**)&pcm
) == NOERROR
)
3986 s_pctxmenu3
= (LPCONTEXTMENU3
)pcm
;
3987 else if (IContextMenu_QueryInterface(pcm1
, &IID_IContextMenu2
, (void**)&pcm
) == NOERROR
)
3988 s_pctxmenu2
= (LPCONTEXTMENU2
)pcm
;
3991 IContextMenu_Release(pcm1
);
3997 static BOOL
CtxMenu_HandleMenuMsg(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4000 if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3
, nmsg
, wparam
, lparam
)))
4005 if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2
, nmsg
, wparam
, lparam
)))
4012 #ifndef _NO_EXTENSIONS
4013 static HRESULT
ShellFolderContextMenu(IShellFolder
* shell_folder
, HWND hwndParent
, int cidl
, LPCITEMIDLIST
* apidl
, int x
, int y
)
4016 BOOL executed
= FALSE
;
4018 HRESULT hr
= IShellFolder_GetUIObjectOf(shell_folder
, hwndParent
, cidl
, apidl
, &IID_IContextMenu
, NULL
, (LPVOID
*)&pcm
);
4020 if (SUCCEEDED(hr
)) {
4021 HMENU hmenu
= CreatePopupMenu();
4023 pcm
= CtxMenu_query_interfaces(pcm
);
4026 hr
= IContextMenu_QueryContextMenu(pcm
, hmenu
, 0, FCIDM_SHVIEWFIRST
, FCIDM_SHVIEWLAST
, CMF_NORMAL
);
4028 if (SUCCEEDED(hr
)) {
4029 UINT idCmd
= TrackPopupMenu(hmenu
, TPM_LEFTALIGN
|TPM_RETURNCMD
|TPM_RIGHTBUTTON
, x
, y
, 0, hwndParent
, NULL
);
4034 CMINVOKECOMMANDINFO cmi
;
4036 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFO
);
4038 cmi
.hwnd
= hwndParent
;
4039 cmi
.lpVerb
= (LPCSTR
)(INT_PTR
)(idCmd
- FCIDM_SHVIEWFIRST
);
4040 cmi
.lpParameters
= NULL
;
4041 cmi
.lpDirectory
= NULL
;
4042 cmi
.nShow
= SW_SHOWNORMAL
;
4046 hr
= IContextMenu_InvokeCommand(pcm
, &cmi
);
4053 IContextMenu_Release(pcm
);
4056 return FAILED(hr
)? hr
: executed
? S_OK
: S_FALSE
;
4058 #endif /* _NO_EXTENSIONS */
4061 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4063 ChildWnd
* child
= (ChildWnd
*)GetWindowLongPtrW(hwnd
, GWLP_USERDATA
);
4068 LPDRAWITEMSTRUCT dis
= (LPDRAWITEMSTRUCT
)lparam
;
4069 Entry
* entry
= (Entry
*) dis
->itemData
;
4071 if (dis
->CtlID
== IDW_TREE_LEFT
)
4072 draw_item(&child
->left
, dis
, entry
, -1);
4073 else if (dis
->CtlID
== IDW_TREE_RIGHT
)
4074 draw_item(&child
->right
, dis
, entry
, -1);
4076 goto draw_menu_item
;
4081 InitChildWindow(child
);
4085 free_child_window(child
);
4086 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, 0);
4093 GetClientRect(hwnd
, &rt
);
4094 BeginPaint(hwnd
, &ps
);
4095 rt
.left
= child
->split_pos
-SPLIT_WIDTH
/2;
4096 rt
.right
= child
->split_pos
+SPLIT_WIDTH
/2+1;
4097 lastBrush
= SelectObject(ps
.hdc
, GetStockObject(COLOR_SPLITBAR
));
4098 Rectangle(ps
.hdc
, rt
.left
, rt
.top
-1, rt
.right
, rt
.bottom
+1);
4099 SelectObject(ps
.hdc
, lastBrush
);
4100 #ifdef _NO_EXTENSIONS
4101 rt
.top
= rt
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
4102 FillRect(ps
.hdc
, &rt
, GetStockObject(BLACK_BRUSH
));
4104 EndPaint(hwnd
, &ps
);
4108 if (LOWORD(lparam
) == HTCLIENT
) {
4111 ScreenToClient(hwnd
, &pt
);
4113 if (pt
.x
>=child
->split_pos
-SPLIT_WIDTH
/2 && pt
.x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
4114 SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_SIZEWE
));
4120 case WM_LBUTTONDOWN
: {
4122 int x
= (short)LOWORD(lparam
);
4124 GetClientRect(hwnd
, &rt
);
4126 if (x
>=child
->split_pos
-SPLIT_WIDTH
/2 && x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
4127 last_split
= child
->split_pos
;
4128 #ifdef _NO_EXTENSIONS
4129 draw_splitbar(hwnd
, last_split
);
4137 if (GetCapture() == hwnd
) {
4138 #ifdef _NO_EXTENSIONS
4140 int x
= (short)LOWORD(lparam
);
4141 draw_splitbar(hwnd
, last_split
);
4143 GetClientRect(hwnd
, &rt
);
4144 child
->split_pos
= x
;
4145 resize_tree(child
, rt
.right
, rt
.bottom
);
4151 #ifdef _NO_EXTENSIONS
4152 case WM_CAPTURECHANGED
:
4153 if (GetCapture()==hwnd
&& last_split
>=0)
4154 draw_splitbar(hwnd
, last_split
);
4159 if (wparam
== VK_ESCAPE
)
4160 if (GetCapture() == hwnd
) {
4162 #ifdef _NO_EXTENSIONS
4163 draw_splitbar(hwnd
, last_split
);
4165 child
->split_pos
= last_split
;
4167 GetClientRect(hwnd
, &rt
);
4168 resize_tree(child
, rt
.right
, rt
.bottom
);
4171 SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_ARROW
));
4176 if (GetCapture() == hwnd
) {
4178 int x
= (short)LOWORD(lparam
);
4180 #ifdef _NO_EXTENSIONS
4181 HDC hdc
= GetDC(hwnd
);
4182 GetClientRect(hwnd
, &rt
);
4184 rt
.left
= last_split
-SPLIT_WIDTH
/2;
4185 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
4186 InvertRect(hdc
, &rt
);
4189 rt
.left
= x
-SPLIT_WIDTH
/2;
4190 rt
.right
= x
+SPLIT_WIDTH
/2+1;
4191 InvertRect(hdc
, &rt
);
4193 ReleaseDC(hwnd
, hdc
);
4195 GetClientRect(hwnd
, &rt
);
4197 if (x
>=0 && x
<rt
.right
) {
4198 child
->split_pos
= x
;
4199 resize_tree(child
, rt
.right
, rt
.bottom
);
4200 rt
.left
= x
-SPLIT_WIDTH
/2;
4201 rt
.right
= x
+SPLIT_WIDTH
/2+1;
4202 InvalidateRect(hwnd
, &rt
, FALSE
);
4203 UpdateWindow(child
->left
.hwnd
);
4205 UpdateWindow(child
->right
.hwnd
);
4211 #ifndef _NO_EXTENSIONS
4212 case WM_GETMINMAXINFO
:
4213 DefMDIChildProcW(hwnd
, nmsg
, wparam
, lparam
);
4215 {LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
4217 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
4218 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
4220 #endif /* _NO_EXTENSIONS */
4223 if (SetCurrentDirectoryW(child
->path
))
4225 SetFocus(child
->focus_pane
? child
->right
.hwnd
: child
->left
.hwnd
);
4228 case WM_DISPATCH_COMMAND
: {
4229 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4231 switch(LOWORD(wparam
)) {
4232 case ID_WINDOW_NEW
: {
4233 ChildWnd
* new_child
= alloc_child_window(child
->path
, NULL
, hwnd
);
4235 if (!create_child_window(new_child
))
4236 HeapFree(GetProcessHeap(), 0, new_child
);
4242 refresh_child(child
);
4246 activate_entry(child
, pane
, hwnd
);
4249 case ID_FILE_MOVE
: {
4250 WCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
4252 if (prompt_target(pane
, source
, target
)) {
4253 SHFILEOPSTRUCTW shfo
= {hwnd
, FO_MOVE
, source
, target
};
4255 source
[lstrlenW(source
)+1] = '\0';
4256 target
[lstrlenW(target
)+1] = '\0';
4258 if (!SHFileOperationW(&shfo
))
4259 refresh_child(child
);
4263 case ID_FILE_COPY
: {
4264 WCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
4266 if (prompt_target(pane
, source
, target
)) {
4267 SHFILEOPSTRUCTW shfo
= {hwnd
, FO_COPY
, source
, target
};
4269 source
[lstrlenW(source
)+1] = '\0';
4270 target
[lstrlenW(target
)+1] = '\0';
4272 if (!SHFileOperationW(&shfo
))
4273 refresh_child(child
);
4277 case ID_FILE_DELETE
: {
4278 WCHAR path
[BUFFER_LEN
];
4279 SHFILEOPSTRUCTW shfo
= {hwnd
, FO_DELETE
, path
, NULL
, FOF_ALLOWUNDO
};
4281 get_path(pane
->cur
, path
);
4283 path
[lstrlenW(path
)+1] = '\0';
4285 if (!SHFileOperationW(&shfo
))
4286 refresh_child(child
);
4289 case ID_VIEW_SORT_NAME
:
4290 set_sort_order(child
, SORT_NAME
);
4293 case ID_VIEW_SORT_TYPE
:
4294 set_sort_order(child
, SORT_EXT
);
4297 case ID_VIEW_SORT_SIZE
:
4298 set_sort_order(child
, SORT_SIZE
);
4301 case ID_VIEW_SORT_DATE
:
4302 set_sort_order(child
, SORT_DATE
);
4305 case ID_VIEW_FILTER
: {
4306 struct FilterDialog dlg
;
4308 memset(&dlg
, 0, sizeof(struct FilterDialog
));
4309 lstrcpyW(dlg
.pattern
, child
->filter_pattern
);
4310 dlg
.flags
= child
->filter_flags
;
4312 if (DialogBoxParamW(Globals
.hInstance
, MAKEINTRESOURCEW(IDD_DIALOG_VIEW_TYPE
), hwnd
, FilterDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
4313 lstrcpyW(child
->filter_pattern
, dlg
.pattern
);
4314 child
->filter_flags
= dlg
.flags
;
4315 refresh_right_pane(child
);
4319 case ID_VIEW_SPLIT
: {
4320 last_split
= child
->split_pos
;
4321 #ifdef _NO_EXTENSIONS
4322 draw_splitbar(hwnd
, last_split
);
4327 case ID_EDIT_PROPERTIES
:
4328 show_properties_dlg(pane
->cur
, child
->hwnd
);
4332 return pane_command(pane
, LOWORD(wparam
));
4338 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4340 switch(HIWORD(wparam
)) {
4341 case LBN_SELCHANGE
: {
4342 int idx
= SendMessageW(pane
->hwnd
, LB_GETCURSEL
, 0, 0);
4343 Entry
* entry
= (Entry
*)SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, idx
, 0);
4345 if (pane
== &child
->left
)
4346 set_curdir(child
, entry
, idx
, hwnd
);
4352 activate_entry(child
, pane
, hwnd
);
4357 #ifndef _NO_EXTENSIONS
4359 NMHDR
* pnmh
= (NMHDR
*) lparam
;
4360 return pane_notify(pnmh
->idFrom
==IDW_HEADER_LEFT
? &child
->left
: &child
->right
, pnmh
);}
4363 #ifdef _SHELL_FOLDERS
4364 case WM_CONTEXTMENU
: {
4369 /* first select the current item in the listbox */
4370 HWND hpanel
= (HWND
) wparam
;
4371 pt_clnt
.x
= pt
.x
= (short)LOWORD(lparam
);
4372 pt_clnt
.y
= pt
.y
= (short)HIWORD(lparam
);
4373 ScreenToClient(hpanel
, &pt_clnt
);
4374 SendMessageW(hpanel
, WM_LBUTTONDOWN
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4375 SendMessageW(hpanel
, WM_LBUTTONUP
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4377 /* now create the popup menu using shell namespace and IContextMenu */
4378 pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4379 idx
= SendMessageW(pane
->hwnd
, LB_GETCURSEL
, 0, 0);
4382 Entry
* entry
= (Entry
*)SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, idx
, 0);
4384 LPITEMIDLIST pidl_abs
= get_to_absolute_pidl(entry
, hwnd
);
4387 IShellFolder
* parentFolder
;
4388 LPCITEMIDLIST pidlLast
;
4390 /* get and use the parent folder to display correct context menu in all cases */
4391 if (SUCCEEDED(SHBindToParent(pidl_abs
, &IID_IShellFolder
, (LPVOID
*)&parentFolder
, &pidlLast
))) {
4392 if (ShellFolderContextMenu(parentFolder
, hwnd
, 1, &pidlLast
, pt
.x
, pt
.y
) == S_OK
)
4393 refresh_child(child
);
4395 IShellFolder_Release(parentFolder
);
4398 IMalloc_Free(Globals
.iMalloc
, pidl_abs
);
4404 case WM_MEASUREITEM
:
4406 if (!wparam
) /* Is the message menu-related? */
4407 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4412 case WM_INITMENUPOPUP
:
4413 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4416 update_view_menu(child
);
4419 case WM_MENUCHAR
: /* only supported by IContextMenu3 */
4421 LRESULT lResult
= 0;
4423 IContextMenu3_HandleMenuMsg2(s_pctxmenu3
, nmsg
, wparam
, lparam
, &lResult
);
4431 if (wparam
!= SIZE_MINIMIZED
)
4432 resize_tree(child
, LOWORD(lparam
), HIWORD(lparam
));
4436 return DefMDIChildProcW(hwnd
, nmsg
, wparam
, lparam
);
4443 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4445 ChildWnd
* child
= (ChildWnd
*)GetWindowLongPtrW(GetParent(hwnd
), GWLP_USERDATA
);
4446 Pane
* pane
= (Pane
*)GetWindowLongPtrW(hwnd
, GWLP_USERDATA
);
4450 #ifndef _NO_EXTENSIONS
4457 child
->focus_pane
= pane
==&child
->right
? 1: 0;
4458 SendMessageW(hwnd
, LB_SETSEL
, TRUE
, 1);
4459 /*TODO: check menu items */
4463 if (wparam
== VK_TAB
) {
4464 /*TODO: SetFocus(Globals.hdrivebar) */
4465 SetFocus(child
->focus_pane
? child
->left
.hwnd
: child
->right
.hwnd
);
4469 return CallWindowProcW(g_orgTreeWndProc
, hwnd
, nmsg
, wparam
, lparam
);
4473 static void InitInstance(HINSTANCE hinstance
)
4475 static const WCHAR sFont
[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4477 WNDCLASSEXW wcFrame
;
4481 INITCOMMONCONTROLSEX icc
= {
4482 sizeof(INITCOMMONCONTROLSEX
),
4488 setlocale(LC_COLLATE
, ""); /* set collating rules to local settings for compareName */
4490 InitCommonControlsEx(&icc
);
4493 /* register frame window class */
4495 wcFrame
.cbSize
= sizeof(WNDCLASSEXW
);
4497 wcFrame
.lpfnWndProc
= FrameWndProc
;
4498 wcFrame
.cbClsExtra
= 0;
4499 wcFrame
.cbWndExtra
= 0;
4500 wcFrame
.hInstance
= hinstance
;
4501 wcFrame
.hIcon
= LoadIconW(hinstance
, MAKEINTRESOURCEW(IDI_WINEFILE
));
4502 wcFrame
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
4503 wcFrame
.hbrBackground
= 0;
4504 wcFrame
.lpszMenuName
= 0;
4505 wcFrame
.lpszClassName
= sWINEFILEFRAME
;
4506 wcFrame
.hIconSm
= LoadImageW(hinstance
, MAKEINTRESOURCEW(IDI_WINEFILE
), IMAGE_ICON
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
4508 Globals
.hframeClass
= RegisterClassExW(&wcFrame
);
4511 /* register tree windows class */
4513 wcChild
.style
= CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
;
4514 wcChild
.lpfnWndProc
= ChildWndProc
;
4515 wcChild
.cbClsExtra
= 0;
4516 wcChild
.cbWndExtra
= 0;
4517 wcChild
.hInstance
= hinstance
;
4519 wcChild
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
4520 wcChild
.hbrBackground
= 0;
4521 wcChild
.lpszMenuName
= 0;
4522 wcChild
.lpszClassName
= sWINEFILETREE
;
4524 RegisterClassW(&wcChild
);
4527 Globals
.haccel
= LoadAcceleratorsW(hinstance
, MAKEINTRESOURCEW(IDA_WINEFILE
));
4529 Globals
.hfont
= CreateFontW(-MulDiv(8,GetDeviceCaps(hdc
,LOGPIXELSY
),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont
);
4533 Globals
.hInstance
= hinstance
;
4535 #ifdef _SHELL_FOLDERS
4537 CoGetMalloc(MEMCTX_TASK
, &Globals
.iMalloc
);
4538 SHGetDesktopFolder(&Globals
.iDesktop
);
4539 Globals
.cfStrFName
= RegisterClipboardFormatW(CFSTR_FILENAMEW
);
4542 /* load column strings */
4545 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_NAME
);
4546 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_SIZE
);
4547 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_CDATE
);
4548 #ifndef _NO_EXTENSIONS
4549 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_ADATE
);
4550 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_MDATE
);
4551 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_IDX
);
4552 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_LINKS
);
4554 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_ATTR
);
4555 #ifndef _NO_EXTENSIONS
4556 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_SEC
);
4561 static BOOL
show_frame(HWND hwndParent
, int cmdshow
, LPCWSTR path
)
4563 static const WCHAR sMDICLIENT
[] = {'M','D','I','C','L','I','E','N','T','\0'};
4565 WCHAR buffer
[MAX_PATH
], b1
[BUFFER_LEN
];
4567 HMENU hMenuFrame
, hMenuWindow
;
4570 CLIENTCREATESTRUCT ccs
;
4572 if (Globals
.hMainWnd
)
4575 opts
= load_registry_settings();
4576 hMenuFrame
= LoadMenuW(Globals
.hInstance
, MAKEINTRESOURCEW(IDM_WINEFILE
));
4577 hMenuWindow
= GetSubMenu(hMenuFrame
, GetMenuItemCount(hMenuFrame
)-2);
4579 Globals
.hMenuFrame
= hMenuFrame
;
4580 Globals
.hMenuView
= GetSubMenu(hMenuFrame
, 2);
4581 Globals
.hMenuOptions
= GetSubMenu(hMenuFrame
, 3);
4583 ccs
.hWindowMenu
= hMenuWindow
;
4584 ccs
.idFirstChild
= IDW_FIRST_CHILD
;
4587 /* create main window */
4588 Globals
.hMainWnd
= CreateWindowExW(0, MAKEINTRESOURCEW(Globals
.hframeClass
), RS(b1
,IDS_WINEFILE
), WS_OVERLAPPEDWINDOW
,
4589 opts
.start_x
, opts
.start_y
, opts
.width
, opts
.height
,
4590 hwndParent
, Globals
.hMenuFrame
, Globals
.hInstance
, 0/*lpParam*/);
4593 Globals
.hmdiclient
= CreateWindowExW(0, sMDICLIENT
, NULL
,
4594 WS_CHILD
|WS_CLIPCHILDREN
|WS_VSCROLL
|WS_HSCROLL
|WS_VISIBLE
|WS_BORDER
,
4596 Globals
.hMainWnd
, 0, Globals
.hInstance
, &ccs
);
4598 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_DRIVE_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4599 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_SAVESETTINGS
, MF_BYCOMMAND
);
4604 TBBUTTON toolbarBtns
[] = {
4605 {0, 0, 0, BTNS_SEP
, {0, 0}, 0, 0},
4606 {0, ID_WINDOW_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4607 {1, ID_WINDOW_CASCADE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4608 {2, ID_WINDOW_TILE_HORZ
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4609 {3, ID_WINDOW_TILE_VERT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4612 Globals
.htoolbar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
,
4613 IDW_TOOLBAR
, 2, Globals
.hInstance
, IDB_TOOLBAR
, toolbarBtns
,
4614 sizeof(toolbarBtns
)/sizeof(TBBUTTON
), 16, 15, 16, 15, sizeof(TBBUTTON
));
4615 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_TOOL_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4618 Globals
.hstatusbar
= CreateStatusWindowW(WS_CHILD
|WS_VISIBLE
, 0, Globals
.hMainWnd
, IDW_STATUSBAR
);
4619 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
4621 /*TODO: read paths from registry */
4623 if (!path
|| !*path
) {
4624 GetCurrentDirectoryW(MAX_PATH
, buffer
);
4628 ShowWindow(Globals
.hMainWnd
, cmdshow
);
4630 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4631 /* Shell Namespace as default: */
4632 child
= alloc_child_window(path
, get_path_pidl(path
,Globals
.hMainWnd
), Globals
.hMainWnd
);
4634 child
= alloc_child_window(path
, NULL
, Globals
.hMainWnd
);
4637 child
->pos
.showCmd
= SW_SHOWMAXIMIZED
;
4638 child
->pos
.rcNormalPosition
.left
= 0;
4639 child
->pos
.rcNormalPosition
.top
= 0;
4640 child
->pos
.rcNormalPosition
.right
= 320;
4641 child
->pos
.rcNormalPosition
.bottom
= 280;
4643 if (!create_child_window(child
)) {
4644 HeapFree(GetProcessHeap(), 0, child
);
4648 SetWindowPlacement(child
->hwnd
, &child
->pos
);
4650 Globals
.himl
= ImageList_LoadImageW(Globals
.hInstance
, MAKEINTRESOURCEW(IDB_IMAGES
), 16, 0, RGB(0,255,0), IMAGE_BITMAP
, 0);
4652 Globals
.prescan_node
= FALSE
;
4654 UpdateWindow(Globals
.hMainWnd
);
4656 if (child
->hwnd
&& path
&& path
[0])
4659 WCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
4660 WCHAR fullname
[_MAX_FNAME
+_MAX_EXT
+1];
4662 memset(name
,0,sizeof(name
));
4663 memset(name
,0,sizeof(ext
));
4664 _wsplitpath(path
, drv
, dir
, name
, ext
);
4667 count
= SendMessageW(child
->right
.hwnd
, LB_GETCOUNT
, 0, 0);
4668 lstrcpyW(fullname
,name
);
4669 lstrcatW(fullname
,ext
);
4671 for (index
= 0; index
< count
; index
++)
4673 Entry
* entry
= (Entry
*)SendMessageW(child
->right
.hwnd
, LB_GETITEMDATA
, index
, 0);
4674 if (lstrcmpW(entry
->data
.cFileName
,fullname
)==0 ||
4675 lstrcmpW(entry
->data
.cAlternateFileName
,fullname
)==0)
4677 SendMessageW(child
->right
.hwnd
, LB_SETCURSEL
, index
, 0);
4678 SetFocus(child
->right
.hwnd
);
4687 static void ExitInstance(void)
4689 #ifdef _SHELL_FOLDERS
4690 IShellFolder_Release(Globals
.iDesktop
);
4691 IMalloc_Release(Globals
.iMalloc
);
4695 DeleteObject(Globals
.hfont
);
4696 ImageList_Destroy(Globals
.himl
);
4699 #ifdef _NO_EXTENSIONS
4701 /* search for already running win[e]files */
4703 static int g_foundPrevInstance
= 0;
4705 static BOOL CALLBACK
EnumWndProc(HWND hwnd
, LPARAM lparam
)
4709 GetClassNameW(hwnd
, cls
, 128);
4711 if (!lstrcmpW(cls
, (LPCWSTR
)lparam
)) {
4712 g_foundPrevInstance
++;
4719 /* search for window of given class name to allow only one running instance */
4720 static int find_window_class(LPCWSTR classname
)
4722 EnumWindows(EnumWndProc
, (LPARAM
)classname
);
4724 if (g_foundPrevInstance
)
4732 static int winefile_main(HINSTANCE hinstance
, int cmdshow
, LPCWSTR path
)
4736 InitInstance(hinstance
);
4738 if( !show_frame(0, cmdshow
, path
) )
4744 while(GetMessageW(&msg
, 0, 0, 0)) {
4745 if (Globals
.hmdiclient
&& TranslateMDISysAccel(Globals
.hmdiclient
, &msg
))
4748 if (Globals
.hMainWnd
&& TranslateAcceleratorW(Globals
.hMainWnd
, Globals
.haccel
, &msg
))
4751 TranslateMessage(&msg
);
4752 DispatchMessageW(&msg
);
4761 #if defined(_MSC_VER)
4762 int APIENTRY
wWinMain(HINSTANCE hinstance
, HINSTANCE previnstance
, LPWSTR cmdline
, int cmdshow
)
4764 int APIENTRY
WinMain(HINSTANCE hinstance
, HINSTANCE previnstance
, LPSTR cmdline
, int cmdshow
)
4767 #ifdef _NO_EXTENSIONS
4768 if (find_window_class(sWINEFILEFRAME
))
4772 { /* convert ANSI cmdline into WCS path string */
4773 WCHAR buffer
[MAX_PATH
];
4774 MultiByteToWideChar(CP_ACP
, 0, cmdline
, -1, buffer
, MAX_PATH
);
4775 winefile_main(hinstance
, cmdshow
, buffer
);