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>
43 #define _MAX_FNAME 256
44 #define _MAX_DIR _MAX_FNAME
45 #define _MAX_EXT _MAX_FNAME
49 #ifdef NONAMELESSUNION
50 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
52 #define UNION_MEMBER(x) x
57 #define DEFAULT_SPLIT_POS 300
59 #define DEFAULT_SPLIT_POS 200
62 static const WCHAR registry_key
[] = { 'S','o','f','t','w','a','r','e','\\',
64 'W','i','n','e','F','i','l','e','\0'};
65 static const WCHAR reg_start_x
[] = { 's','t','a','r','t','X','\0'};
66 static const WCHAR reg_start_y
[] = { 's','t','a','r','t','Y','\0'};
67 static const WCHAR reg_width
[] = { 'w','i','d','t','h','\0'};
68 static const WCHAR reg_height
[] = { 'h','e','i','g','h','t','\0'};
69 static const WCHAR reg_logfont
[] = { 'l','o','g','f','o','n','t','\0'};
79 typedef struct _Entry
{
90 #ifndef _NO_EXTENSIONS
91 BY_HANDLE_FILE_INFORMATION bhfi
;
93 enum ENTRY_TYPE etype
;
104 TCHAR path
[MAX_PATH
];
105 TCHAR volname
[_MAX_FNAME
];
115 COL_ATTRIBUTES
= 0x08,
117 #ifdef _NO_EXTENSIONS
118 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
122 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
|COL_INDEX
|COL_LINKS
135 #ifndef _NO_EXTENSIONS
139 #ifndef _NO_EXTENSIONS
145 int positions
[COLUMNS
+1];
157 int focus_pane
; /* 0: left 1: right */
160 BOOL header_wdths_ok
;
162 TCHAR path
[MAX_PATH
];
163 TCHAR filter_pattern
[MAX_PATH
];
167 SORT_ORDER sortOrder
;
172 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
);
173 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
);
174 static void refresh_child(ChildWnd
* child
);
175 static void refresh_drives(void);
176 static void get_path(Entry
* dir
, PTSTR path
);
177 static void format_date(const FILETIME
* ft
, TCHAR
* buffer
, int visible_cols
);
179 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
180 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
181 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
185 WINEFILE_GLOBALS Globals
;
187 static int last_split
;
189 /* some common string constants */
190 static const TCHAR sEmpty
[] = {'\0'};
191 static const WCHAR sSpace
[] = {' ', '\0'};
192 static const TCHAR sNumFmt
[] = {'%','d','\0'};
193 static const TCHAR sQMarks
[] = {'?','?','?','\0'};
195 /* window class names */
196 static const TCHAR sWINEFILEFRAME
[] = {'W','F','S','_','F','r','a','m','e','\0'};
197 static const TCHAR sWINEFILETREE
[] = {'W','F','S','_','T','r','e','e','\0'};
199 static const TCHAR sLongHexFmt
[] = {'%','I','6','4','X','\0'};
200 static const TCHAR sLongNumFmt
[] = {'%','I','6','4','u','\0'};
203 /* load resource string */
204 static LPTSTR
load_string(LPTSTR buffer
, UINT id
)
206 LoadString(Globals
.hInstance
, id
, buffer
, BUFFER_LEN
);
211 #define RS(b, i) load_string(b, i)
214 /* display error message for the specified WIN32 error code */
215 static void display_error(HWND hwnd
, DWORD error
)
217 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
220 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_FROM_SYSTEM
,
221 0, error
, MAKELANGID(LANG_NEUTRAL
,SUBLANG_DEFAULT
), (PTSTR
)&msg
, 0, NULL
))
222 MessageBox(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
224 MessageBox(hwnd
, RS(b1
,IDS_ERROR
), RS(b2
,IDS_WINEFILE
), MB_OK
);
230 /* display network error message using WNetGetLastError() */
231 static void display_network_error(HWND hwnd
)
233 TCHAR msg
[BUFFER_LEN
], provider
[BUFFER_LEN
], b2
[BUFFER_LEN
];
236 if (WNetGetLastError(&error
, msg
, BUFFER_LEN
, provider
, BUFFER_LEN
) == NO_ERROR
)
237 MessageBox(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
240 static inline BOOL
get_check(HWND hwnd
, INT id
)
242 return BST_CHECKED
&SendMessageW(GetDlgItem(hwnd
, id
), BM_GETSTATE
, 0, 0);
245 static inline INT
set_check(HWND hwnd
, INT id
, BOOL on
)
247 return SendMessageW(GetDlgItem(hwnd
, id
), BM_SETCHECK
, on
?BST_CHECKED
:BST_UNCHECKED
, 0);
250 static inline void choose_font(HWND hwnd
)
252 WCHAR dlg_name
[BUFFER_LEN
], dlg_info
[BUFFER_LEN
];
256 HDC hdc
= GetDC(hwnd
);
257 chFont
.lStructSize
= sizeof(CHOOSEFONT
);
258 chFont
.hwndOwner
= hwnd
;
260 chFont
.lpLogFont
= &lFont
;
261 chFont
.Flags
= CF_SCREENFONTS
| CF_FORCEFONTEXIST
| CF_LIMITSIZE
| CF_NOSCRIPTSEL
;
262 chFont
.rgbColors
= RGB(0,0,0);
263 chFont
.lCustData
= 0;
264 chFont
.lpfnHook
= NULL
;
265 chFont
.lpTemplateName
= NULL
;
266 chFont
.hInstance
= Globals
.hInstance
;
267 chFont
.lpszStyle
= NULL
;
268 chFont
.nFontType
= SIMULATED_FONTTYPE
;
270 chFont
.nSizeMax
= 24;
272 if (ChooseFontW(&chFont
)) {
276 DeleteObject(Globals
.hfont
);
277 Globals
.hfont
= CreateFontIndirectW(&lFont
);
278 hFontOld
= SelectObject(hdc
, Globals
.hfont
);
279 GetTextExtentPoint32W(hdc
, sSpace
, 1, &Globals
.spaceSize
);
281 /* change font in all open child windows */
282 for(childWnd
=GetWindow(Globals
.hmdiclient
,GW_CHILD
); childWnd
; childWnd
=GetNextWindow(childWnd
,GW_HWNDNEXT
)) {
283 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtrW(childWnd
, GWLP_USERDATA
);
284 SendMessageW(child
->left
.hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, TRUE
);
285 SendMessageW(child
->right
.hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, TRUE
);
286 SendMessageW(child
->left
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
287 SendMessageW(child
->right
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
288 InvalidateRect(child
->left
.hwnd
, NULL
, TRUE
);
289 InvalidateRect(child
->right
.hwnd
, NULL
, TRUE
);
292 SelectObject(hdc
, hFontOld
);
294 else if (CommDlgExtendedError()) {
295 LoadStringW(Globals
.hInstance
, IDS_FONT_SEL_DLG_NAME
, dlg_name
, BUFFER_LEN
);
296 LoadStringW(Globals
.hInstance
, IDS_FONT_SEL_ERROR
, dlg_info
, BUFFER_LEN
);
297 MessageBoxW(hwnd
, dlg_info
, dlg_name
, MB_OK
);
300 ReleaseDC(hwnd
, hdc
);
307 /* call vswprintf() in msvcrt.dll */
308 /*TODO: fix swprintf() in non-msvcrt mode, so that this dynamic linking function can be removed */
309 static int msvcrt_swprintf(WCHAR
* buffer
, const WCHAR
* fmt
, ...)
311 static int (__cdecl
*pvswprintf
)(WCHAR
*, const WCHAR
*, va_list) = NULL
;
316 HMODULE hModMsvcrt
= LoadLibraryA("msvcrt");
317 pvswprintf
= (int(__cdecl
*)(WCHAR
*,const WCHAR
*,va_list)) GetProcAddress(hModMsvcrt
, "vswprintf");
321 ret
= (*pvswprintf
)(buffer
, fmt
, ap
);
327 static LPCWSTR
my_wcsrchr(LPCWSTR str
, WCHAR c
)
342 #define _tcsrchr my_wcsrchr
344 #define _tcsrchr strrchr
347 #endif /* __WINE__ */
350 /* allocate and initialise a directory entry */
351 static Entry
* alloc_entry(void)
353 Entry
* entry
= HeapAlloc(GetProcessHeap(), 0, sizeof(Entry
));
355 #ifdef _SHELL_FOLDERS
357 entry
->folder
= NULL
;
364 /* free a directory entry */
365 static void free_entry(Entry
* entry
)
367 #ifdef _SHELL_FOLDERS
368 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
369 DestroyIcon(entry
->hicon
);
371 if (entry
->folder
&& entry
->folder
!=Globals
.iDesktop
)
372 IShellFolder_Release(entry
->folder
);
375 IMalloc_Free(Globals
.iMalloc
, entry
->pidl
);
378 HeapFree(GetProcessHeap(), 0, entry
);
381 /* recursively free all child entries */
382 static void free_entries(Entry
* dir
)
384 Entry
*entry
, *next
=dir
->down
;
400 static void read_directory_win(Entry
* dir
, LPCTSTR path
)
402 Entry
* first_entry
= NULL
;
406 int level
= dir
->level
+ 1;
407 WIN32_FIND_DATA w32fd
;
409 #ifndef _NO_EXTENSIONS
413 TCHAR buffer
[MAX_PATH
], *p
;
414 for(p
=buffer
; *path
; )
421 hFind
= FindFirstFile(buffer
, &w32fd
);
423 if (hFind
!= INVALID_HANDLE_VALUE
) {
425 #ifdef _NO_EXTENSIONS
426 /* hide directory entry "." */
427 if (w32fd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
428 LPCTSTR name
= w32fd
.cFileName
;
430 if (name
[0]=='.' && name
[1]=='\0')
434 entry
= alloc_entry();
442 memcpy(&entry
->data
, &w32fd
, sizeof(WIN32_FIND_DATA
));
445 entry
->expanded
= FALSE
;
446 entry
->scanned
= FALSE
;
447 entry
->level
= level
;
449 #ifndef _NO_EXTENSIONS
450 entry
->etype
= ET_WINDOWS
;
451 entry
->bhfi_valid
= FALSE
;
453 lstrcpy(p
, entry
->data
.cFileName
);
455 hFile
= CreateFile(buffer
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
456 0, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0);
458 if (hFile
!= INVALID_HANDLE_VALUE
) {
459 if (GetFileInformationByHandle(hFile
, &entry
->bhfi
))
460 entry
->bhfi_valid
= TRUE
;
467 } while(FindNextFile(hFind
, &w32fd
));
475 dir
->down
= first_entry
;
480 static Entry
* find_entry_win(Entry
* dir
, LPCTSTR name
)
484 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
486 LPCTSTR q
= entry
->data
.cFileName
;
489 if (!*p
|| *p
== '\\' || *p
== '/')
491 } while(tolower(*p
++) == tolower(*q
++));
494 q
= entry
->data
.cAlternateFileName
;
497 if (!*p
|| *p
== '\\' || *p
== '/')
499 } while(tolower(*p
++) == tolower(*q
++));
506 static Entry
* read_tree_win(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
508 TCHAR buffer
[MAX_PATH
];
509 Entry
* entry
= &root
->entry
;
513 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
515 #ifndef _NO_EXTENSIONS
516 entry
->etype
= ET_WINDOWS
;
520 while(*s
&& *s
!= '\\' && *s
!= '/')
523 while(*s
== '\\' || *s
== '/')
529 read_directory(entry
, buffer
, sortOrder
, hwnd
);
532 entry
->expanded
= TRUE
;
537 entry
= find_entry_win(entry
, s
);
540 SetCursor(old_cursor
);
546 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
548 static BOOL
time_to_filetime(const time_t* t
, FILETIME
* ftime
)
550 struct tm
* tm
= gmtime(t
);
556 stime
.wYear
= tm
->tm_year
+1900;
557 stime
.wMonth
= tm
->tm_mon
+1;
558 /* stime.wDayOfWeek */
559 stime
.wDay
= tm
->tm_mday
;
560 stime
.wHour
= tm
->tm_hour
;
561 stime
.wMinute
= tm
->tm_min
;
562 stime
.wSecond
= tm
->tm_sec
;
564 return SystemTimeToFileTime(&stime
, ftime
);
567 static void read_directory_unix(Entry
* dir
, LPCTSTR path
)
569 Entry
* first_entry
= NULL
;
574 int level
= dir
->level
+ 1;
576 char cpath
[MAX_PATH
];
578 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, cpath
, MAX_PATH
, NULL
, NULL
);
580 const char* cpath
= path
;
583 pdir
= opendir(cpath
);
588 char buffer
[MAX_PATH
], *p
;
591 for(p
=buffer
,s
=cpath
; *s
; )
594 if (p
==buffer
|| p
[-1]!='/')
597 while((ent
=readdir(pdir
))) {
598 entry
= alloc_entry();
606 entry
->etype
= ET_UNIX
;
608 strcpy(p
, ent
->d_name
);
610 MultiByteToWideChar(CP_UNIXCP
, 0, p
, -1, entry
->data
.cFileName
, MAX_PATH
);
612 lstrcpy(entry
->data
.cFileName
, p
);
615 if (!stat(buffer
, &st
)) {
616 entry
->data
.dwFileAttributes
= p
[0]=='.'? FILE_ATTRIBUTE_HIDDEN
: 0;
618 if (S_ISDIR(st
.st_mode
))
619 entry
->data
.dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
621 entry
->data
.nFileSizeLow
= st
.st_size
& 0xFFFFFFFF;
622 entry
->data
.nFileSizeHigh
= st
.st_size
>> 32;
624 memset(&entry
->data
.ftCreationTime
, 0, sizeof(FILETIME
));
625 time_to_filetime(&st
.st_atime
, &entry
->data
.ftLastAccessTime
);
626 time_to_filetime(&st
.st_mtime
, &entry
->data
.ftLastWriteTime
);
628 entry
->bhfi
.nFileIndexLow
= ent
->d_ino
;
629 entry
->bhfi
.nFileIndexHigh
= 0;
631 entry
->bhfi
.nNumberOfLinks
= st
.st_nlink
;
633 entry
->bhfi_valid
= TRUE
;
635 entry
->data
.nFileSizeLow
= 0;
636 entry
->data
.nFileSizeHigh
= 0;
637 entry
->bhfi_valid
= FALSE
;
642 entry
->expanded
= FALSE
;
643 entry
->scanned
= FALSE
;
644 entry
->level
= level
;
655 dir
->down
= first_entry
;
659 static Entry
* find_entry_unix(Entry
* dir
, LPCTSTR name
)
663 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
665 LPCTSTR q
= entry
->data
.cFileName
;
668 if (!*p
|| *p
== '/')
670 } while(*p
++ == *q
++);
676 static Entry
* read_tree_unix(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
678 TCHAR buffer
[MAX_PATH
];
679 Entry
* entry
= &root
->entry
;
683 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
685 entry
->etype
= ET_UNIX
;
688 while(*s
&& *s
!= '/')
697 read_directory(entry
, buffer
, sortOrder
, hwnd
);
700 entry
->expanded
= TRUE
;
705 entry
= find_entry_unix(entry
, s
);
708 SetCursor(old_cursor
);
713 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
716 #ifdef _SHELL_FOLDERS
719 #define get_strret get_strretW
720 #define path_from_pidl path_from_pidlW
722 #define get_strret get_strretA
723 #define path_from_pidl path_from_pidlA
727 static void free_strret(STRRET
* str
)
729 if (str
->uType
== STRRET_WSTR
)
730 IMalloc_Free(Globals
.iMalloc
, str
->UNION_MEMBER(pOleStr
));
736 static LPSTR
strcpyn(LPSTR dest
, LPCSTR source
, size_t count
)
741 for(s
=source
; count
&&(*d
++=*s
++); )
747 static void get_strretA(STRRET
* str
, const SHITEMID
* shiid
, LPSTR buffer
, int len
)
751 WideCharToMultiByte(CP_ACP
, 0, str
->UNION_MEMBER(pOleStr
), -1, buffer
, len
, NULL
, NULL
);
755 strcpyn(buffer
, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), len
);
759 strcpyn(buffer
, str
->UNION_MEMBER(cStr
), len
);
763 static HRESULT
path_from_pidlA(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPSTR buffer
, int len
)
767 /* SHGDN_FORPARSING: get full path of id list */
768 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, SHGDN_FORPARSING
, &str
);
771 get_strretA(&str
, &pidl
->mkid
, buffer
, len
);
781 static LPWSTR
wcscpyn(LPWSTR dest
, LPCWSTR source
, size_t count
)
786 for(s
=source
; count
&&(*d
++=*s
++); )
792 static void get_strretW(STRRET
* str
, const SHITEMID
* shiid
, LPWSTR buffer
, int len
)
796 wcscpyn(buffer
, str
->UNION_MEMBER(pOleStr
), len
);
800 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), -1, buffer
, len
);
804 MultiByteToWideChar(CP_ACP
, 0, str
->UNION_MEMBER(cStr
), -1, buffer
, len
);
809 static HRESULT
name_from_pidl(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPTSTR buffer
, int len
, SHGDNF flags
)
813 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, flags
, &str
);
816 get_strret(&str
, &pidl
->mkid
, buffer
, len
);
825 static HRESULT
path_from_pidlW(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPWSTR buffer
, int len
)
829 /* SHGDN_FORPARSING: get full path of id list */
830 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, SHGDN_FORPARSING
, &str
);
833 get_strretW(&str
, &pidl
->mkid
, buffer
, len
);
842 /* create an item id list from a file system path */
844 static LPITEMIDLIST
get_path_pidl(LPTSTR path
, HWND hwnd
)
851 LPWSTR buffer
= path
;
853 WCHAR buffer
[MAX_PATH
];
854 MultiByteToWideChar(CP_ACP
, 0, path
, -1, buffer
, MAX_PATH
);
857 hr
= IShellFolder_ParseDisplayName(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
865 /* convert an item id list from relative to absolute (=relative to the desktop) format */
867 static LPITEMIDLIST
get_to_absolute_pidl(Entry
* entry
, HWND hwnd
)
869 if (entry
->up
&& entry
->up
->etype
==ET_SHELL
) {
870 IShellFolder
* folder
= entry
->up
->folder
;
871 WCHAR buffer
[MAX_PATH
];
873 HRESULT hr
= path_from_pidlW(folder
, entry
->pidl
, buffer
, MAX_PATH
);
879 hr
= IShellFolder_ParseDisplayName(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
884 } else if (entry
->etype
== ET_WINDOWS
) {
885 TCHAR path
[MAX_PATH
];
887 get_path(entry
, path
);
889 return get_path_pidl(path
, hwnd
);
890 } else if (entry
->pidl
)
891 return ILClone(entry
->pidl
);
897 static HICON
extract_icon(IShellFolder
* folder
, LPCITEMIDLIST pidl
)
899 IExtractIcon
* pExtract
;
901 if (SUCCEEDED(IShellFolder_GetUIObjectOf(folder
, 0, 1, (LPCITEMIDLIST
*)&pidl
, &IID_IExtractIcon
, 0, (LPVOID
*)&pExtract
))) {
902 TCHAR path
[_MAX_PATH
];
907 if (SUCCEEDED(IExtractIconW_GetIconLocation(pExtract
, GIL_FORSHELL
, path
, _MAX_PATH
, &idx
, &flags
))) {
908 if (!(flags
& GIL_NOTFILENAME
)) {
910 idx
= 0; /* special case for some control panel applications */
912 if ((int)ExtractIconEx(path
, idx
, 0, &hicon
, 1) > 0)
913 flags
&= ~GIL_DONTCACHE
;
915 HICON hIconLarge
= 0;
917 HRESULT hr
= IExtractIconW_Extract(pExtract
, path
, idx
, &hIconLarge
, &hicon
, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON
)));
920 DestroyIcon(hIconLarge
);
931 static Entry
* find_entry_shell(Entry
* dir
, LPCITEMIDLIST pidl
)
935 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
936 if (entry
->pidl
->mkid
.cb
== pidl
->mkid
.cb
&&
937 !memcmp(entry
->pidl
, pidl
, entry
->pidl
->mkid
.cb
))
944 static Entry
* read_tree_shell(Root
* root
, LPITEMIDLIST pidl
, SORT_ORDER sortOrder
, HWND hwnd
)
946 Entry
* entry
= &root
->entry
;
948 LPITEMIDLIST next_pidl
= pidl
;
949 IShellFolder
* folder
;
950 IShellFolder
* child
= NULL
;
953 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
955 #ifndef _NO_EXTENSIONS
956 entry
->etype
= ET_SHELL
;
959 folder
= Globals
.iDesktop
;
962 entry
->pidl
= next_pidl
;
963 entry
->folder
= folder
;
968 /* copy first element of item idlist */
969 next_pidl
= IMalloc_Alloc(Globals
.iMalloc
, pidl
->mkid
.cb
+sizeof(USHORT
));
970 memcpy(next_pidl
, pidl
, pidl
->mkid
.cb
);
971 ((LPITEMIDLIST
)((LPBYTE
)next_pidl
+pidl
->mkid
.cb
))->mkid
.cb
= 0;
973 hr
= IShellFolder_BindToObject(folder
, next_pidl
, 0, &IID_IShellFolder
, (void**)&child
);
977 read_directory(entry
, NULL
, sortOrder
, hwnd
);
980 entry
->expanded
= TRUE
;
982 next
= find_entry_shell(entry
, next_pidl
);
989 /* go to next element */
990 pidl
= (LPITEMIDLIST
) ((LPBYTE
)pidl
+pidl
->mkid
.cb
);
993 SetCursor(old_cursor
);
999 static void fill_w32fdata_shell(IShellFolder
* folder
, LPCITEMIDLIST pidl
, SFGAOF attribs
, WIN32_FIND_DATA
* w32fdata
)
1001 if (!(attribs
& SFGAO_FILESYSTEM
) ||
1002 FAILED(SHGetDataFromIDList(folder
, pidl
, SHGDFIL_FINDDATA
, w32fdata
, sizeof(WIN32_FIND_DATA
)))) {
1003 WIN32_FILE_ATTRIBUTE_DATA fad
;
1004 IDataObject
* pDataObj
;
1006 STGMEDIUM medium
= {0, {0}, 0};
1007 FORMATETC fmt
= {Globals
.cfStrFName
, 0, DVASPECT_CONTENT
, -1, TYMED_HGLOBAL
};
1009 HRESULT hr
= IShellFolder_GetUIObjectOf(folder
, 0, 1, &pidl
, &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
1011 if (SUCCEEDED(hr
)) {
1012 hr
= IDataObject_GetData(pDataObj
, &fmt
, &medium
);
1014 IDataObject_Release(pDataObj
);
1016 if (SUCCEEDED(hr
)) {
1017 LPCTSTR path
= (LPCTSTR
)GlobalLock(medium
.UNION_MEMBER(hGlobal
));
1018 UINT sem_org
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1020 if (GetFileAttributesEx(path
, GetFileExInfoStandard
, &fad
)) {
1021 w32fdata
->dwFileAttributes
= fad
.dwFileAttributes
;
1022 w32fdata
->ftCreationTime
= fad
.ftCreationTime
;
1023 w32fdata
->ftLastAccessTime
= fad
.ftLastAccessTime
;
1024 w32fdata
->ftLastWriteTime
= fad
.ftLastWriteTime
;
1026 if (!(fad
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)) {
1027 w32fdata
->nFileSizeLow
= fad
.nFileSizeLow
;
1028 w32fdata
->nFileSizeHigh
= fad
.nFileSizeHigh
;
1032 SetErrorMode(sem_org
);
1034 GlobalUnlock(medium
.UNION_MEMBER(hGlobal
));
1035 GlobalFree(medium
.UNION_MEMBER(hGlobal
));
1040 if (attribs
& (SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
))
1041 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
1043 if (attribs
& SFGAO_READONLY
)
1044 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_READONLY
;
1046 if (attribs
& SFGAO_COMPRESSED
)
1047 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_COMPRESSED
;
1051 static void read_directory_shell(Entry
* dir
, HWND hwnd
)
1053 IShellFolder
* folder
= dir
->folder
;
1054 int level
= dir
->level
+ 1;
1057 IShellFolder
* child
;
1058 IEnumIDList
* idlist
;
1060 Entry
* first_entry
= NULL
;
1067 hr
= IShellFolder_EnumObjects(folder
, hwnd
, SHCONTF_FOLDERS
|SHCONTF_NONFOLDERS
|SHCONTF_INCLUDEHIDDEN
|SHCONTF_SHAREABLE
|SHCONTF_STORAGE
, &idlist
);
1069 if (SUCCEEDED(hr
)) {
1071 #define FETCH_ITEM_COUNT 32
1072 LPITEMIDLIST pidls
[FETCH_ITEM_COUNT
];
1077 memset(pidls
, 0, sizeof(pidls
));
1079 hr
= IEnumIDList_Next(idlist
, FETCH_ITEM_COUNT
, pidls
, &cnt
);
1086 for(n
=0; n
<cnt
; ++n
) {
1087 entry
= alloc_entry();
1090 first_entry
= entry
;
1095 memset(&entry
->data
, 0, sizeof(WIN32_FIND_DATA
));
1096 entry
->bhfi_valid
= FALSE
;
1098 attribs
= ~SFGAO_FILESYSTEM
; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
1100 hr
= IShellFolder_GetAttributesOf(folder
, 1, (LPCITEMIDLIST
*)&pidls
[n
], &attribs
);
1102 if (SUCCEEDED(hr
)) {
1103 if (attribs
!= (SFGAOF
)~SFGAO_FILESYSTEM
) {
1104 fill_w32fdata_shell(folder
, pidls
[n
], attribs
, &entry
->data
);
1106 entry
->bhfi_valid
= TRUE
;
1112 entry
->pidl
= pidls
[n
];
1114 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1115 hr
= IShellFolder_BindToObject(folder
, pidls
[n
], 0, &IID_IShellFolder
, (void**)&child
);
1118 entry
->folder
= child
;
1120 entry
->folder
= NULL
;
1123 entry
->folder
= NULL
;
1125 if (!entry
->data
.cFileName
[0])
1126 /*hr = */name_from_pidl(folder
, pidls
[n
], entry
->data
.cFileName
, MAX_PATH
, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1128 /* get display icons for files and virtual objects */
1129 if (!(entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ||
1130 !(attribs
& SFGAO_FILESYSTEM
)) {
1131 entry
->hicon
= extract_icon(folder
, pidls
[n
]);
1134 entry
->hicon
= (HICON
)-1; /* don't try again later */
1139 entry
->expanded
= FALSE
;
1140 entry
->scanned
= FALSE
;
1141 entry
->level
= level
;
1143 #ifndef _NO_EXTENSIONS
1144 entry
->etype
= ET_SHELL
;
1145 entry
->bhfi_valid
= FALSE
;
1152 IEnumIDList_Release(idlist
);
1158 dir
->down
= first_entry
;
1159 dir
->scanned
= TRUE
;
1162 #endif /* _SHELL_FOLDERS */
1165 /* sort order for different directory/file types */
1174 /* distinguish between ".", ".." and any other directory names */
1175 static int TypeOrderFromDirname(LPCTSTR name
)
1177 if (name
[0] == '.') {
1178 if (name
[1] == '\0')
1179 return TO_DOT
; /* "." */
1181 if (name
[1]=='.' && name
[2]=='\0')
1182 return TO_DOTDOT
; /* ".." */
1185 return TO_OTHER_DIR
; /* anything else */
1188 /* directories first... */
1189 static int compareType(const WIN32_FIND_DATA
* fd1
, const WIN32_FIND_DATA
* fd2
)
1191 int order1
= fd1
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1192 int order2
= fd2
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1194 /* Handle "." and ".." as special case and move them at the very first beginning. */
1195 if (order1
==TO_DIR
&& order2
==TO_DIR
) {
1196 order1
= TypeOrderFromDirname(fd1
->cFileName
);
1197 order2
= TypeOrderFromDirname(fd2
->cFileName
);
1200 return order2
==order1
? 0: order1
<order2
? -1: 1;
1204 static int compareName(const void* arg1
, const void* arg2
)
1206 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1207 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1209 int cmp
= compareType(fd1
, fd2
);
1213 return lstrcmpi(fd1
->cFileName
, fd2
->cFileName
);
1216 static int compareExt(const void* arg1
, const void* arg2
)
1218 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1219 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1220 const TCHAR
*name1
, *name2
, *ext1
, *ext2
;
1222 int cmp
= compareType(fd1
, fd2
);
1226 name1
= fd1
->cFileName
;
1227 name2
= fd2
->cFileName
;
1229 ext1
= _tcsrchr(name1
, '.');
1230 ext2
= _tcsrchr(name2
, '.');
1242 cmp
= lstrcmpi(ext1
, ext2
);
1246 return lstrcmpi(name1
, name2
);
1249 static int compareSize(const void* arg1
, const void* arg2
)
1251 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1252 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1254 int cmp
= compareType(fd1
, fd2
);
1258 cmp
= fd2
->nFileSizeHigh
- fd1
->nFileSizeHigh
;
1265 cmp
= fd2
->nFileSizeLow
- fd1
->nFileSizeLow
;
1267 return cmp
<0? -1: cmp
>0? 1: 0;
1270 static int compareDate(const void* arg1
, const void* arg2
)
1272 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1273 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1275 int cmp
= compareType(fd1
, fd2
);
1279 return CompareFileTime(&fd2
->ftLastWriteTime
, &fd1
->ftLastWriteTime
);
1283 static int (*sortFunctions
[])(const void* arg1
, const void* arg2
) = {
1284 compareName
, /* SORT_NAME */
1285 compareExt
, /* SORT_EXT */
1286 compareSize
, /* SORT_SIZE */
1287 compareDate
/* SORT_DATE */
1291 static void SortDirectory(Entry
* dir
, SORT_ORDER sortOrder
)
1293 Entry
* entry
= dir
->down
;
1298 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1302 array
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(Entry
*));
1305 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1308 /* call qsort with the appropriate compare function */
1309 qsort(array
, len
, sizeof(array
[0]), sortFunctions
[sortOrder
]);
1311 dir
->down
= array
[0];
1313 for(p
=array
; --len
; p
++)
1318 HeapFree(GetProcessHeap(), 0, array
);
1323 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
1325 TCHAR buffer
[MAX_PATH
];
1330 #ifdef _SHELL_FOLDERS
1331 if (dir
->etype
== ET_SHELL
)
1333 read_directory_shell(dir
, hwnd
);
1335 if (Globals
.prescan_node
) {
1344 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1345 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1346 read_directory_shell(entry
, hwnd
);
1347 SortDirectory(entry
, sortOrder
);
1353 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1354 if (dir
->etype
== ET_UNIX
)
1356 read_directory_unix(dir
, path
);
1358 if (Globals
.prescan_node
) {
1367 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1368 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1369 lstrcpy(d
, entry
->data
.cFileName
);
1370 read_directory_unix(entry
, buffer
);
1371 SortDirectory(entry
, sortOrder
);
1378 read_directory_win(dir
, path
);
1380 if (Globals
.prescan_node
) {
1389 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1390 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1391 lstrcpy(d
, entry
->data
.cFileName
);
1392 read_directory_win(entry
, buffer
);
1393 SortDirectory(entry
, sortOrder
);
1398 SortDirectory(dir
, sortOrder
);
1402 static Entry
* read_tree(Root
* root
, LPCTSTR path
, LPITEMIDLIST pidl
, LPTSTR drv
, SORT_ORDER sortOrder
, HWND hwnd
)
1404 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1405 static const TCHAR sSlash
[] = {'/', '\0'};
1407 static const TCHAR sBackslash
[] = {'\\', '\0'};
1409 #ifdef _SHELL_FOLDERS
1412 /* read shell namespace tree */
1413 root
->drive_type
= DRIVE_UNKNOWN
;
1416 load_string(root
->volname
, IDS_DESKTOP
);
1418 load_string(root
->fs
, IDS_SHELL
);
1420 return read_tree_shell(root
, pidl
, sortOrder
, hwnd
);
1424 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1427 /* read unix file system tree */
1428 root
->drive_type
= GetDriveType(path
);
1430 lstrcat(drv
, sSlash
);
1431 load_string(root
->volname
, IDS_ROOT_FS
);
1433 load_string(root
->fs
, IDS_UNIXFS
);
1435 lstrcpy(root
->path
, sSlash
);
1437 return read_tree_unix(root
, path
, sortOrder
, hwnd
);
1441 /* read WIN32 file system tree */
1442 root
->drive_type
= GetDriveType(path
);
1444 lstrcat(drv
, sBackslash
);
1445 GetVolumeInformation(drv
, root
->volname
, _MAX_FNAME
, 0, 0, &root
->fs_flags
, root
->fs
, _MAX_DIR
);
1447 lstrcpy(root
->path
, drv
);
1449 return read_tree_win(root
, path
, sortOrder
, hwnd
);
1453 /* flags to filter different file types */
1455 TF_DIRECTORIES
= 0x01,
1457 TF_DOCUMENTS
= 0x04,
1464 static ChildWnd
* alloc_child_window(LPCTSTR path
, LPITEMIDLIST pidl
, HWND hwnd
)
1466 TCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
1467 TCHAR dir_path
[MAX_PATH
];
1468 TCHAR b1
[BUFFER_LEN
];
1469 static const TCHAR sAsterics
[] = {'*', '\0'};
1471 ChildWnd
* child
= HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd
));
1472 Root
* root
= &child
->root
;
1475 memset(child
, 0, sizeof(ChildWnd
));
1477 child
->left
.treePane
= TRUE
;
1478 child
->left
.visible_cols
= 0;
1480 child
->right
.treePane
= FALSE
;
1481 #ifndef _NO_EXTENSIONS
1482 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_INDEX
|COL_LINKS
;
1484 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
;
1487 child
->pos
.length
= sizeof(WINDOWPLACEMENT
);
1488 child
->pos
.flags
= 0;
1489 child
->pos
.showCmd
= SW_SHOWNORMAL
;
1490 child
->pos
.rcNormalPosition
.left
= CW_USEDEFAULT
;
1491 child
->pos
.rcNormalPosition
.top
= CW_USEDEFAULT
;
1492 child
->pos
.rcNormalPosition
.right
= CW_USEDEFAULT
;
1493 child
->pos
.rcNormalPosition
.bottom
= CW_USEDEFAULT
;
1495 child
->focus_pane
= 0;
1496 child
->split_pos
= DEFAULT_SPLIT_POS
;
1497 child
->sortOrder
= SORT_NAME
;
1498 child
->header_wdths_ok
= FALSE
;
1502 lstrcpy(child
->path
, path
);
1504 _tsplitpath(path
, drv
, dir
, name
, ext
);
1507 lstrcpy(child
->filter_pattern
, sAsterics
);
1508 child
->filter_flags
= TF_ALL
;
1510 root
->entry
.level
= 0;
1512 lstrcpy(dir_path
, drv
);
1513 lstrcat(dir_path
, dir
);
1514 entry
= read_tree(root
, dir_path
, pidl
, drv
, child
->sortOrder
, hwnd
);
1516 #ifdef _SHELL_FOLDERS
1517 if (root
->entry
.etype
== ET_SHELL
)
1518 load_string(root
->entry
.data
.cFileName
, IDS_DESKTOP
);
1521 wsprintf(root
->entry
.data
.cFileName
, RS(b1
,IDS_TITLEFMT
), drv
, root
->fs
);
1523 root
->entry
.data
.dwFileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1525 child
->left
.root
= &root
->entry
;
1526 child
->right
.root
= NULL
;
1528 set_curdir(child
, entry
, 0, hwnd
);
1534 /* free all memory associated with a child window */
1535 static void free_child_window(ChildWnd
* child
)
1537 free_entries(&child
->root
.entry
);
1538 HeapFree(GetProcessHeap(), 0, child
);
1542 /* get full path of specified directory entry */
1543 static void get_path(Entry
* dir
, PTSTR path
)
1549 #ifdef _SHELL_FOLDERS
1550 if (dir
->etype
== ET_SHELL
)
1560 hr
= IShellFolder_GetAttributesOf(dir
->folder
, 1, (LPCITEMIDLIST
*)&dir
->pidl
, &attribs
);
1562 if (SUCCEEDED(hr
) && (attribs
&SFGAO_FILESYSTEM
)) {
1563 IShellFolder
* parent
= dir
->up
? dir
->up
->folder
: Globals
.iDesktop
;
1565 hr
= path_from_pidl(parent
, dir
->pidl
, path
, MAX_PATH
);
1571 for(entry
=dir
; entry
; level
++) {
1577 name
= entry
->data
.cFileName
;
1580 for(l
=0; *s
&& *s
!= '/' && *s
!= '\\'; s
++)
1586 memmove(path
+l
+1, path
, len
*sizeof(TCHAR
));
1587 memcpy(path
+1, name
, l
*sizeof(TCHAR
));
1590 #ifndef _NO_EXTENSIONS
1591 if (entry
->etype
== ET_UNIX
)
1600 memmove(path
+l
, path
, len
*sizeof(TCHAR
));
1601 memcpy(path
, name
, l
*sizeof(TCHAR
));
1608 #ifndef _NO_EXTENSIONS
1609 if (entry
->etype
== ET_UNIX
)
1620 static windowOptions
load_registry_settings(void)
1628 RegOpenKeyExW( HKEY_CURRENT_USER
, registry_key
,
1629 0, KEY_QUERY_VALUE
, &hKey
);
1631 size
= sizeof(DWORD
);
1633 if( RegQueryValueExW( hKey
, reg_start_x
, NULL
, &type
,
1634 (LPBYTE
) &opts
.start_x
, &size
) != ERROR_SUCCESS
)
1635 opts
.start_x
= CW_USEDEFAULT
;
1637 if( RegQueryValueExW( hKey
, reg_start_y
, NULL
, &type
,
1638 (LPBYTE
) &opts
.start_y
, &size
) != ERROR_SUCCESS
)
1639 opts
.start_y
= CW_USEDEFAULT
;
1641 if( RegQueryValueExW( hKey
, reg_width
, NULL
, &type
,
1642 (LPBYTE
) &opts
.width
, &size
) != ERROR_SUCCESS
)
1643 opts
.width
= CW_USEDEFAULT
;
1645 if( RegQueryValueExW( hKey
, reg_height
, NULL
, &type
,
1646 (LPBYTE
) &opts
.height
, &size
) != ERROR_SUCCESS
)
1647 opts
.height
= CW_USEDEFAULT
;
1648 size
=sizeof(logfont
);
1649 if( RegQueryValueExW( hKey
, reg_logfont
, NULL
, &type
,
1650 (LPBYTE
) &logfont
, &size
) != ERROR_SUCCESS
)
1651 GetObject(GetStockObject(DEFAULT_GUI_FONT
),sizeof(logfont
),&logfont
);
1653 RegCloseKey( hKey
);
1655 Globals
.hfont
= CreateFontIndirect(&logfont
);
1659 static void save_registry_settings(void)
1666 wi
.cbSize
= sizeof( WINDOWINFO
);
1667 GetWindowInfo(Globals
.hMainWnd
, &wi
);
1668 width
= wi
.rcWindow
.right
- wi
.rcWindow
.left
;
1669 height
= wi
.rcWindow
.bottom
- wi
.rcWindow
.top
;
1671 if ( RegOpenKeyExW( HKEY_CURRENT_USER
, registry_key
,
1672 0, KEY_SET_VALUE
, &hKey
) != ERROR_SUCCESS
)
1674 /* Unable to save registry settings - try to create key */
1675 if ( RegCreateKeyExW( HKEY_CURRENT_USER
, registry_key
,
1676 0, NULL
, REG_OPTION_NON_VOLATILE
,
1677 KEY_SET_VALUE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
1679 /* FIXME: Cannot create key */
1683 /* Save all of the settings */
1684 RegSetValueExW( hKey
, reg_start_x
, 0, REG_DWORD
,
1685 (LPBYTE
) &wi
.rcWindow
.left
, sizeof(DWORD
) );
1686 RegSetValueExW( hKey
, reg_start_y
, 0, REG_DWORD
,
1687 (LPBYTE
) &wi
.rcWindow
.top
, sizeof(DWORD
) );
1688 RegSetValueExW( hKey
, reg_width
, 0, REG_DWORD
,
1689 (LPBYTE
) &width
, sizeof(DWORD
) );
1690 RegSetValueExW( hKey
, reg_height
, 0, REG_DWORD
,
1691 (LPBYTE
) &height
, sizeof(DWORD
) );
1692 GetObject(Globals
.hfont
, sizeof(logfont
), &logfont
);
1693 RegSetValueExW( hKey
, reg_logfont
, 0, REG_BINARY
,
1694 (LPBYTE
) &logfont
, sizeof(LOGFONT
) );
1696 /* TODO: Save more settings here (List vs. Detailed View, etc.) */
1697 RegCloseKey( hKey
);
1700 static void resize_frame_rect(HWND hwnd
, PRECT prect
)
1705 if (IsWindowVisible(Globals
.htoolbar
)) {
1706 SendMessage(Globals
.htoolbar
, WM_SIZE
, 0, 0);
1707 GetClientRect(Globals
.htoolbar
, &rt
);
1708 prect
->top
= rt
.bottom
+3;
1709 prect
->bottom
-= rt
.bottom
+3;
1712 if (IsWindowVisible(Globals
.hdrivebar
)) {
1713 SendMessage(Globals
.hdrivebar
, WM_SIZE
, 0, 0);
1714 GetClientRect(Globals
.hdrivebar
, &rt
);
1715 new_top
= --prect
->top
+ rt
.bottom
+3;
1716 MoveWindow(Globals
.hdrivebar
, 0, prect
->top
, rt
.right
, new_top
, TRUE
);
1717 prect
->top
= new_top
;
1718 prect
->bottom
-= rt
.bottom
+2;
1721 if (IsWindowVisible(Globals
.hstatusbar
)) {
1722 int parts
[] = {300, 500};
1724 SendMessage(Globals
.hstatusbar
, WM_SIZE
, 0, 0);
1725 SendMessage(Globals
.hstatusbar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
1726 GetClientRect(Globals
.hstatusbar
, &rt
);
1727 prect
->bottom
-= rt
.bottom
;
1730 MoveWindow(Globals
.hmdiclient
, prect
->left
-1,prect
->top
-1,prect
->right
+2,prect
->bottom
+1, TRUE
);
1733 static void resize_frame(HWND hwnd
, int cx
, int cy
)
1742 resize_frame_rect(hwnd
, &rect
);
1745 static void resize_frame_client(HWND hwnd
)
1749 GetClientRect(hwnd
, &rect
);
1751 resize_frame_rect(hwnd
, &rect
);
1755 static HHOOK hcbthook
;
1756 static ChildWnd
* newchild
= NULL
;
1758 static LRESULT CALLBACK
CBTProc(int code
, WPARAM wparam
, LPARAM lparam
)
1760 if (code
==HCBT_CREATEWND
&& newchild
) {
1761 ChildWnd
* child
= newchild
;
1764 child
->hwnd
= (HWND
) wparam
;
1765 SetWindowLongPtr(child
->hwnd
, GWLP_USERDATA
, (LPARAM
)child
);
1768 return CallNextHookEx(hcbthook
, code
, wparam
, lparam
);
1771 static HWND
create_child_window(ChildWnd
* child
)
1773 MDICREATESTRUCT mcs
;
1776 mcs
.szClass
= sWINEFILETREE
;
1777 mcs
.szTitle
= (LPTSTR
)child
->path
;
1778 mcs
.hOwner
= Globals
.hInstance
;
1779 mcs
.x
= child
->pos
.rcNormalPosition
.left
;
1780 mcs
.y
= child
->pos
.rcNormalPosition
.top
;
1781 mcs
.cx
= child
->pos
.rcNormalPosition
.right
-child
->pos
.rcNormalPosition
.left
;
1782 mcs
.cy
= child
->pos
.rcNormalPosition
.bottom
-child
->pos
.rcNormalPosition
.top
;
1786 hcbthook
= SetWindowsHookEx(WH_CBT
, CBTProc
, 0, GetCurrentThreadId());
1789 child
->hwnd
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDICREATE
, 0, (LPARAM
)&mcs
);
1791 UnhookWindowsHookEx(hcbthook
);
1795 UnhookWindowsHookEx(hcbthook
);
1797 SendMessage(child
->left
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1798 SendMessage(child
->right
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1800 idx
= SendMessage(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)child
->left
.cur
);
1801 SendMessage(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
1807 struct ExecuteDialog
{
1808 TCHAR cmd
[MAX_PATH
];
1812 static INT_PTR CALLBACK
ExecuteDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1814 static struct ExecuteDialog
* dlg
;
1818 dlg
= (struct ExecuteDialog
*) lparam
;
1822 int id
= (int)wparam
;
1825 GetWindowText(GetDlgItem(hwnd
, 201), dlg
->cmd
, MAX_PATH
);
1826 dlg
->cmdshow
= get_check(hwnd
,214) ? SW_SHOWMINIMIZED
: SW_SHOWNORMAL
;
1827 EndDialog(hwnd
, id
);
1828 } else if (id
== IDCANCEL
)
1829 EndDialog(hwnd
, id
);
1838 static INT_PTR CALLBACK
DestinationDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1840 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1844 SetWindowLongPtr(hwnd
, GWLP_USERDATA
, lparam
);
1845 SetWindowText(GetDlgItem(hwnd
, 201), (LPCTSTR
)lparam
);
1849 int id
= (int)wparam
;
1853 LPTSTR dest
= (LPTSTR
) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
1854 GetWindowText(GetDlgItem(hwnd
, 201), dest
, MAX_PATH
);
1855 EndDialog(hwnd
, id
);
1859 EndDialog(hwnd
, id
);
1863 MessageBox(hwnd
, RS(b1
,IDS_NO_IMPL
), RS(b2
,IDS_WINEFILE
), MB_OK
);
1875 struct FilterDialog
{
1876 TCHAR pattern
[MAX_PATH
];
1880 static INT_PTR CALLBACK
FilterDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1882 static struct FilterDialog
* dlg
;
1886 dlg
= (struct FilterDialog
*) lparam
;
1887 SetWindowText(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
);
1888 set_check(hwnd
, IDC_VIEW_TYPE_DIRECTORIES
, dlg
->flags
&TF_DIRECTORIES
);
1889 set_check(hwnd
, IDC_VIEW_TYPE_PROGRAMS
, dlg
->flags
&TF_PROGRAMS
);
1890 set_check(hwnd
, IDC_VIEW_TYPE_DOCUMENTS
, dlg
->flags
&TF_DOCUMENTS
);
1891 set_check(hwnd
, IDC_VIEW_TYPE_OTHERS
, dlg
->flags
&TF_OTHERS
);
1892 set_check(hwnd
, IDC_VIEW_TYPE_HIDDEN
, dlg
->flags
&TF_HIDDEN
);
1896 int id
= (int)wparam
;
1901 GetWindowText(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
, MAX_PATH
);
1903 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_DIRECTORIES
) ? TF_DIRECTORIES
: 0;
1904 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_PROGRAMS
) ? TF_PROGRAMS
: 0;
1905 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_DOCUMENTS
) ? TF_DOCUMENTS
: 0;
1906 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_OTHERS
) ? TF_OTHERS
: 0;
1907 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_HIDDEN
) ? TF_HIDDEN
: 0;
1911 EndDialog(hwnd
, id
);
1912 } else if (id
== IDCANCEL
)
1913 EndDialog(hwnd
, id
);
1922 struct PropertiesDialog
{
1923 TCHAR path
[MAX_PATH
];
1928 /* Structure used to store enumerated languages and code pages. */
1929 struct LANGANDCODEPAGE
{
1934 static LPCSTR InfoStrings
[] = {
1950 static void PropDlg_DisplayValue(HWND hlbox
, HWND hedit
)
1952 int idx
= SendMessage(hlbox
, LB_GETCURSEL
, 0, 0);
1954 if (idx
!= LB_ERR
) {
1955 LPCTSTR pValue
= (LPCTSTR
) SendMessage(hlbox
, LB_GETITEMDATA
, idx
, 0);
1958 SetWindowText(hedit
, pValue
);
1962 static void CheckForFileInfo(struct PropertiesDialog
* dlg
, HWND hwnd
, LPCTSTR strFilename
)
1964 static TCHAR sBackSlash
[] = {'\\','\0'};
1965 static TCHAR sTranslation
[] = {'\\','V','a','r','F','i','l','e','I','n','f','o','\\','T','r','a','n','s','l','a','t','i','o','n','\0'};
1966 static TCHAR sStringFileInfo
[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1967 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1968 DWORD dwVersionDataLen
= GetFileVersionInfoSize(strFilename
, NULL
);
1970 if (dwVersionDataLen
) {
1971 dlg
->pVersionData
= HeapAlloc(GetProcessHeap(), 0, dwVersionDataLen
);
1973 if (GetFileVersionInfo(strFilename
, 0, dwVersionDataLen
, dlg
->pVersionData
)) {
1977 if (VerQueryValue(dlg
->pVersionData
, sBackSlash
, &pVal
, &nValLen
)) {
1978 if (nValLen
== sizeof(VS_FIXEDFILEINFO
)) {
1979 VS_FIXEDFILEINFO
* pFixedFileInfo
= (VS_FIXEDFILEINFO
*)pVal
;
1980 char buffer
[BUFFER_LEN
];
1982 sprintf(buffer
, "%d.%d.%d.%d",
1983 HIWORD(pFixedFileInfo
->dwFileVersionMS
), LOWORD(pFixedFileInfo
->dwFileVersionMS
),
1984 HIWORD(pFixedFileInfo
->dwFileVersionLS
), LOWORD(pFixedFileInfo
->dwFileVersionLS
));
1986 SetDlgItemTextA(hwnd
, IDC_STATIC_PROP_VERSION
, buffer
);
1990 /* Read the list of languages and code pages. */
1991 if (VerQueryValue(dlg
->pVersionData
, sTranslation
, &pVal
, &nValLen
)) {
1992 struct LANGANDCODEPAGE
* pTranslate
= (struct LANGANDCODEPAGE
*)pVal
;
1993 struct LANGANDCODEPAGE
* pEnd
= (struct LANGANDCODEPAGE
*)((LPBYTE
)pVal
+nValLen
);
1995 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
1997 /* Read the file description for each language and code page. */
1998 for(; pTranslate
<pEnd
; ++pTranslate
) {
2001 for(p
=InfoStrings
; *p
; ++p
) {
2002 TCHAR subblock
[200];
2009 LPCSTR pInfoString
= *p
;
2011 MultiByteToWideChar(CP_ACP
, 0, pInfoString
, -1, infoStr
, 100);
2013 #define infoStr pInfoString
2015 wsprintf(subblock
, sStringFileInfo
, pTranslate
->wLanguage
, pTranslate
->wCodePage
, infoStr
);
2017 /* Retrieve file description for language and code page */
2018 if (VerQueryValue(dlg
->pVersionData
, subblock
, (PVOID
)&pTxt
, &nValLen
)) {
2019 int idx
= SendMessage(hlbox
, LB_ADDSTRING
, 0L, (LPARAM
)infoStr
);
2020 SendMessage(hlbox
, LB_SETITEMDATA
, idx
, (LPARAM
) pTxt
);
2025 SendMessage(hlbox
, LB_SETCURSEL
, 0, 0);
2027 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
2033 static INT_PTR CALLBACK
PropertiesDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
2035 static struct PropertiesDialog
* dlg
;
2038 case WM_INITDIALOG
: {
2039 static const TCHAR sByteFmt
[] = {'%','s',' ','B','y','t','e','s','\0'};
2040 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2041 LPWIN32_FIND_DATA pWFD
;
2044 dlg
= (struct PropertiesDialog
*) lparam
;
2045 pWFD
= (LPWIN32_FIND_DATA
) &dlg
->entry
.data
;
2047 GetWindowText(hwnd
, b1
, MAX_PATH
);
2048 wsprintf(b2
, b1
, pWFD
->cFileName
);
2049 SetWindowText(hwnd
, b2
);
2051 format_date(&pWFD
->ftLastWriteTime
, b1
, COL_DATE
|COL_TIME
);
2052 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_LASTCHANGE
), b1
);
2054 size
= ((ULONGLONG
)pWFD
->nFileSizeHigh
<< 32) | pWFD
->nFileSizeLow
;
2055 _stprintf(b1
, sLongNumFmt
, size
);
2056 wsprintf(b2
, sByteFmt
, b1
);
2057 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_SIZE
), b2
);
2059 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_FILENAME
), pWFD
->cFileName
);
2060 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_PATH
), dlg
->path
);
2062 set_check(hwnd
, IDC_CHECK_READONLY
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_READONLY
);
2063 set_check(hwnd
, IDC_CHECK_ARCHIVE
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_ARCHIVE
);
2064 set_check(hwnd
, IDC_CHECK_COMPRESSED
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_COMPRESSED
);
2065 set_check(hwnd
, IDC_CHECK_HIDDEN
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_HIDDEN
);
2066 set_check(hwnd
, IDC_CHECK_SYSTEM
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_SYSTEM
);
2068 CheckForFileInfo(dlg
, hwnd
, dlg
->path
);
2072 int id
= (int)wparam
;
2074 switch(HIWORD(wparam
)) {
2075 case LBN_SELCHANGE
: {
2076 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
2077 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
2082 if (id
==IDOK
|| id
==IDCANCEL
)
2083 EndDialog(hwnd
, id
);
2089 HeapFree(GetProcessHeap(), 0, dlg
->pVersionData
);
2090 dlg
->pVersionData
= NULL
;
2097 static void show_properties_dlg(Entry
* entry
, HWND hwnd
)
2099 struct PropertiesDialog dlg
;
2101 memset(&dlg
, 0, sizeof(struct PropertiesDialog
));
2102 get_path(entry
, dlg
.path
);
2103 memcpy(&dlg
.entry
, entry
, sizeof(Entry
));
2105 DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_DIALOG_PROPERTIES
), hwnd
, PropertiesDialogDlgProc
, (LPARAM
)&dlg
);
2109 #ifndef _NO_EXTENSIONS
2111 static struct FullScreenParameters
{
2121 static void frame_get_clientspace(HWND hwnd
, PRECT prect
)
2125 if (!IsIconic(hwnd
))
2126 GetClientRect(hwnd
, prect
);
2130 GetWindowPlacement(hwnd
, &wp
);
2132 prect
->left
= prect
->top
= 0;
2133 prect
->right
= wp
.rcNormalPosition
.right
-wp
.rcNormalPosition
.left
-
2134 2*(GetSystemMetrics(SM_CXSIZEFRAME
)+GetSystemMetrics(SM_CXEDGE
));
2135 prect
->bottom
= wp
.rcNormalPosition
.bottom
-wp
.rcNormalPosition
.top
-
2136 2*(GetSystemMetrics(SM_CYSIZEFRAME
)+GetSystemMetrics(SM_CYEDGE
))-
2137 GetSystemMetrics(SM_CYCAPTION
)-GetSystemMetrics(SM_CYMENUSIZE
);
2140 if (IsWindowVisible(Globals
.htoolbar
)) {
2141 GetClientRect(Globals
.htoolbar
, &rt
);
2142 prect
->top
+= rt
.bottom
+2;
2145 if (IsWindowVisible(Globals
.hdrivebar
)) {
2146 GetClientRect(Globals
.hdrivebar
, &rt
);
2147 prect
->top
+= rt
.bottom
+2;
2150 if (IsWindowVisible(Globals
.hstatusbar
)) {
2151 GetClientRect(Globals
.hstatusbar
, &rt
);
2152 prect
->bottom
-= rt
.bottom
;
2156 static BOOL
toggle_fullscreen(HWND hwnd
)
2160 if ((g_fullscreen
.mode
=!g_fullscreen
.mode
)) {
2161 GetWindowRect(hwnd
, &g_fullscreen
.orgPos
);
2162 g_fullscreen
.wasZoomed
= IsZoomed(hwnd
);
2164 Frame_CalcFrameClient(hwnd
, &rt
);
2165 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
2166 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
2168 rt
.left
= g_fullscreen
.orgPos
.left
-rt
.left
;
2169 rt
.top
= g_fullscreen
.orgPos
.top
-rt
.top
;
2170 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+g_fullscreen
.orgPos
.right
-rt
.right
;
2171 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+g_fullscreen
.orgPos
.bottom
-rt
.bottom
;
2173 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
2175 MoveWindow(hwnd
, g_fullscreen
.orgPos
.left
, g_fullscreen
.orgPos
.top
,
2176 g_fullscreen
.orgPos
.right
-g_fullscreen
.orgPos
.left
,
2177 g_fullscreen
.orgPos
.bottom
-g_fullscreen
.orgPos
.top
, TRUE
);
2179 if (g_fullscreen
.wasZoomed
)
2180 ShowWindow(hwnd
, WS_MAXIMIZE
);
2183 return g_fullscreen
.mode
;
2186 static void fullscreen_move(HWND hwnd
)
2189 GetWindowRect(hwnd
, &pos
);
2191 Frame_CalcFrameClient(hwnd
, &rt
);
2192 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
2193 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
2195 rt
.left
= pos
.left
-rt
.left
;
2196 rt
.top
= pos
.top
-rt
.top
;
2197 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+pos
.right
-rt
.right
;
2198 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+pos
.bottom
-rt
.bottom
;
2200 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
2206 static void toggle_child(HWND hwnd
, UINT cmd
, HWND hchild
)
2208 BOOL vis
= IsWindowVisible(hchild
);
2210 CheckMenuItem(Globals
.hMenuOptions
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
2212 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
2214 #ifndef _NO_EXTENSIONS
2215 if (g_fullscreen
.mode
)
2216 fullscreen_move(hwnd
);
2219 resize_frame_client(hwnd
);
2222 static BOOL
activate_drive_window(LPCTSTR path
)
2224 TCHAR drv1
[_MAX_DRIVE
], drv2
[_MAX_DRIVE
];
2227 _tsplitpath(path
, drv1
, 0, 0, 0);
2229 /* search for a already open window for the same drive */
2230 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2231 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(child_wnd
, GWLP_USERDATA
);
2234 _tsplitpath(child
->root
.path
, drv2
, 0, 0, 0);
2236 if (!lstrcmpi(drv2
, drv1
)) {
2237 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2239 if (IsIconic(child_wnd
))
2240 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2250 static BOOL
activate_fs_window(LPCTSTR filesys
)
2254 /* search for a already open window of the given file system name */
2255 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2256 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(child_wnd
, GWLP_USERDATA
);
2259 if (!lstrcmpi(child
->root
.fs
, filesys
)) {
2260 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2262 if (IsIconic(child_wnd
))
2263 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2273 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
2275 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2279 if (Globals
.saveSettings
)
2280 save_registry_settings();
2282 DestroyWindow(hwnd
);
2284 /* clear handle variables */
2285 Globals
.hMenuFrame
= 0;
2286 Globals
.hMenuView
= 0;
2287 Globals
.hMenuOptions
= 0;
2288 Globals
.hMainWnd
= 0;
2289 Globals
.hmdiclient
= 0;
2290 Globals
.hdrivebar
= 0;
2297 case WM_INITMENUPOPUP
: {
2298 HWND hwndClient
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2300 if (!SendMessage(hwndClient
, WM_INITMENUPOPUP
, wparam
, lparam
))
2305 UINT cmd
= LOWORD(wparam
);
2306 HWND hwndClient
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2308 if (SendMessage(hwndClient
, WM_DISPATCH_COMMAND
, wparam
, lparam
))
2311 if (cmd
>=ID_DRIVE_FIRST
&& cmd
<=ID_DRIVE_FIRST
+0xFF) {
2312 TCHAR drv
[_MAX_DRIVE
], path
[MAX_PATH
];
2314 LPCTSTR root
= Globals
.drives
;
2317 for(i
=cmd
-ID_DRIVE_FIRST
; i
--; root
++)
2321 if (activate_drive_window(root
))
2324 _tsplitpath(root
, drv
, 0, 0, 0);
2326 if (!SetCurrentDirectory(drv
)) {
2327 display_error(hwnd
, GetLastError());
2331 GetCurrentDirectory(MAX_PATH
, path
); /*TODO: store last directory per drive */
2332 child
= alloc_child_window(path
, NULL
, hwnd
);
2334 if (!create_child_window(child
))
2335 HeapFree(GetProcessHeap(), 0, child
);
2336 } else switch(cmd
) {
2338 SendMessage(hwnd
, WM_CLOSE
, 0, 0);
2341 case ID_WINDOW_NEW
: {
2342 TCHAR path
[MAX_PATH
];
2345 GetCurrentDirectory(MAX_PATH
, path
);
2346 child
= alloc_child_window(path
, NULL
, hwnd
);
2348 if (!create_child_window(child
))
2349 HeapFree(GetProcessHeap(), 0, child
);
2356 case ID_WINDOW_CASCADE
:
2357 SendMessage(Globals
.hmdiclient
, WM_MDICASCADE
, 0, 0);
2360 case ID_WINDOW_TILE_HORZ
:
2361 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
2364 case ID_WINDOW_TILE_VERT
:
2365 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
2368 case ID_WINDOW_ARRANGE
:
2369 SendMessage(Globals
.hmdiclient
, WM_MDIICONARRANGE
, 0, 0);
2372 case ID_SELECT_FONT
:
2376 case ID_VIEW_TOOL_BAR
:
2377 toggle_child(hwnd
, cmd
, Globals
.htoolbar
);
2380 case ID_VIEW_DRIVE_BAR
:
2381 toggle_child(hwnd
, cmd
, Globals
.hdrivebar
);
2384 case ID_VIEW_STATUSBAR
:
2385 toggle_child(hwnd
, cmd
, Globals
.hstatusbar
);
2388 case ID_VIEW_SAVESETTINGS
:
2389 Globals
.saveSettings
= !Globals
.saveSettings
;
2390 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_SAVESETTINGS
,
2391 Globals
.saveSettings
? MF_CHECKED
: MF_UNCHECKED
);
2395 struct ExecuteDialog dlg
;
2397 memset(&dlg
, 0, sizeof(struct ExecuteDialog
));
2399 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_EXECUTE
), hwnd
, ExecuteDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
2400 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, dlg
.cmd
/*file*/, NULL
/*parameters*/, NULL
/*dir*/, dlg
.cmdshow
);
2402 if (PtrToUlong(hinst
) <= 32)
2403 display_error(hwnd
, GetLastError());
2407 case ID_CONNECT_NETWORK_DRIVE
: {
2408 DWORD ret
= WNetConnectionDialog(hwnd
, RESOURCETYPE_DISK
);
2409 if (ret
== NO_ERROR
)
2411 else if (ret
!= (DWORD
)-1) {
2412 if (ret
== ERROR_EXTENDED_ERROR
)
2413 display_network_error(hwnd
);
2415 display_error(hwnd
, ret
);
2419 case ID_DISCONNECT_NETWORK_DRIVE
: {
2420 DWORD ret
= WNetDisconnectDialog(hwnd
, RESOURCETYPE_DISK
);
2421 if (ret
== NO_ERROR
)
2423 else if (ret
!= (DWORD
)-1) {
2424 if (ret
== ERROR_EXTENDED_ERROR
)
2425 display_network_error(hwnd
);
2427 display_error(hwnd
, ret
);
2431 case ID_FORMAT_DISK
: {
2432 UINT sem_org
= SetErrorMode(0); /* Get the current Error Mode settings. */
2433 SetErrorMode(sem_org
& ~SEM_FAILCRITICALERRORS
); /* Force O/S to handle */
2434 SHFormatDrive(hwnd
, 0 /* A: */, SHFMT_ID_DEFAULT
, 0);
2435 SetErrorMode(sem_org
); /* Put it back the way it was. */
2439 WinHelp(hwnd
, RS(b1
,IDS_WINEFILE
), HELP_INDEX
, 0);
2442 #ifndef _NO_EXTENSIONS
2443 case ID_VIEW_FULLSCREEN
:
2444 CheckMenuItem(Globals
.hMenuOptions
, cmd
, toggle_fullscreen(hwnd
)?MF_CHECKED
:0);
2448 case ID_DRIVE_UNIX_FS
: {
2449 TCHAR path
[MAX_PATH
];
2451 char cpath
[MAX_PATH
];
2455 if (activate_fs_window(RS(b1
,IDS_UNIXFS
)))
2459 getcwd(cpath
, MAX_PATH
);
2460 MultiByteToWideChar(CP_UNIXCP
, 0, cpath
, -1, path
, MAX_PATH
);
2462 getcwd(path
, MAX_PATH
);
2464 child
= alloc_child_window(path
, NULL
, hwnd
);
2466 if (!create_child_window(child
))
2467 HeapFree(GetProcessHeap(), 0, child
);
2470 #ifdef _SHELL_FOLDERS
2471 case ID_DRIVE_SHELL_NS
: {
2472 TCHAR path
[MAX_PATH
];
2475 if (activate_fs_window(RS(b1
,IDS_SHELL
)))
2478 GetCurrentDirectory(MAX_PATH
, path
);
2479 child
= alloc_child_window(path
, get_path_pidl(path
,hwnd
), hwnd
);
2481 if (!create_child_window(child
))
2482 HeapFree(GetProcessHeap(), 0, child
);
2487 /*TODO: There are even more menu items! */
2490 ShellAbout(hwnd
, RS(b1
,IDS_WINEFILE
), NULL
,
2491 LoadImage( Globals
.hInstance
, MAKEINTRESOURCE(IDI_WINEFILE
),
2492 IMAGE_ICON
, 48, 48, LR_SHARED
));
2496 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2497 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2498 else */if ((cmd
<IDW_FIRST_CHILD
|| cmd
>=IDW_FIRST_CHILD
+0x100) &&
2499 (cmd
<SC_SIZE
|| cmd
>SC_RESTORE
))
2500 MessageBox(hwnd
, RS(b2
,IDS_NO_IMPL
), RS(b1
,IDS_WINEFILE
), MB_OK
);
2502 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2507 resize_frame(hwnd
, LOWORD(lparam
), HIWORD(lparam
));
2508 break; /* do not pass message to DefFrameProc */
2510 case WM_DEVICECHANGE
:
2511 SendMessage(hwnd
, WM_COMMAND
, MAKELONG(ID_REFRESH
,0), 0);
2514 #ifndef _NO_EXTENSIONS
2515 case WM_GETMINMAXINFO
: {
2516 LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
2518 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2519 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2522 case FRM_CALC_CLIENT
:
2523 frame_get_clientspace(hwnd
, (PRECT
)lparam
);
2525 #endif /* _NO_EXTENSIONS */
2528 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2535 static TCHAR g_pos_names
[COLUMNS
][20] = {
2539 static const int g_pos_align
[] = {
2541 HDF_LEFT
, /* Name */
2542 HDF_RIGHT
, /* Size */
2543 HDF_LEFT
, /* CDate */
2544 #ifndef _NO_EXTENSIONS
2545 HDF_LEFT
, /* ADate */
2546 HDF_LEFT
, /* MDate */
2547 HDF_LEFT
, /* Index */
2548 HDF_CENTER
, /* Links */
2550 HDF_CENTER
, /* Attributes */
2551 #ifndef _NO_EXTENSIONS
2552 HDF_LEFT
/* Security */
2556 static void resize_tree(ChildWnd
* child
, int cx
, int cy
)
2558 HDWP hdwp
= BeginDeferWindowPos(4);
2566 cx
= child
->split_pos
+ SPLIT_WIDTH
/2;
2568 #ifndef _NO_EXTENSIONS
2576 SendMessage(child
->left
.hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hdl
);
2578 DeferWindowPos(hdwp
, child
->left
.hwndHeader
, wp
.hwndInsertAfter
,
2579 wp
.x
-1, wp
.y
, child
->split_pos
-SPLIT_WIDTH
/2+1, wp
.cy
, wp
.flags
);
2580 DeferWindowPos(hdwp
, child
->right
.hwndHeader
, wp
.hwndInsertAfter
,
2581 rt
.left
+cx
+1, wp
.y
, wp
.cx
-cx
+2, wp
.cy
, wp
.flags
);
2583 #endif /* _NO_EXTENSIONS */
2585 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
);
2586 DeferWindowPos(hdwp
, child
->right
.hwnd
, 0, rt
.left
+cx
+1, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
2588 EndDeferWindowPos(hdwp
);
2592 #ifndef _NO_EXTENSIONS
2594 static HWND
create_header(HWND parent
, Pane
* pane
, UINT id
)
2599 HWND hwnd
= CreateWindow(WC_HEADER
, 0, WS_CHILD
|WS_VISIBLE
|HDS_HORZ
|HDS_FULLDRAG
/*TODO: |HDS_BUTTONS + sort orders*/,
2600 0, 0, 0, 0, parent
, (HMENU
)ULongToHandle(id
), Globals
.hInstance
, 0);
2604 SendMessage(hwnd
, WM_SETFONT
, (WPARAM
)GetStockObject(DEFAULT_GUI_FONT
), FALSE
);
2606 hdi
.mask
= HDI_TEXT
|HDI_WIDTH
|HDI_FORMAT
;
2608 for(idx
=0; idx
<COLUMNS
; idx
++) {
2609 hdi
.pszText
= g_pos_names
[idx
];
2610 hdi
.fmt
= HDF_STRING
| g_pos_align
[idx
];
2611 hdi
.cxy
= pane
->widths
[idx
];
2612 SendMessage(hwnd
, HDM_INSERTITEM
, idx
, (LPARAM
) &hdi
);
2618 #endif /* _NO_EXTENSIONS */
2621 static void init_output(HWND hwnd
)
2623 static const WCHAR s1000
[] = {'1','0','0','0','\0'};
2626 HDC hdc
= GetDC(hwnd
);
2628 if (GetNumberFormatW(LOCALE_USER_DEFAULT
, 0, s1000
, 0, b
, 16) > 4)
2629 Globals
.num_sep
= b
[1];
2631 Globals
.num_sep
= '.';
2633 old_font
= SelectObject(hdc
, Globals
.hfont
);
2634 GetTextExtentPoint32W(hdc
, sSpace
, 1, &Globals
.spaceSize
);
2635 SelectObject(hdc
, old_font
);
2636 ReleaseDC(hwnd
, hdc
);
2639 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
);
2642 /* calculate preferred width for all visible columns */
2644 static BOOL
calc_widths(Pane
* pane
, BOOL anyway
)
2646 int col
, x
, cx
, spc
=3*Globals
.spaceSize
.cx
;
2647 int entries
= SendMessage(pane
->hwnd
, LB_GETCOUNT
, 0, 0);
2648 int orgWidths
[COLUMNS
];
2649 int orgPositions
[COLUMNS
+1];
2655 memcpy(orgWidths
, pane
->widths
, sizeof(orgWidths
));
2656 memcpy(orgPositions
, pane
->positions
, sizeof(orgPositions
));
2659 for(col
=0; col
<COLUMNS
; col
++)
2660 pane
->widths
[col
] = 0;
2662 hdc
= GetDC(pane
->hwnd
);
2663 hfontOld
= SelectObject(hdc
, Globals
.hfont
);
2665 for(cnt
=0; cnt
<entries
; cnt
++) {
2666 Entry
* entry
= (Entry
*) SendMessage(pane
->hwnd
, LB_GETITEMDATA
, cnt
, 0);
2675 dis
.hwndItem
= pane
->hwnd
;
2677 dis
.rcItem
.left
= 0;
2679 dis
.rcItem
.right
= 0;
2680 dis
.rcItem
.bottom
= 0;
2681 /*dis.itemData = 0; */
2683 draw_item(pane
, &dis
, entry
, COLUMNS
);
2686 SelectObject(hdc
, hfontOld
);
2687 ReleaseDC(pane
->hwnd
, hdc
);
2690 for(col
=0; col
<COLUMNS
; col
++) {
2691 pane
->positions
[col
] = x
;
2692 cx
= pane
->widths
[col
];
2697 if (cx
< IMAGE_WIDTH
)
2700 pane
->widths
[col
] = cx
;
2706 pane
->positions
[COLUMNS
] = x
;
2708 SendMessage(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, x
, 0);
2711 if (!memcmp(orgWidths
, pane
->widths
, sizeof(orgWidths
)))
2714 /* don't move, if only collapsing an entry */
2715 if (!anyway
&& pane
->widths
[0]<orgWidths
[0] &&
2716 !memcmp(orgWidths
+1, pane
->widths
+1, sizeof(orgWidths
)-sizeof(int))) {
2717 pane
->widths
[0] = orgWidths
[0];
2718 memcpy(pane
->positions
, orgPositions
, sizeof(orgPositions
));
2723 InvalidateRect(pane
->hwnd
, 0, TRUE
);
2729 /* calculate one preferred column width */
2731 static void calc_single_width(Pane
* pane
, int col
)
2735 int entries
= SendMessage(pane
->hwnd
, LB_GETCOUNT
, 0, 0);
2739 pane
->widths
[col
] = 0;
2741 hdc
= GetDC(pane
->hwnd
);
2742 hfontOld
= SelectObject(hdc
, Globals
.hfont
);
2744 for(cnt
=0; cnt
<entries
; cnt
++) {
2745 Entry
* entry
= (Entry
*) SendMessage(pane
->hwnd
, LB_GETITEMDATA
, cnt
, 0);
2753 dis
.hwndItem
= pane
->hwnd
;
2755 dis
.rcItem
.left
= 0;
2757 dis
.rcItem
.right
= 0;
2758 dis
.rcItem
.bottom
= 0;
2759 /*dis.itemData = 0; */
2761 draw_item(pane
, &dis
, entry
, col
);
2764 SelectObject(hdc
, hfontOld
);
2765 ReleaseDC(pane
->hwnd
, hdc
);
2767 cx
= pane
->widths
[col
];
2770 cx
+= 3*Globals
.spaceSize
.cx
;
2772 if (cx
< IMAGE_WIDTH
)
2776 pane
->widths
[col
] = cx
;
2778 x
= pane
->positions
[col
] + cx
;
2780 for(; col
<COLUMNS
; ) {
2781 pane
->positions
[++col
] = x
;
2782 x
+= pane
->widths
[col
];
2785 SendMessage(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, x
, 0);
2789 static BOOL
pattern_match(LPCTSTR str
, LPCTSTR pattern
)
2791 for( ; *str
&&*pattern
; str
++,pattern
++) {
2792 if (*pattern
== '*') {
2794 while(*pattern
== '*');
2800 if (*str
==*pattern
&& pattern_match(str
, pattern
))
2805 else if (*str
!=*pattern
&& *pattern
!='?')
2809 if (*str
|| *pattern
)
2810 if (*pattern
!='*' || pattern
[1]!='\0')
2816 static BOOL
pattern_imatch(LPCTSTR str
, LPCTSTR pattern
)
2818 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2821 lstrcpy(b2
, pattern
);
2825 return pattern_match(b1
, b2
);
2835 static enum FILE_TYPE
get_file_type(LPCTSTR filename
);
2838 /* insert listbox entries after index idx */
2840 static int insert_entries(Pane
* pane
, Entry
* dir
, LPCTSTR pattern
, int filter_flags
, int idx
)
2847 ShowWindow(pane
->hwnd
, SW_HIDE
);
2849 for(; entry
; entry
=entry
->next
) {
2851 if (pane
->treePane
&& !(entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
2855 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
2856 /* don't display entries "." and ".." in the left pane */
2857 if (pane
->treePane
&& entry
->data
.cFileName
[0] == '.')
2859 #ifndef _NO_EXTENSIONS
2860 entry
->data
.cFileName
[1] == '\0' ||
2862 (entry
->data
.cFileName
[1] == '.' && entry
->data
.cFileName
[2] == '\0'))
2865 /* filter directories in right pane */
2866 if (!pane
->treePane
&& !(filter_flags
&TF_DIRECTORIES
))
2870 /* filter using the file name pattern */
2872 if (!pattern_imatch(entry
->data
.cFileName
, pattern
))
2875 /* filter system and hidden files */
2876 if (!(filter_flags
&TF_HIDDEN
) && (entry
->data
.dwFileAttributes
&(FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
)))
2879 /* filter looking at the file type */
2880 if ((filter_flags
&(TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
)) != (TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
))
2881 switch(get_file_type(entry
->data
.cFileName
)) {
2883 if (!(filter_flags
& TF_PROGRAMS
))
2888 if (!(filter_flags
& TF_DOCUMENTS
))
2892 default: /* TF_OTHERS */
2893 if (!(filter_flags
& TF_OTHERS
))
2900 SendMessage(pane
->hwnd
, LB_INSERTSTRING
, idx
, (LPARAM
) entry
);
2902 if (pane
->treePane
&& entry
->expanded
)
2903 idx
= insert_entries(pane
, entry
->down
, pattern
, filter_flags
, idx
);
2906 ShowWindow(pane
->hwnd
, SW_SHOW
);
2912 static void format_bytes(LPTSTR buffer
, LONGLONG bytes
)
2914 static const TCHAR sFmtGB
[] = {'%', '.', '1', 'f', ' ', 'G', 'B', '\0'};
2915 static const TCHAR sFmtMB
[] = {'%', '.', '1', 'f', ' ', 'M', 'B', '\0'};
2916 static const TCHAR sFmtkB
[] = {'%', '.', '1', 'f', ' ', 'k', 'B', '\0'};
2918 float fBytes
= (float)bytes
;
2920 if (bytes
>= 1073741824) /* 1 GB */
2921 _stprintf(buffer
, sFmtGB
, fBytes
/1073741824.f
+.5f
);
2922 else if (bytes
>= 1048576) /* 1 MB */
2923 _stprintf(buffer
, sFmtMB
, fBytes
/1048576.f
+.5f
);
2924 else if (bytes
>= 1024) /* 1 kB */
2925 _stprintf(buffer
, sFmtkB
, fBytes
/1024.f
+.5f
);
2927 _stprintf(buffer
, sLongNumFmt
, bytes
);
2930 static void set_space_status(void)
2932 ULARGE_INTEGER ulFreeBytesToCaller
, ulTotalBytes
, ulFreeBytes
;
2933 TCHAR fmt
[64], b1
[64], b2
[64], buffer
[BUFFER_LEN
];
2935 if (GetDiskFreeSpaceEx(NULL
, &ulFreeBytesToCaller
, &ulTotalBytes
, &ulFreeBytes
)) {
2936 format_bytes(b1
, ulFreeBytesToCaller
.QuadPart
);
2937 format_bytes(b2
, ulTotalBytes
.QuadPart
);
2938 wsprintf(buffer
, RS(fmt
,IDS_FREE_SPACE_FMT
), b1
, b2
);
2940 lstrcpy(buffer
, sQMarks
);
2942 SendMessage(Globals
.hstatusbar
, SB_SETTEXT
, 0, (LPARAM
)buffer
);
2946 static WNDPROC g_orgTreeWndProc
;
2948 static void create_tree_window(HWND parent
, Pane
* pane
, UINT id
, UINT id_header
, LPCTSTR pattern
, int filter_flags
)
2950 static const TCHAR sListBox
[] = {'L','i','s','t','B','o','x','\0'};
2952 static int s_init
= 0;
2953 Entry
* entry
= pane
->root
;
2955 pane
->hwnd
= CreateWindow(sListBox
, sEmpty
, WS_CHILD
|WS_VISIBLE
|WS_HSCROLL
|WS_VSCROLL
|
2956 LBS_DISABLENOSCROLL
|LBS_NOINTEGRALHEIGHT
|LBS_OWNERDRAWFIXED
|LBS_NOTIFY
,
2957 0, 0, 0, 0, parent
, (HMENU
)ULongToHandle(id
), Globals
.hInstance
, 0);
2959 SetWindowLongPtr(pane
->hwnd
, GWLP_USERDATA
, (LPARAM
)pane
);
2960 g_orgTreeWndProc
= (WNDPROC
) SetWindowLongPtr(pane
->hwnd
, GWLP_WNDPROC
, (LPARAM
)TreeWndProc
);
2962 SendMessage(pane
->hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, FALSE
);
2964 /* insert entries into listbox */
2966 insert_entries(pane
, entry
, pattern
, filter_flags
, -1);
2968 /* calculate column widths */
2971 init_output(pane
->hwnd
);
2974 calc_widths(pane
, TRUE
);
2976 #ifndef _NO_EXTENSIONS
2977 pane
->hwndHeader
= create_header(parent
, pane
, id_header
);
2982 static void InitChildWindow(ChildWnd
* child
)
2984 create_tree_window(child
->hwnd
, &child
->left
, IDW_TREE_LEFT
, IDW_HEADER_LEFT
, NULL
, TF_ALL
);
2985 create_tree_window(child
->hwnd
, &child
->right
, IDW_TREE_RIGHT
, IDW_HEADER_RIGHT
, child
->filter_pattern
, child
->filter_flags
);
2989 static void format_date(const FILETIME
* ft
, TCHAR
* buffer
, int visible_cols
)
2997 if (!ft
->dwLowDateTime
&& !ft
->dwHighDateTime
)
3000 if (!FileTimeToLocalFileTime(ft
, &lft
))
3001 {err
: lstrcpy(buffer
,sQMarks
); return;}
3003 if (!FileTimeToSystemTime(&lft
, &systime
))
3006 if (visible_cols
& COL_DATE
) {
3007 len
= GetDateFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
, BUFFER_LEN
);
3012 if (visible_cols
& COL_TIME
) {
3014 buffer
[len
-1] = ' ';
3016 buffer
[len
++] = ' ';
3018 if (!GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
+len
, BUFFER_LEN
-len
))
3024 static void calc_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3026 RECT rt
= {0, 0, 0, 0};
3028 DrawText(dis
->hDC
, str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
3030 if (rt
.right
> pane
->widths
[col
])
3031 pane
->widths
[col
] = rt
.right
;
3034 static void calc_tabbed_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3036 RECT rt
= {0, 0, 0, 0};
3038 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
3039 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
3041 DrawText(dis
->hDC
, str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
3042 /*FIXME rt (0,0) ??? */
3044 if (rt
.right
> pane
->widths
[col
])
3045 pane
->widths
[col
] = rt
.right
;
3049 static void output_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
, DWORD flags
)
3051 int x
= dis
->rcItem
.left
;
3054 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
3055 rt
.top
= dis
->rcItem
.top
;
3056 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
3057 rt
.bottom
= dis
->rcItem
.bottom
;
3059 DrawText(dis
->hDC
, str
, -1, &rt
, DT_SINGLELINE
|DT_NOPREFIX
|flags
);
3062 static void output_tabbed_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3064 int x
= dis
->rcItem
.left
;
3067 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
3068 rt
.top
= dis
->rcItem
.top
;
3069 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
3070 rt
.bottom
= dis
->rcItem
.bottom
;
3072 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
3073 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
3075 DrawText(dis
->hDC
, str
, -1, &rt
, DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
3078 static void output_number(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3080 int x
= dis
->rcItem
.left
;
3087 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
3088 rt
.top
= dis
->rcItem
.top
;
3089 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
3090 rt
.bottom
= dis
->rcItem
.bottom
;
3095 /* insert number separator characters */
3096 pos
= lstrlen(s
) % 3;
3102 *d
++ = Globals
.num_sep
;
3106 DrawText(dis
->hDC
, b
, d
-b
, &rt
, DT_RIGHT
|DT_SINGLELINE
|DT_NOPREFIX
|DT_END_ELLIPSIS
);
3110 static BOOL
is_exe_file(LPCTSTR ext
)
3112 static const TCHAR executable_extensions
[][4] = {
3117 #ifndef _NO_EXTENSIONS
3121 #endif /* _NO_EXTENSIONS */
3125 TCHAR ext_buffer
[_MAX_EXT
];
3126 const TCHAR (*p
)[4];
3130 for(s
=ext
+1,d
=ext_buffer
; (*d
=tolower(*s
)); s
++)
3133 for(p
=executable_extensions
; (*p
)[0]; p
++)
3134 if (!lstrcmpi(ext_buffer
, *p
))
3140 static BOOL
is_registered_type(LPCTSTR ext
)
3142 /* check if there exists a classname for this file extension in the registry */
3143 if (!RegQueryValue(HKEY_CLASSES_ROOT
, ext
, NULL
, NULL
))
3149 static enum FILE_TYPE
get_file_type(LPCTSTR filename
)
3151 LPCTSTR ext
= _tcsrchr(filename
, '.');
3155 if (is_exe_file(ext
))
3156 return FT_EXECUTABLE
;
3157 else if (is_registered_type(ext
))
3164 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
)
3166 TCHAR buffer
[BUFFER_LEN
];
3168 int visible_cols
= pane
->visible_cols
;
3169 COLORREF bkcolor
, textcolor
;
3170 RECT focusRect
= dis
->rcItem
;
3177 attrs
= entry
->data
.dwFileAttributes
;
3179 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) {
3180 if (entry
->data
.cFileName
[0] == '.' && entry
->data
.cFileName
[1] == '.'
3181 && entry
->data
.cFileName
[2] == '\0')
3182 img
= IMG_FOLDER_UP
;
3183 #ifndef _NO_EXTENSIONS
3184 else if (entry
->data
.cFileName
[0] == '.' && entry
->data
.cFileName
[1] == '\0')
3185 img
= IMG_FOLDER_CUR
;
3188 #ifdef _NO_EXTENSIONS
3191 (pane
->treePane
&& (dis
->itemState
&ODS_FOCUS
)))
3192 img
= IMG_OPEN_FOLDER
;
3196 switch(get_file_type(entry
->data
.cFileName
)) {
3197 case FT_EXECUTABLE
: img
= IMG_EXECUTABLE
; break;
3198 case FT_DOCUMENT
: img
= IMG_DOCUMENT
; break;
3199 default: img
= IMG_FILE
;
3207 if (pane
->treePane
) {
3209 img_pos
= dis
->rcItem
.left
+ entry
->level
*(IMAGE_WIDTH
+TREE_LINE_DX
);
3211 if (calcWidthCol
== -1) {
3213 int y
= dis
->rcItem
.top
+ IMAGE_HEIGHT
/2;
3216 HRGN hrgn_org
= CreateRectRgn(0, 0, 0, 0);
3219 rt_clip
.left
= dis
->rcItem
.left
;
3220 rt_clip
.top
= dis
->rcItem
.top
;
3221 rt_clip
.right
= dis
->rcItem
.left
+pane
->widths
[col
];
3222 rt_clip
.bottom
= dis
->rcItem
.bottom
;
3224 hrgn
= CreateRectRgnIndirect(&rt_clip
);
3226 if (!GetClipRgn(dis
->hDC
, hrgn_org
)) {
3227 DeleteObject(hrgn_org
);
3231 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
3232 ExtSelectClipRgn(dis
->hDC
, hrgn
, RGN_AND
);
3235 if ((up
=entry
->up
) != NULL
) {
3236 MoveToEx(dis
->hDC
, img_pos
-IMAGE_WIDTH
/2, y
, 0);
3237 LineTo(dis
->hDC
, img_pos
-2, y
);
3239 x
= img_pos
- IMAGE_WIDTH
/2;
3242 x
-= IMAGE_WIDTH
+TREE_LINE_DX
;
3246 && (up
->next
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
3249 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
3250 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
3252 } while((up
=up
->up
) != NULL
);
3255 x
= img_pos
- IMAGE_WIDTH
/2;
3257 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
3258 LineTo(dis
->hDC
, x
, y
);
3262 && (entry
->next
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
)
3265 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
3267 SelectClipRgn(dis
->hDC
, hrgn_org
);
3268 if (hrgn_org
) DeleteObject(hrgn_org
);
3269 /* SelectObject(dis->hDC, holdPen); */
3270 } else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
) {
3271 int right
= img_pos
+ IMAGE_WIDTH
- TREE_LINE_DX
;
3273 if (right
> pane
->widths
[col
])
3274 pane
->widths
[col
] = right
;
3277 img_pos
= dis
->rcItem
.left
;
3280 img_pos
= dis
->rcItem
.left
;
3282 if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3283 pane
->widths
[col
] = IMAGE_WIDTH
;
3286 if (calcWidthCol
== -1) {
3287 focusRect
.left
= img_pos
-2;
3289 #ifdef _NO_EXTENSIONS
3290 if (pane
->treePane
&& entry
) {
3293 DrawText(dis
->hDC
, entry
->data
.cFileName
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
3295 focusRect
.right
= dis
->rcItem
.left
+pane
->positions
[col
+1]+TREE_LINE_DX
+ rt
.right
+2;
3299 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
)
3300 textcolor
= COLOR_COMPRESSED
;
3302 #endif /* _NO_EXTENSIONS */
3303 textcolor
= RGB(0,0,0);
3305 if (dis
->itemState
& ODS_FOCUS
) {
3306 textcolor
= RGB(255,255,255);
3307 bkcolor
= COLOR_SELECTION
;
3309 bkcolor
= RGB(255,255,255);
3312 hbrush
= CreateSolidBrush(bkcolor
);
3313 FillRect(dis
->hDC
, &focusRect
, hbrush
);
3314 DeleteObject(hbrush
);
3316 SetBkMode(dis
->hDC
, TRANSPARENT
);
3317 SetTextColor(dis
->hDC
, textcolor
);
3319 cx
= pane
->widths
[col
];
3321 if (cx
&& img
!=IMG_NONE
) {
3322 if (cx
> IMAGE_WIDTH
)
3325 #ifdef _SHELL_FOLDERS
3326 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
3327 DrawIconEx(dis
->hDC
, img_pos
, dis
->rcItem
.top
, entry
->hicon
, cx
, GetSystemMetrics(SM_CYSMICON
), 0, 0, DI_NORMAL
);
3330 ImageList_DrawEx(Globals
.himl
, img
, dis
->hDC
,
3331 img_pos
, dis
->rcItem
.top
, cx
,
3332 IMAGE_HEIGHT
, bkcolor
, CLR_DEFAULT
, ILD_NORMAL
);
3339 #ifdef _NO_EXTENSIONS
3340 if (img
>= IMG_FOLDER_UP
)
3346 /* ouput file name */
3347 if (calcWidthCol
== -1)
3348 output_text(pane
, dis
, col
, entry
->data
.cFileName
, 0);
3349 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3350 calc_width(pane
, dis
, col
, entry
->data
.cFileName
);
3354 #ifdef _NO_EXTENSIONS
3355 if (!pane
->treePane
) {
3358 /* display file size */
3359 if (visible_cols
& COL_SIZE
) {
3360 #ifdef _NO_EXTENSIONS
3361 if (!(attrs
&FILE_ATTRIBUTE_DIRECTORY
))
3366 size
= ((ULONGLONG
)entry
->data
.nFileSizeHigh
<< 32) | entry
->data
.nFileSizeLow
;
3368 _stprintf(buffer
, sLongNumFmt
, size
);
3370 if (calcWidthCol
== -1)
3371 output_number(pane
, dis
, col
, buffer
);
3372 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3373 calc_width(pane
, dis
, col
, buffer
);/*TODO: not ever time enough */
3379 /* display file date */
3380 if (visible_cols
& (COL_DATE
|COL_TIME
)) {
3381 #ifndef _NO_EXTENSIONS
3382 format_date(&entry
->data
.ftCreationTime
, buffer
, visible_cols
);
3383 if (calcWidthCol
== -1)
3384 output_text(pane
, dis
, col
, buffer
, 0);
3385 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3386 calc_width(pane
, dis
, col
, buffer
);
3389 format_date(&entry
->data
.ftLastAccessTime
, buffer
, visible_cols
);
3390 if (calcWidthCol
== -1)
3391 output_text(pane
, dis
, col
, buffer
, 0);
3392 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3393 calc_width(pane
, dis
, col
, buffer
);
3395 #endif /* _NO_EXTENSIONS */
3397 format_date(&entry
->data
.ftLastWriteTime
, buffer
, visible_cols
);
3398 if (calcWidthCol
== -1)
3399 output_text(pane
, dis
, col
, buffer
, 0);
3400 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3401 calc_width(pane
, dis
, col
, buffer
);
3405 #ifndef _NO_EXTENSIONS
3406 if (entry
->bhfi_valid
) {
3407 ULONGLONG index
= ((ULONGLONG
)entry
->bhfi
.nFileIndexHigh
<< 32) | entry
->bhfi
.nFileIndexLow
;
3409 if (visible_cols
& COL_INDEX
) {
3410 _stprintf(buffer
, sLongHexFmt
, index
);
3412 if (calcWidthCol
== -1)
3413 output_text(pane
, dis
, col
, buffer
, DT_RIGHT
);
3414 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3415 calc_width(pane
, dis
, col
, buffer
);
3420 if (visible_cols
& COL_LINKS
) {
3421 wsprintf(buffer
, sNumFmt
, entry
->bhfi
.nNumberOfLinks
);
3423 if (calcWidthCol
== -1)
3424 output_text(pane
, dis
, col
, buffer
, DT_CENTER
);
3425 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3426 calc_width(pane
, dis
, col
, buffer
);
3432 #endif /* _NO_EXTENSIONS */
3434 /* show file attributes */
3435 if (visible_cols
& COL_ATTRIBUTES
) {
3436 #ifdef _NO_EXTENSIONS
3437 static const TCHAR s4Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3438 lstrcpy(buffer
, s4Tabs
);
3440 static const TCHAR s11Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3441 lstrcpy(buffer
, s11Tabs
);
3444 if (attrs
& FILE_ATTRIBUTE_NORMAL
) buffer
[ 0] = 'N';
3446 if (attrs
& FILE_ATTRIBUTE_READONLY
) buffer
[ 2] = 'R';
3447 if (attrs
& FILE_ATTRIBUTE_HIDDEN
) buffer
[ 4] = 'H';
3448 if (attrs
& FILE_ATTRIBUTE_SYSTEM
) buffer
[ 6] = 'S';
3449 if (attrs
& FILE_ATTRIBUTE_ARCHIVE
) buffer
[ 8] = 'A';
3450 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
) buffer
[10] = 'C';
3451 #ifndef _NO_EXTENSIONS
3452 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) buffer
[12] = 'D';
3453 if (attrs
& FILE_ATTRIBUTE_ENCRYPTED
) buffer
[14] = 'E';
3454 if (attrs
& FILE_ATTRIBUTE_TEMPORARY
) buffer
[16] = 'T';
3455 if (attrs
& FILE_ATTRIBUTE_SPARSE_FILE
) buffer
[18] = 'P';
3456 if (attrs
& FILE_ATTRIBUTE_REPARSE_POINT
) buffer
[20] = 'Q';
3457 if (attrs
& FILE_ATTRIBUTE_OFFLINE
) buffer
[22] = 'O';
3458 if (attrs
& FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
) buffer
[24] = 'X';
3459 #endif /* _NO_EXTENSIONS */
3462 if (calcWidthCol
== -1)
3463 output_tabbed_text(pane
, dis
, col
, buffer
);
3464 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3465 calc_tabbed_width(pane
, dis
, col
, buffer
);
3471 if (flags.security) {
3472 static const TCHAR sSecTabs[] = {
3473 ' ','\t',' ','\t',' ','\t',' ',
3475 ' ','\t',' ','\t',' ','\t',' ',
3477 ' ','\t',' ','\t',' ','\t',' ',
3481 DWORD rights = get_access_mask();
3483 lstrcpy(buffer, sSecTabs);
3485 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
3486 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
3487 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
3488 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
3489 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
3490 if (rights & FILE_EXECUTE) buffer[12] = 'X';
3491 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
3492 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
3493 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
3494 if (rights & WRITE_DAC) buffer[22] = 'C';
3495 if (rights & WRITE_OWNER) buffer[24] = 'O';
3496 if (rights & SYNCHRONIZE) buffer[26] = 'S';
3498 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
3501 if (flags.description) {
3502 get_description(buffer);
3503 output_text(dis, col++, buffer, 0, psize);
3507 #ifdef _NO_EXTENSIONS
3510 /* draw focus frame */
3511 if ((dis
->itemState
&ODS_FOCUS
) && calcWidthCol
==-1) {
3512 /* Currently [04/2000] Wine neither behaves exactly the same */
3513 /* way as WIN 95 nor like Windows NT... */
3518 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
3519 LOGBRUSH lb
= {PS_SOLID
, RGB(255,255,255)};
3520 hpen
= ExtCreatePen(PS_COSMETIC
|PS_ALTERNATE
, 1, &lb
, 0, 0);
3522 hpen
= CreatePen(PS_DOT
, 0, RGB(255,255,255));
3524 lastPen
= SelectPen(dis
->hDC
, hpen
);
3525 lastBrush
= SelectObject(dis
->hDC
, GetStockObject(HOLLOW_BRUSH
));
3526 SetROP2(dis
->hDC
, R2_XORPEN
);
3527 Rectangle(dis
->hDC
, focusRect
.left
, focusRect
.top
, focusRect
.right
, focusRect
.bottom
);
3528 SelectObject(dis
->hDC
, lastBrush
);
3529 SelectObject(dis
->hDC
, lastPen
);
3532 #endif /* _NO_EXTENSIONS */
3536 #ifdef _NO_EXTENSIONS
3538 static void draw_splitbar(HWND hwnd
, int x
)
3541 HDC hdc
= GetDC(hwnd
);
3543 GetClientRect(hwnd
, &rt
);
3545 rt
.left
= x
- SPLIT_WIDTH
/2;
3546 rt
.right
= x
+ SPLIT_WIDTH
/2+1;
3548 InvertRect(hdc
, &rt
);
3550 ReleaseDC(hwnd
, hdc
);
3553 #endif /* _NO_EXTENSIONS */
3556 #ifndef _NO_EXTENSIONS
3558 static void set_header(Pane
* pane
)
3561 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3564 item
.mask
= HDI_WIDTH
;
3567 for(; x
+pane
->widths
[i
]<scroll_pos
&& i
<COLUMNS
; i
++) {
3568 x
+= pane
->widths
[i
];
3569 SendMessage(pane
->hwndHeader
, HDM_SETITEM
, i
, (LPARAM
) &item
);
3573 x
+= pane
->widths
[i
];
3574 item
.cxy
= x
- scroll_pos
;
3575 SendMessage(pane
->hwndHeader
, HDM_SETITEM
, i
++, (LPARAM
) &item
);
3577 for(; i
<COLUMNS
; i
++) {
3578 item
.cxy
= pane
->widths
[i
];
3579 x
+= pane
->widths
[i
];
3580 SendMessage(pane
->hwndHeader
, HDM_SETITEM
, i
, (LPARAM
) &item
);
3585 static LRESULT
pane_notify(Pane
* pane
, NMHDR
* pnmh
)
3587 switch(pnmh
->code
) {
3588 case HDN_ITEMCHANGED
: {
3589 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3590 int idx
= phdn
->iItem
;
3591 int dx
= phdn
->pitem
->cxy
- pane
->widths
[idx
];
3595 GetClientRect(pane
->hwnd
, &clnt
);
3597 pane
->widths
[idx
] += dx
;
3599 for(i
=idx
; ++i
<=COLUMNS
; )
3600 pane
->positions
[i
] += dx
;
3603 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3607 rt_scr
.left
= pane
->positions
[idx
+1]-scroll_pos
;
3609 rt_scr
.right
= clnt
.right
;
3610 rt_scr
.bottom
= clnt
.bottom
;
3612 rt_clip
.left
= pane
->positions
[idx
]-scroll_pos
;
3614 rt_clip
.right
= clnt
.right
;
3615 rt_clip
.bottom
= clnt
.bottom
;
3617 if (rt_scr
.left
< 0) rt_scr
.left
= 0;
3618 if (rt_clip
.left
< 0) rt_clip
.left
= 0;
3620 ScrollWindowEx(pane
->hwnd
, dx
, 0, &rt_scr
, &rt_clip
, 0, 0, SW_INVALIDATE
);
3622 rt_clip
.right
= pane
->positions
[idx
+1];
3623 RedrawWindow(pane
->hwnd
, &rt_clip
, 0, RDW_INVALIDATE
|RDW_UPDATENOW
);
3625 if (pnmh
->code
== HDN_ENDTRACK
) {
3626 SendMessage(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, pane
->positions
[COLUMNS
], 0);
3628 if (GetScrollPos(pane
->hwnd
, SB_HORZ
) != scroll_pos
)
3636 case HDN_DIVIDERDBLCLICK
: {
3637 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3640 calc_single_width(pane
, phdn
->iItem
);
3641 item
.mask
= HDI_WIDTH
;
3642 item
.cxy
= pane
->widths
[phdn
->iItem
];
3644 SendMessage(pane
->hwndHeader
, HDM_SETITEM
, phdn
->iItem
, (LPARAM
) &item
);
3645 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3652 #endif /* _NO_EXTENSIONS */
3655 static void scan_entry(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3657 TCHAR path
[MAX_PATH
];
3658 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
3660 /* delete sub entries in left pane */
3662 LRESULT res
= SendMessage(child
->left
.hwnd
, LB_GETITEMDATA
, idx
+1, 0);
3663 Entry
* sub
= (Entry
*) res
;
3665 if (res
==LB_ERR
|| !sub
|| sub
->level
<=entry
->level
)
3668 SendMessage(child
->left
.hwnd
, LB_DELETESTRING
, idx
+1, 0);
3671 /* empty right pane */
3672 SendMessage(child
->right
.hwnd
, LB_RESETCONTENT
, 0, 0);
3674 /* release memory */
3675 free_entries(entry
);
3677 /* read contents from disk */
3678 #ifdef _SHELL_FOLDERS
3679 if (entry
->etype
== ET_SHELL
)
3681 read_directory(entry
, NULL
, child
->sortOrder
, hwnd
);
3686 get_path(entry
, path
);
3687 read_directory(entry
, path
, child
->sortOrder
, hwnd
);
3690 /* insert found entries in right pane */
3691 insert_entries(&child
->right
, entry
->down
, child
->filter_pattern
, child
->filter_flags
, -1);
3692 calc_widths(&child
->right
, FALSE
);
3693 #ifndef _NO_EXTENSIONS
3694 set_header(&child
->right
);
3697 child
->header_wdths_ok
= FALSE
;
3699 SetCursor(old_cursor
);
3703 /* expand a directory entry */
3705 static BOOL
expand_entry(ChildWnd
* child
, Entry
* dir
)
3710 if (!dir
|| dir
->expanded
|| !dir
->down
)
3715 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='\0' && p
->next
) {
3718 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='.' &&
3719 p
->data
.cFileName
[2]=='\0' && p
->next
)
3723 /* no subdirectories ? */
3724 if (!(p
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
3727 idx
= SendMessage(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)dir
);
3729 dir
->expanded
= TRUE
;
3731 /* insert entries in left pane */
3732 insert_entries(&child
->left
, p
, NULL
, TF_ALL
, idx
);
3734 if (!child
->header_wdths_ok
) {
3735 if (calc_widths(&child
->left
, FALSE
)) {
3736 #ifndef _NO_EXTENSIONS
3737 set_header(&child
->left
);
3740 child
->header_wdths_ok
= TRUE
;
3748 static void collapse_entry(Pane
* pane
, Entry
* dir
)
3750 int idx
= SendMessage(pane
->hwnd
, LB_FINDSTRING
, 0, (LPARAM
)dir
);
3752 ShowWindow(pane
->hwnd
, SW_HIDE
);
3754 /* hide sub entries */
3756 LRESULT res
= SendMessage(pane
->hwnd
, LB_GETITEMDATA
, idx
+1, 0);
3757 Entry
* sub
= (Entry
*) res
;
3759 if (res
==LB_ERR
|| !sub
|| sub
->level
<=dir
->level
)
3762 SendMessage(pane
->hwnd
, LB_DELETESTRING
, idx
+1, 0);
3765 dir
->expanded
= FALSE
;
3767 ShowWindow(pane
->hwnd
, SW_SHOW
);
3771 static void refresh_right_pane(ChildWnd
* child
)
3773 SendMessage(child
->right
.hwnd
, LB_RESETCONTENT
, 0, 0);
3774 insert_entries(&child
->right
, child
->right
.root
, child
->filter_pattern
, child
->filter_flags
, -1);
3775 calc_widths(&child
->right
, FALSE
);
3777 #ifndef _NO_EXTENSIONS
3778 set_header(&child
->right
);
3782 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3784 TCHAR path
[MAX_PATH
];
3791 child
->left
.cur
= entry
;
3793 child
->right
.root
= entry
->down
? entry
->down
: entry
;
3794 child
->right
.cur
= entry
;
3796 if (!entry
->scanned
)
3797 scan_entry(child
, entry
, idx
, hwnd
);
3799 refresh_right_pane(child
);
3801 get_path(entry
, path
);
3802 lstrcpy(child
->path
, path
);
3804 if (child
->hwnd
) /* only change window title, if the window already exists */
3805 SetWindowText(child
->hwnd
, path
);
3808 if (SetCurrentDirectory(path
))
3813 static void refresh_child(ChildWnd
* child
)
3815 TCHAR path
[MAX_PATH
], drv
[_MAX_DRIVE
+1];
3819 get_path(child
->left
.cur
, path
);
3820 _tsplitpath(path
, drv
, NULL
, NULL
, NULL
);
3822 child
->right
.root
= NULL
;
3824 scan_entry(child
, &child
->root
.entry
, 0, child
->hwnd
);
3826 #ifdef _SHELL_FOLDERS
3827 if (child
->root
.entry
.etype
== ET_SHELL
)
3828 entry
= read_tree(&child
->root
, NULL
, get_path_pidl(path
,child
->hwnd
), drv
, child
->sortOrder
, child
->hwnd
);
3831 entry
= read_tree(&child
->root
, path
, NULL
, drv
, child
->sortOrder
, child
->hwnd
);
3834 entry
= &child
->root
.entry
;
3836 insert_entries(&child
->left
, child
->root
.entry
.down
, NULL
, TF_ALL
, 0);
3838 set_curdir(child
, entry
, 0, child
->hwnd
);
3840 idx
= SendMessage(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)child
->left
.cur
);
3841 SendMessage(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
3845 static void create_drive_bar(void)
3847 TBBUTTON drivebarBtn
= {0, 0, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0};
3848 #ifndef _NO_EXTENSIONS
3849 TCHAR b1
[BUFFER_LEN
];
3854 GetLogicalDriveStrings(BUFFER_LEN
, Globals
.drives
);
3856 Globals
.hdrivebar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
,
3857 IDW_DRIVEBAR
, 2, Globals
.hInstance
, IDB_DRIVEBAR
, &drivebarBtn
,
3858 0, 16, 13, 16, 13, sizeof(TBBUTTON
));
3860 #ifndef _NO_EXTENSIONS
3862 /* insert unix file system button */
3866 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
3868 drivebarBtn
.idCommand
= ID_DRIVE_UNIX_FS
;
3869 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3870 drivebarBtn
.iString
++;
3872 #ifdef _SHELL_FOLDERS
3873 /* insert shell namespace button */
3874 load_string(b1
, IDS_SHELL
);
3875 b1
[lstrlen(b1
)+1] = '\0';
3876 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
3878 drivebarBtn
.idCommand
= ID_DRIVE_SHELL_NS
;
3879 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3880 drivebarBtn
.iString
++;
3883 /* register windows drive root strings */
3884 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)Globals
.drives
);
3887 drivebarBtn
.idCommand
= ID_DRIVE_FIRST
;
3889 for(p
=Globals
.drives
; *p
; ) {
3890 #ifdef _NO_EXTENSIONS
3891 /* insert drive letter */
3892 TCHAR b
[3] = {tolower(*p
)};
3893 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b
);
3895 switch(GetDriveType(p
)) {
3896 case DRIVE_REMOVABLE
: drivebarBtn
.iBitmap
= 1; break;
3897 case DRIVE_CDROM
: drivebarBtn
.iBitmap
= 3; break;
3898 case DRIVE_REMOTE
: drivebarBtn
.iBitmap
= 4; break;
3899 case DRIVE_RAMDISK
: drivebarBtn
.iBitmap
= 5; break;
3900 default:/*DRIVE_FIXED*/ drivebarBtn
.iBitmap
= 2;
3903 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3904 drivebarBtn
.idCommand
++;
3905 drivebarBtn
.iString
++;
3911 static void refresh_drives(void)
3915 /* destroy drive bar */
3916 DestroyWindow(Globals
.hdrivebar
);
3917 Globals
.hdrivebar
= 0;
3919 /* re-create drive bar */
3922 /* update window layout */
3923 GetClientRect(Globals
.hMainWnd
, &rect
);
3924 SendMessage(Globals
.hMainWnd
, WM_SIZE
, 0, MAKELONG(rect
.right
, rect
.bottom
));
3928 static BOOL
launch_file(HWND hwnd
, LPCTSTR cmd
, UINT nCmdShow
)
3930 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3932 if (PtrToUlong(hinst
) <= 32) {
3933 display_error(hwnd
, GetLastError());
3941 static BOOL
launch_entry(Entry
* entry
, HWND hwnd
, UINT nCmdShow
)
3943 TCHAR cmd
[MAX_PATH
];
3945 #ifdef _SHELL_FOLDERS
3946 if (entry
->etype
== ET_SHELL
) {
3949 SHELLEXECUTEINFO shexinfo
;
3951 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFO
);
3952 shexinfo
.fMask
= SEE_MASK_IDLIST
;
3953 shexinfo
.hwnd
= hwnd
;
3954 shexinfo
.lpVerb
= NULL
;
3955 shexinfo
.lpFile
= NULL
;
3956 shexinfo
.lpParameters
= NULL
;
3957 shexinfo
.lpDirectory
= NULL
;
3958 shexinfo
.nShow
= nCmdShow
;
3959 shexinfo
.lpIDList
= get_to_absolute_pidl(entry
, hwnd
);
3961 if (!ShellExecuteEx(&shexinfo
)) {
3962 display_error(hwnd
, GetLastError());
3966 if (shexinfo
.lpIDList
!= entry
->pidl
)
3967 IMalloc_Free(Globals
.iMalloc
, shexinfo
.lpIDList
);
3973 get_path(entry
, cmd
);
3975 /* start program, open document... */
3976 return launch_file(hwnd
, cmd
, nCmdShow
);
3980 static void activate_entry(ChildWnd
* child
, Pane
* pane
, HWND hwnd
)
3982 Entry
* entry
= pane
->cur
;
3987 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
3988 int scanned_old
= entry
->scanned
;
3992 int idx
= SendMessage(child
->left
.hwnd
, LB_GETCURSEL
, 0, 0);
3993 scan_entry(child
, entry
, idx
, hwnd
);
3996 #ifndef _NO_EXTENSIONS
3997 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='\0')
4001 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='.' && entry
->data
.cFileName
[2]=='\0') {
4002 entry
= child
->left
.cur
->up
;
4003 collapse_entry(&child
->left
, entry
);
4005 } else if (entry
->expanded
)
4006 collapse_entry(pane
, child
->left
.cur
);
4008 expand_entry(child
, child
->left
.cur
);
4010 if (!pane
->treePane
) focus_entry
: {
4011 int idxstart
= SendMessage(child
->left
.hwnd
, LB_GETCURSEL
, 0, 0);
4012 int idx
= SendMessage(child
->left
.hwnd
, LB_FINDSTRING
, idxstart
, (LPARAM
)entry
);
4013 SendMessage(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
4014 set_curdir(child
, entry
, idx
, hwnd
);
4019 calc_widths(pane
, FALSE
);
4021 #ifndef _NO_EXTENSIONS
4026 if (GetKeyState(VK_MENU
) < 0)
4027 show_properties_dlg(entry
, child
->hwnd
);
4029 launch_entry(entry
, child
->hwnd
, SW_SHOWNORMAL
);
4034 static BOOL
pane_command(Pane
* pane
, UINT cmd
)
4038 if (pane
->visible_cols
) {
4039 pane
->visible_cols
= 0;
4040 calc_widths(pane
, TRUE
);
4041 #ifndef _NO_EXTENSIONS
4044 InvalidateRect(pane
->hwnd
, 0, TRUE
);
4045 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
|MF_CHECKED
);
4046 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
);
4047 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
4051 case ID_VIEW_ALL_ATTRIBUTES
:
4052 if (pane
->visible_cols
!= COL_ALL
) {
4053 pane
->visible_cols
= COL_ALL
;
4054 calc_widths(pane
, TRUE
);
4055 #ifndef _NO_EXTENSIONS
4058 InvalidateRect(pane
->hwnd
, 0, TRUE
);
4059 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
);
4060 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
|MF_CHECKED
);
4061 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
4065 #ifndef _NO_EXTENSIONS
4066 case ID_PREFERRED_SIZES
: {
4067 calc_widths(pane
, TRUE
);
4069 InvalidateRect(pane
->hwnd
, 0, TRUE
);
4073 /* TODO: more command ids... */
4083 static void set_sort_order(ChildWnd
* child
, SORT_ORDER sortOrder
)
4085 if (child
->sortOrder
!= sortOrder
) {
4086 child
->sortOrder
= sortOrder
;
4087 refresh_child(child
);
4091 static void update_view_menu(ChildWnd
* child
)
4093 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_NAME
, child
->sortOrder
==SORT_NAME
? MF_CHECKED
: MF_UNCHECKED
);
4094 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_TYPE
, child
->sortOrder
==SORT_EXT
? MF_CHECKED
: MF_UNCHECKED
);
4095 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_SIZE
, child
->sortOrder
==SORT_SIZE
? MF_CHECKED
: MF_UNCHECKED
);
4096 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_DATE
, child
->sortOrder
==SORT_DATE
? MF_CHECKED
: MF_UNCHECKED
);
4100 static BOOL
is_directory(LPCTSTR target
)
4102 /*TODO correctly handle UNIX paths */
4103 DWORD target_attr
= GetFileAttributes(target
);
4105 if (target_attr
== INVALID_FILE_ATTRIBUTES
)
4108 return target_attr
&FILE_ATTRIBUTE_DIRECTORY
? TRUE
: FALSE
;
4111 static BOOL
prompt_target(Pane
* pane
, LPTSTR source
, LPTSTR target
)
4113 TCHAR path
[MAX_PATH
];
4116 get_path(pane
->cur
, path
);
4118 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_SELECT_DESTINATION
), pane
->hwnd
, DestinationDlgProc
, (LPARAM
)path
) != IDOK
)
4121 get_path(pane
->cur
, source
);
4123 /* convert relative targets to absolute paths */
4124 if (path
[0]!='/' && path
[1]!=':') {
4125 get_path(pane
->cur
->up
, target
);
4126 len
= lstrlen(target
);
4128 if (target
[len
-1]!='\\' && target
[len
-1]!='/')
4129 target
[len
++] = '/';
4131 lstrcpy(target
+len
, path
);
4133 lstrcpy(target
, path
);
4135 /* If the target already exists as directory, create a new target below this. */
4136 if (is_directory(path
)) {
4137 TCHAR fname
[_MAX_FNAME
], ext
[_MAX_EXT
];
4138 static const TCHAR sAppend
[] = {'%','s','/','%','s','%','s','\0'};
4140 _tsplitpath(source
, NULL
, NULL
, fname
, ext
);
4142 wsprintf(target
, sAppend
, path
, fname
, ext
);
4149 static IContextMenu2
* s_pctxmenu2
= NULL
;
4150 static IContextMenu3
* s_pctxmenu3
= NULL
;
4152 static void CtxMenu_reset(void)
4158 static IContextMenu
* CtxMenu_query_interfaces(IContextMenu
* pcm1
)
4160 IContextMenu
* pcm
= NULL
;
4164 if (IContextMenu_QueryInterface(pcm1
, &IID_IContextMenu3
, (void**)&pcm
) == NOERROR
)
4165 s_pctxmenu3
= (LPCONTEXTMENU3
)pcm
;
4166 else if (IContextMenu_QueryInterface(pcm1
, &IID_IContextMenu2
, (void**)&pcm
) == NOERROR
)
4167 s_pctxmenu2
= (LPCONTEXTMENU2
)pcm
;
4170 IContextMenu_Release(pcm1
);
4176 static BOOL
CtxMenu_HandleMenuMsg(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4179 if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3
, nmsg
, wparam
, lparam
)))
4184 if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2
, nmsg
, wparam
, lparam
)))
4191 static HRESULT
ShellFolderContextMenu(IShellFolder
* shell_folder
, HWND hwndParent
, int cidl
, LPCITEMIDLIST
* apidl
, int x
, int y
)
4194 BOOL executed
= FALSE
;
4196 HRESULT hr
= IShellFolder_GetUIObjectOf(shell_folder
, hwndParent
, cidl
, apidl
, &IID_IContextMenu
, NULL
, (LPVOID
*)&pcm
);
4197 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
4199 if (SUCCEEDED(hr
)) {
4200 HMENU hmenu
= CreatePopupMenu();
4202 pcm
= CtxMenu_query_interfaces(pcm
);
4205 hr
= IContextMenu_QueryContextMenu(pcm
, hmenu
, 0, FCIDM_SHVIEWFIRST
, FCIDM_SHVIEWLAST
, CMF_NORMAL
);
4207 if (SUCCEEDED(hr
)) {
4208 UINT idCmd
= TrackPopupMenu(hmenu
, TPM_LEFTALIGN
|TPM_RETURNCMD
|TPM_RIGHTBUTTON
, x
, y
, 0, hwndParent
, NULL
);
4213 CMINVOKECOMMANDINFO cmi
;
4215 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFO
);
4217 cmi
.hwnd
= hwndParent
;
4218 cmi
.lpVerb
= (LPCSTR
)(INT_PTR
)(idCmd
- FCIDM_SHVIEWFIRST
);
4219 cmi
.lpParameters
= NULL
;
4220 cmi
.lpDirectory
= NULL
;
4221 cmi
.nShow
= SW_SHOWNORMAL
;
4225 hr
= IContextMenu_InvokeCommand(pcm
, &cmi
);
4232 IContextMenu_Release(pcm
);
4235 return FAILED(hr
)? hr
: executed
? S_OK
: S_FALSE
;
4239 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4241 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
4246 LPDRAWITEMSTRUCT dis
= (LPDRAWITEMSTRUCT
)lparam
;
4247 Entry
* entry
= (Entry
*) dis
->itemData
;
4249 if (dis
->CtlID
== IDW_TREE_LEFT
)
4250 draw_item(&child
->left
, dis
, entry
, -1);
4251 else if (dis
->CtlID
== IDW_TREE_RIGHT
)
4252 draw_item(&child
->right
, dis
, entry
, -1);
4254 goto draw_menu_item
;
4259 InitChildWindow(child
);
4263 free_child_window(child
);
4264 SetWindowLongPtr(hwnd
, GWLP_USERDATA
, 0);
4271 GetClientRect(hwnd
, &rt
);
4272 BeginPaint(hwnd
, &ps
);
4273 rt
.left
= child
->split_pos
-SPLIT_WIDTH
/2;
4274 rt
.right
= child
->split_pos
+SPLIT_WIDTH
/2+1;
4275 lastBrush
= SelectObject(ps
.hdc
, GetStockObject(COLOR_SPLITBAR
));
4276 Rectangle(ps
.hdc
, rt
.left
, rt
.top
-1, rt
.right
, rt
.bottom
+1);
4277 SelectObject(ps
.hdc
, lastBrush
);
4278 #ifdef _NO_EXTENSIONS
4279 rt
.top
= rt
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
4280 FillRect(ps
.hdc
, &rt
, GetStockObject(BLACK_BRUSH
));
4282 EndPaint(hwnd
, &ps
);
4286 if (LOWORD(lparam
) == HTCLIENT
) {
4289 ScreenToClient(hwnd
, &pt
);
4291 if (pt
.x
>=child
->split_pos
-SPLIT_WIDTH
/2 && pt
.x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
4292 SetCursor(LoadCursor(0, IDC_SIZEWE
));
4298 case WM_LBUTTONDOWN
: {
4300 int x
= (short)LOWORD(lparam
);
4302 GetClientRect(hwnd
, &rt
);
4304 if (x
>=child
->split_pos
-SPLIT_WIDTH
/2 && x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
4305 last_split
= child
->split_pos
;
4306 #ifdef _NO_EXTENSIONS
4307 draw_splitbar(hwnd
, last_split
);
4315 if (GetCapture() == hwnd
) {
4316 #ifdef _NO_EXTENSIONS
4318 int x
= (short)LOWORD(lparam
);
4319 draw_splitbar(hwnd
, last_split
);
4321 GetClientRect(hwnd
, &rt
);
4322 child
->split_pos
= x
;
4323 resize_tree(child
, rt
.right
, rt
.bottom
);
4329 #ifdef _NO_EXTENSIONS
4330 case WM_CAPTURECHANGED
:
4331 if (GetCapture()==hwnd
&& last_split
>=0)
4332 draw_splitbar(hwnd
, last_split
);
4337 if (wparam
== VK_ESCAPE
)
4338 if (GetCapture() == hwnd
) {
4340 #ifdef _NO_EXTENSIONS
4341 draw_splitbar(hwnd
, last_split
);
4343 child
->split_pos
= last_split
;
4345 GetClientRect(hwnd
, &rt
);
4346 resize_tree(child
, rt
.right
, rt
.bottom
);
4349 SetCursor(LoadCursor(0, IDC_ARROW
));
4354 if (GetCapture() == hwnd
) {
4356 int x
= (short)LOWORD(lparam
);
4358 #ifdef _NO_EXTENSIONS
4359 HDC hdc
= GetDC(hwnd
);
4360 GetClientRect(hwnd
, &rt
);
4362 rt
.left
= last_split
-SPLIT_WIDTH
/2;
4363 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
4364 InvertRect(hdc
, &rt
);
4367 rt
.left
= x
-SPLIT_WIDTH
/2;
4368 rt
.right
= x
+SPLIT_WIDTH
/2+1;
4369 InvertRect(hdc
, &rt
);
4371 ReleaseDC(hwnd
, hdc
);
4373 GetClientRect(hwnd
, &rt
);
4375 if (x
>=0 && x
<rt
.right
) {
4376 child
->split_pos
= x
;
4377 resize_tree(child
, rt
.right
, rt
.bottom
);
4378 rt
.left
= x
-SPLIT_WIDTH
/2;
4379 rt
.right
= x
+SPLIT_WIDTH
/2+1;
4380 InvalidateRect(hwnd
, &rt
, FALSE
);
4381 UpdateWindow(child
->left
.hwnd
);
4383 UpdateWindow(child
->right
.hwnd
);
4389 #ifndef _NO_EXTENSIONS
4390 case WM_GETMINMAXINFO
:
4391 DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
4393 {LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
4395 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
4396 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
4398 #endif /* _NO_EXTENSIONS */
4401 if (SetCurrentDirectory(child
->path
))
4403 SetFocus(child
->focus_pane
? child
->right
.hwnd
: child
->left
.hwnd
);
4406 case WM_DISPATCH_COMMAND
: {
4407 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4409 switch(LOWORD(wparam
)) {
4410 case ID_WINDOW_NEW
: {
4411 ChildWnd
* new_child
= alloc_child_window(child
->path
, NULL
, hwnd
);
4413 if (!create_child_window(new_child
))
4414 HeapFree(GetProcessHeap(), 0, new_child
);
4420 refresh_child(child
);
4424 activate_entry(child
, pane
, hwnd
);
4427 case ID_FILE_MOVE
: {
4428 TCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
4430 if (prompt_target(pane
, source
, target
)) {
4431 SHFILEOPSTRUCT shfo
= {hwnd
, FO_MOVE
, source
, target
};
4433 source
[lstrlen(source
)+1] = '\0';
4434 target
[lstrlen(target
)+1] = '\0';
4436 if (!SHFileOperation(&shfo
))
4437 refresh_child(child
);
4441 case ID_FILE_COPY
: {
4442 TCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
4444 if (prompt_target(pane
, source
, target
)) {
4445 SHFILEOPSTRUCT shfo
= {hwnd
, FO_COPY
, source
, target
};
4447 source
[lstrlen(source
)+1] = '\0';
4448 target
[lstrlen(target
)+1] = '\0';
4450 if (!SHFileOperation(&shfo
))
4451 refresh_child(child
);
4455 case ID_FILE_DELETE
: {
4456 TCHAR path
[BUFFER_LEN
];
4457 SHFILEOPSTRUCT shfo
= {hwnd
, FO_DELETE
, path
, NULL
, FOF_ALLOWUNDO
};
4459 get_path(pane
->cur
, path
);
4461 path
[lstrlen(path
)+1] = '\0';
4463 if (!SHFileOperation(&shfo
))
4464 refresh_child(child
);
4467 case ID_VIEW_SORT_NAME
:
4468 set_sort_order(child
, SORT_NAME
);
4471 case ID_VIEW_SORT_TYPE
:
4472 set_sort_order(child
, SORT_EXT
);
4475 case ID_VIEW_SORT_SIZE
:
4476 set_sort_order(child
, SORT_SIZE
);
4479 case ID_VIEW_SORT_DATE
:
4480 set_sort_order(child
, SORT_DATE
);
4483 case ID_VIEW_FILTER
: {
4484 struct FilterDialog dlg
;
4486 memset(&dlg
, 0, sizeof(struct FilterDialog
));
4487 lstrcpy(dlg
.pattern
, child
->filter_pattern
);
4488 dlg
.flags
= child
->filter_flags
;
4490 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE
), hwnd
, FilterDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
4491 lstrcpy(child
->filter_pattern
, dlg
.pattern
);
4492 child
->filter_flags
= dlg
.flags
;
4493 refresh_right_pane(child
);
4497 case ID_VIEW_SPLIT
: {
4498 last_split
= child
->split_pos
;
4499 #ifdef _NO_EXTENSIONS
4500 draw_splitbar(hwnd
, last_split
);
4505 case ID_EDIT_PROPERTIES
:
4506 show_properties_dlg(pane
->cur
, child
->hwnd
);
4510 return pane_command(pane
, LOWORD(wparam
));
4516 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4518 switch(HIWORD(wparam
)) {
4519 case LBN_SELCHANGE
: {
4520 int idx
= SendMessage(pane
->hwnd
, LB_GETCURSEL
, 0, 0);
4521 Entry
* entry
= (Entry
*) SendMessage(pane
->hwnd
, LB_GETITEMDATA
, idx
, 0);
4523 if (pane
== &child
->left
)
4524 set_curdir(child
, entry
, idx
, hwnd
);
4530 activate_entry(child
, pane
, hwnd
);
4535 #ifndef _NO_EXTENSIONS
4537 NMHDR
* pnmh
= (NMHDR
*) lparam
;
4538 return pane_notify(pnmh
->idFrom
==IDW_HEADER_LEFT
? &child
->left
: &child
->right
, pnmh
);}
4541 #ifdef _SHELL_FOLDERS
4542 case WM_CONTEXTMENU
: {
4547 /* first select the current item in the listbox */
4548 HWND hpanel
= (HWND
) wparam
;
4549 pt_clnt
.x
= pt
.x
= (short)LOWORD(lparam
);
4550 pt_clnt
.y
= pt
.y
= (short)HIWORD(lparam
);
4551 ScreenToClient(hpanel
, &pt_clnt
);
4552 SendMessage(hpanel
, WM_LBUTTONDOWN
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4553 SendMessage(hpanel
, WM_LBUTTONUP
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4555 /* now create the popup menu using shell namespace and IContextMenu */
4556 pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4557 idx
= SendMessage(pane
->hwnd
, LB_GETCURSEL
, 0, 0);
4560 Entry
* entry
= (Entry
*) SendMessage(pane
->hwnd
, LB_GETITEMDATA
, idx
, 0);
4562 LPITEMIDLIST pidl_abs
= get_to_absolute_pidl(entry
, hwnd
);
4565 IShellFolder
* parentFolder
;
4566 LPCITEMIDLIST pidlLast
;
4568 /* get and use the parent folder to display correct context menu in all cases */
4569 if (SUCCEEDED(SHBindToParent(pidl_abs
, &IID_IShellFolder
, (LPVOID
*)&parentFolder
, &pidlLast
))) {
4570 if (ShellFolderContextMenu(parentFolder
, hwnd
, 1, &pidlLast
, pt
.x
, pt
.y
) == S_OK
)
4571 refresh_child(child
);
4573 IShellFolder_Release(parentFolder
);
4576 IMalloc_Free(Globals
.iMalloc
, pidl_abs
);
4582 case WM_MEASUREITEM
:
4584 if (!wparam
) /* Is the message menu-related? */
4585 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4590 case WM_INITMENUPOPUP
:
4591 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4594 update_view_menu(child
);
4597 case WM_MENUCHAR
: /* only supported by IContextMenu3 */
4599 LRESULT lResult
= 0;
4601 IContextMenu3_HandleMenuMsg2(s_pctxmenu3
, nmsg
, wparam
, lparam
, &lResult
);
4609 if (wparam
!= SIZE_MINIMIZED
)
4610 resize_tree(child
, LOWORD(lparam
), HIWORD(lparam
));
4614 return DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
4621 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4623 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(GetParent(hwnd
), GWLP_USERDATA
);
4624 Pane
* pane
= (Pane
*) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
4628 #ifndef _NO_EXTENSIONS
4635 child
->focus_pane
= pane
==&child
->right
? 1: 0;
4636 SendMessage(hwnd
, LB_SETSEL
, TRUE
, 1);
4637 /*TODO: check menu items */
4641 if (wparam
== VK_TAB
) {
4642 /*TODO: SetFocus(Globals.hdrivebar) */
4643 SetFocus(child
->focus_pane
? child
->left
.hwnd
: child
->right
.hwnd
);
4647 return CallWindowProc(g_orgTreeWndProc
, hwnd
, nmsg
, wparam
, lparam
);
4651 static void InitInstance(HINSTANCE hinstance
)
4653 static const TCHAR sFont
[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4660 INITCOMMONCONTROLSEX icc
= {
4661 sizeof(INITCOMMONCONTROLSEX
),
4667 setlocale(LC_COLLATE
, ""); /* set collating rules to local settings for compareName */
4669 InitCommonControlsEx(&icc
);
4672 /* register frame window class */
4674 wcFrame
.cbSize
= sizeof(WNDCLASSEX
);
4676 wcFrame
.lpfnWndProc
= FrameWndProc
;
4677 wcFrame
.cbClsExtra
= 0;
4678 wcFrame
.cbWndExtra
= 0;
4679 wcFrame
.hInstance
= hinstance
;
4680 wcFrame
.hIcon
= LoadIcon(hinstance
, MAKEINTRESOURCE(IDI_WINEFILE
));
4681 wcFrame
.hCursor
= LoadCursor(0, IDC_ARROW
);
4682 wcFrame
.hbrBackground
= 0;
4683 wcFrame
.lpszMenuName
= 0;
4684 wcFrame
.lpszClassName
= sWINEFILEFRAME
;
4685 wcFrame
.hIconSm
= (HICON
)LoadImage(hinstance
,
4686 MAKEINTRESOURCE(IDI_WINEFILE
),
4688 GetSystemMetrics(SM_CXSMICON
),
4689 GetSystemMetrics(SM_CYSMICON
),
4692 Globals
.hframeClass
= RegisterClassEx(&wcFrame
);
4695 /* register tree windows class */
4697 wcChild
.style
= CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
;
4698 wcChild
.lpfnWndProc
= ChildWndProc
;
4699 wcChild
.cbClsExtra
= 0;
4700 wcChild
.cbWndExtra
= 0;
4701 wcChild
.hInstance
= hinstance
;
4703 wcChild
.hCursor
= LoadCursor(0, IDC_ARROW
);
4704 wcChild
.hbrBackground
= 0;
4705 wcChild
.lpszMenuName
= 0;
4706 wcChild
.lpszClassName
= sWINEFILETREE
;
4708 hChildClass
= RegisterClass(&wcChild
);
4711 Globals
.haccel
= LoadAccelerators(hinstance
, MAKEINTRESOURCE(IDA_WINEFILE
));
4713 Globals
.hfont
= CreateFont(-MulDiv(8,GetDeviceCaps(hdc
,LOGPIXELSY
),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont
);
4717 Globals
.hInstance
= hinstance
;
4719 #ifdef _SHELL_FOLDERS
4721 CoGetMalloc(MEMCTX_TASK
, &Globals
.iMalloc
);
4722 SHGetDesktopFolder(&Globals
.iDesktop
);
4724 Globals
.cfStrFName
= RegisterClipboardFormatA(CFSTR_FILENAME
);
4726 Globals
.cfStrFName
= RegisterClipboardFormat(CFSTR_FILENAME
);
4730 /* load column strings */
4733 load_string(g_pos_names
[col
++], IDS_COL_NAME
);
4734 load_string(g_pos_names
[col
++], IDS_COL_SIZE
);
4735 load_string(g_pos_names
[col
++], IDS_COL_CDATE
);
4736 #ifndef _NO_EXTENSIONS
4737 load_string(g_pos_names
[col
++], IDS_COL_ADATE
);
4738 load_string(g_pos_names
[col
++], IDS_COL_MDATE
);
4739 load_string(g_pos_names
[col
++], IDS_COL_IDX
);
4740 load_string(g_pos_names
[col
++], IDS_COL_LINKS
);
4742 load_string(g_pos_names
[col
++], IDS_COL_ATTR
);
4743 #ifndef _NO_EXTENSIONS
4744 load_string(g_pos_names
[col
++], IDS_COL_SEC
);
4749 static void show_frame(HWND hwndParent
, int cmdshow
, LPCTSTR path
)
4751 static const TCHAR sMDICLIENT
[] = {'M','D','I','C','L','I','E','N','T','\0'};
4753 TCHAR buffer
[MAX_PATH
], b1
[BUFFER_LEN
];
4755 HMENU hMenuFrame
, hMenuWindow
;
4758 CLIENTCREATESTRUCT ccs
;
4760 if (Globals
.hMainWnd
)
4763 opts
= load_registry_settings();
4764 hMenuFrame
= LoadMenu(Globals
.hInstance
, MAKEINTRESOURCE(IDM_WINEFILE
));
4765 hMenuWindow
= GetSubMenu(hMenuFrame
, GetMenuItemCount(hMenuFrame
)-2);
4767 Globals
.hMenuFrame
= hMenuFrame
;
4768 Globals
.hMenuView
= GetSubMenu(hMenuFrame
, 3);
4769 Globals
.hMenuOptions
= GetSubMenu(hMenuFrame
, 4);
4771 ccs
.hWindowMenu
= hMenuWindow
;
4772 ccs
.idFirstChild
= IDW_FIRST_CHILD
;
4775 /* create main window */
4776 Globals
.hMainWnd
= CreateWindowEx(0, MAKEINTRESOURCE(Globals
.hframeClass
), RS(b1
,IDS_WINE_FILE
), WS_OVERLAPPEDWINDOW
,
4777 opts
.start_x
, opts
.start_y
, opts
.width
, opts
.height
,
4778 hwndParent
, Globals
.hMenuFrame
, Globals
.hInstance
, 0/*lpParam*/);
4781 Globals
.hmdiclient
= CreateWindowEx(0, sMDICLIENT
, NULL
,
4782 WS_CHILD
|WS_CLIPCHILDREN
|WS_VSCROLL
|WS_HSCROLL
|WS_VISIBLE
|WS_BORDER
,
4784 Globals
.hMainWnd
, 0, Globals
.hInstance
, &ccs
);
4786 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_DRIVE_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4787 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_SAVESETTINGS
, MF_BYCOMMAND
);
4792 TBBUTTON toolbarBtns
[] = {
4793 {0, 0, 0, BTNS_SEP
, {0, 0}, 0, 0},
4794 {0, ID_WINDOW_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4795 {1, ID_WINDOW_CASCADE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4796 {2, ID_WINDOW_TILE_HORZ
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4797 {3, ID_WINDOW_TILE_VERT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4799 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4800 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4803 Globals
.htoolbar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
,
4804 IDW_TOOLBAR
, 2, Globals
.hInstance
, IDB_TOOLBAR
, toolbarBtns
,
4805 sizeof(toolbarBtns
)/sizeof(TBBUTTON
), 16, 15, 16, 15, sizeof(TBBUTTON
));
4806 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_TOOL_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4809 Globals
.hstatusbar
= CreateStatusWindow(WS_CHILD
|WS_VISIBLE
, 0, Globals
.hMainWnd
, IDW_STATUSBAR
);
4810 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
4812 /* CreateStatusWindow does not accept WS_BORDER
4813 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
4814 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
4815 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
4817 /*TODO: read paths from registry */
4819 if (!path
|| !*path
) {
4820 GetCurrentDirectory(MAX_PATH
, buffer
);
4824 ShowWindow(Globals
.hMainWnd
, cmdshow
);
4826 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4827 /* Shell Namespace as default: */
4828 child
= alloc_child_window(path
, get_path_pidl(path
,Globals
.hMainWnd
), Globals
.hMainWnd
);
4830 child
= alloc_child_window(path
, NULL
, Globals
.hMainWnd
);
4833 child
->pos
.showCmd
= SW_SHOWMAXIMIZED
;
4834 child
->pos
.rcNormalPosition
.left
= 0;
4835 child
->pos
.rcNormalPosition
.top
= 0;
4836 child
->pos
.rcNormalPosition
.right
= 320;
4837 child
->pos
.rcNormalPosition
.bottom
= 280;
4839 if (!create_child_window(child
))
4840 HeapFree(GetProcessHeap(), 0, child
);
4842 SetWindowPlacement(child
->hwnd
, &child
->pos
);
4844 Globals
.himl
= ImageList_LoadBitmap(Globals
.hInstance
, MAKEINTRESOURCE(IDB_IMAGES
), 16, 0, RGB(0,255,0));
4846 Globals
.prescan_node
= FALSE
;
4848 UpdateWindow(Globals
.hMainWnd
);
4850 if (path
&& path
[0])
4853 TCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
4854 TCHAR fullname
[_MAX_FNAME
+_MAX_EXT
+1];
4856 memset(name
,0,sizeof(name
));
4857 memset(name
,0,sizeof(ext
));
4858 _tsplitpath(path
, drv
, dir
, name
, ext
);
4861 count
= SendMessage(child
->right
.hwnd
, LB_GETCOUNT
, 0, 0);
4862 lstrcpy(fullname
,name
);
4863 lstrcat(fullname
,ext
);
4865 for (index
= 0; index
< count
; index
++)
4867 Entry
* entry
= (Entry
*) SendMessage(child
->right
.hwnd
, LB_GETITEMDATA
, index
, 0);
4868 if (lstrcmp(entry
->data
.cFileName
,fullname
)==0 ||
4869 lstrcmp(entry
->data
.cAlternateFileName
,fullname
)==0)
4871 SendMessage(child
->right
.hwnd
, LB_SETCURSEL
, index
, 0);
4872 SetFocus(child
->right
.hwnd
);
4880 static void ExitInstance(void)
4882 #ifdef _SHELL_FOLDERS
4883 IShellFolder_Release(Globals
.iDesktop
);
4884 IMalloc_Release(Globals
.iMalloc
);
4888 DeleteObject(Globals
.hfont
);
4889 ImageList_Destroy(Globals
.himl
);
4892 #ifdef _NO_EXTENSIONS
4894 /* search for already running win[e]files */
4896 static int g_foundPrevInstance
= 0;
4898 static BOOL CALLBACK
EnumWndProc(HWND hwnd
, LPARAM lparam
)
4902 GetClassName(hwnd
, cls
, 128);
4904 if (!lstrcmp(cls
, (LPCTSTR
)lparam
)) {
4905 g_foundPrevInstance
++;
4912 /* search for window of given class name to allow only one running instance */
4913 static int find_window_class(LPCTSTR classname
)
4915 EnumWindows(EnumWndProc
, (LPARAM
)classname
);
4917 if (g_foundPrevInstance
)
4925 static int winefile_main(HINSTANCE hinstance
, int cmdshow
, LPCTSTR path
)
4929 InitInstance(hinstance
);
4931 show_frame(0, cmdshow
, path
);
4933 while(GetMessage(&msg
, 0, 0, 0)) {
4934 if (Globals
.hmdiclient
&& TranslateMDISysAccel(Globals
.hmdiclient
, &msg
))
4937 if (Globals
.hMainWnd
&& TranslateAccelerator(Globals
.hMainWnd
, Globals
.haccel
, &msg
))
4940 TranslateMessage(&msg
);
4941 DispatchMessage(&msg
);
4950 #if defined(UNICODE) && defined(_MSC_VER)
4951 int APIENTRY
wWinMain(HINSTANCE hinstance
, HINSTANCE previnstance
, LPWSTR cmdline
, int cmdshow
)
4953 int APIENTRY
WinMain(HINSTANCE hinstance
, HINSTANCE previnstance
, LPSTR cmdline
, int cmdshow
)
4956 #ifdef _NO_EXTENSIONS
4957 if (find_window_class(sWINEFILEFRAME
))
4961 #if defined(UNICODE) && !defined(_MSC_VER)
4962 { /* convert ANSI cmdline into WCS path string */
4963 TCHAR buffer
[MAX_PATH
];
4964 MultiByteToWideChar(CP_ACP
, 0, cmdline
, -1, buffer
, MAX_PATH
);
4965 winefile_main(hinstance
, cmdshow
, buffer
);
4968 winefile_main(hinstance
, cmdshow
, cmdline
);