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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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'};
78 typedef struct _Entry
{
89 #ifndef _NO_EXTENSIONS
90 BY_HANDLE_FILE_INFORMATION bhfi
;
92 enum ENTRY_TYPE etype
;
103 TCHAR path
[MAX_PATH
];
104 TCHAR volname
[_MAX_FNAME
];
114 COL_ATTRIBUTES
= 0x08,
116 #ifdef _NO_EXTENSIONS
117 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
121 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
|COL_INDEX
|COL_LINKS
134 #ifndef _NO_EXTENSIONS
138 #ifndef _NO_EXTENSIONS
144 int positions
[COLUMNS
+1];
156 int focus_pane
; /* 0: left 1: right */
159 BOOL header_wdths_ok
;
161 TCHAR path
[MAX_PATH
];
162 TCHAR filter_pattern
[MAX_PATH
];
166 SORT_ORDER sortOrder
;
171 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
);
172 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
);
173 static void refresh_child(ChildWnd
* child
);
174 static void refresh_drives(void);
175 static void get_path(Entry
* dir
, PTSTR path
);
176 static void format_date(const FILETIME
* ft
, TCHAR
* buffer
, int visible_cols
);
178 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
179 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
180 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
184 WINEFILE_GLOBALS Globals
;
186 static int last_split
;
188 /* some common string constants */
189 static const TCHAR sEmpty
[] = {'\0'};
190 static const TCHAR sSpace
[] = {' ', '\0'};
191 static const TCHAR sNumFmt
[] = {'%','d','\0'};
192 static const TCHAR sQMarks
[] = {'?','?','?','\0'};
194 /* window class names */
195 static const TCHAR sWINEFILEFRAME
[] = {'W','F','S','_','F','r','a','m','e','\0'};
196 static const TCHAR sWINEFILETREE
[] = {'W','F','S','_','T','r','e','e','\0'};
199 /* #define LONGLONGARG _T("I64") */
200 static const TCHAR sLongHexFmt
[] = {'%','I','6','4','X','\0'};
201 static const TCHAR sLongNumFmt
[] = {'%','I','6','4','d','\0'};
203 /* #define LONGLONGARG _T("L") */
204 static const TCHAR sLongHexFmt
[] = {'%','L','X','\0'};
205 static const TCHAR sLongNumFmt
[] = {'%','L','d','\0'};
209 /* load resource string */
210 static LPTSTR
load_string(LPTSTR buffer
, UINT id
)
212 LoadString(Globals
.hInstance
, id
, buffer
, BUFFER_LEN
);
217 #define RS(b, i) load_string(b, i)
220 /* display error message for the specified WIN32 error code */
221 static void display_error(HWND hwnd
, DWORD error
)
223 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
226 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_FROM_SYSTEM
,
227 0, error
, MAKELANGID(LANG_NEUTRAL
,SUBLANG_DEFAULT
), (PTSTR
)&msg
, 0, NULL
))
228 MessageBox(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
230 MessageBox(hwnd
, RS(b1
,IDS_ERROR
), RS(b2
,IDS_WINEFILE
), MB_OK
);
236 /* display network error message using WNetGetLastError() */
237 static void display_network_error(HWND hwnd
)
239 TCHAR msg
[BUFFER_LEN
], provider
[BUFFER_LEN
], b2
[BUFFER_LEN
];
242 if (WNetGetLastError(&error
, msg
, BUFFER_LEN
, provider
, BUFFER_LEN
) == NO_ERROR
)
243 MessageBox(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
246 static VOID
WineLicense(HWND Wnd
)
248 TCHAR cap
[20], text
[1024];
249 LoadString(Globals
.hInstance
, IDS_LICENSE
, text
, 1024);
250 LoadString(Globals
.hInstance
, IDS_LICENSE_CAPTION
, cap
, 20);
251 MessageBox(Wnd
, text
, cap
, MB_ICONINFORMATION
| MB_OK
);
254 static VOID
WineWarranty(HWND Wnd
)
256 TCHAR cap
[20], text
[1024];
257 LoadString(Globals
.hInstance
, IDS_WARRANTY
, text
, 1024);
258 LoadString(Globals
.hInstance
, IDS_WARRANTY_CAPTION
, cap
, 20);
259 MessageBox(Wnd
, text
, cap
, MB_ICONEXCLAMATION
| MB_OK
);
267 /* call vswprintf() in msvcrt.dll */
268 /*TODO: fix swprintf() in non-msvcrt mode, so that this dynamic linking function can be removed */
269 static int msvcrt_swprintf(WCHAR
* buffer
, const WCHAR
* fmt
, ...)
271 static int (__cdecl
*pvswprintf
)(WCHAR
*, const WCHAR
*, va_list) = NULL
;
276 HMODULE hModMsvcrt
= LoadLibraryA("msvcrt");
277 pvswprintf
= (int(__cdecl
*)(WCHAR
*,const WCHAR
*,va_list)) GetProcAddress(hModMsvcrt
, "vswprintf");
281 ret
= (*pvswprintf
)(buffer
, fmt
, ap
);
287 static LPCWSTR
my_wcsrchr(LPCWSTR str
, WCHAR c
)
302 #define _tcsrchr my_wcsrchr
304 #define _tcsrchr strrchr
307 #endif /* __WINE__ */
310 /* allocate and initialise a directory entry */
311 static Entry
* alloc_entry(void)
313 Entry
* entry
= (Entry
*) malloc(sizeof(Entry
));
315 #ifdef _SHELL_FOLDERS
317 entry
->folder
= NULL
;
324 /* free a directory entry */
325 static void free_entry(Entry
* entry
)
327 #ifdef _SHELL_FOLDERS
328 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
329 DestroyIcon(entry
->hicon
);
331 if (entry
->folder
&& entry
->folder
!=Globals
.iDesktop
)
332 IShellFolder_Release(entry
->folder
);
335 IMalloc_Free(Globals
.iMalloc
, entry
->pidl
);
341 /* recursively free all child entries */
342 static void free_entries(Entry
* dir
)
344 Entry
*entry
, *next
=dir
->down
;
360 static void read_directory_win(Entry
* dir
, LPCTSTR path
)
362 Entry
* first_entry
= NULL
;
366 int level
= dir
->level
+ 1;
367 WIN32_FIND_DATA w32fd
;
369 #ifndef _NO_EXTENSIONS
373 TCHAR buffer
[MAX_PATH
], *p
;
374 for(p
=buffer
; *path
; )
381 hFind
= FindFirstFile(buffer
, &w32fd
);
383 if (hFind
!= INVALID_HANDLE_VALUE
) {
385 #ifdef _NO_EXTENSIONS
386 /* hide directory entry "." */
387 if (w32fd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
388 LPCTSTR name
= w32fd
.cFileName
;
390 if (name
[0]=='.' && name
[1]=='\0')
394 entry
= alloc_entry();
402 memcpy(&entry
->data
, &w32fd
, sizeof(WIN32_FIND_DATA
));
405 entry
->expanded
= FALSE
;
406 entry
->scanned
= FALSE
;
407 entry
->level
= level
;
409 #ifndef _NO_EXTENSIONS
410 entry
->etype
= ET_WINDOWS
;
411 entry
->bhfi_valid
= FALSE
;
413 lstrcpy(p
, entry
->data
.cFileName
);
415 hFile
= CreateFile(buffer
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
416 0, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0);
418 if (hFile
!= INVALID_HANDLE_VALUE
) {
419 if (GetFileInformationByHandle(hFile
, &entry
->bhfi
))
420 entry
->bhfi_valid
= TRUE
;
427 } while(FindNextFile(hFind
, &w32fd
));
435 dir
->down
= first_entry
;
440 static Entry
* find_entry_win(Entry
* dir
, LPCTSTR name
)
444 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
446 LPCTSTR q
= entry
->data
.cFileName
;
449 if (!*p
|| *p
==TEXT('\\') || *p
==TEXT('/'))
451 } while(tolower(*p
++) == tolower(*q
++));
454 q
= entry
->data
.cAlternateFileName
;
457 if (!*p
|| *p
==TEXT('\\') || *p
==TEXT('/'))
459 } while(tolower(*p
++) == tolower(*q
++));
466 static Entry
* read_tree_win(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
468 TCHAR buffer
[MAX_PATH
];
469 Entry
* entry
= &root
->entry
;
473 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
475 #ifndef _NO_EXTENSIONS
476 entry
->etype
= ET_WINDOWS
;
480 while(*s
&& *s
!=TEXT('\\') && *s
!=TEXT('/'))
483 while(*s
==TEXT('\\') || *s
==TEXT('/'))
489 read_directory(entry
, buffer
, sortOrder
, hwnd
);
492 entry
->expanded
= TRUE
;
497 entry
= find_entry_win(entry
, s
);
500 SetCursor(old_cursor
);
506 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
508 static BOOL
time_to_filetime(const time_t* t
, FILETIME
* ftime
)
510 struct tm
* tm
= gmtime(t
);
516 stime
.wYear
= tm
->tm_year
+1900;
517 stime
.wMonth
= tm
->tm_mon
+1;
518 /* stime.wDayOfWeek */
519 stime
.wDay
= tm
->tm_mday
;
520 stime
.wHour
= tm
->tm_hour
;
521 stime
.wMinute
= tm
->tm_min
;
522 stime
.wSecond
= tm
->tm_sec
;
524 return SystemTimeToFileTime(&stime
, ftime
);
527 static void read_directory_unix(Entry
* dir
, LPCTSTR path
)
529 Entry
* first_entry
= NULL
;
534 int level
= dir
->level
+ 1;
536 char cpath
[MAX_PATH
];
538 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, cpath
, MAX_PATH
, NULL
, NULL
);
540 const char* cpath
= path
;
543 pdir
= opendir(cpath
);
548 char buffer
[MAX_PATH
], *p
;
551 for(p
=buffer
,s
=cpath
; *s
; )
554 if (p
==buffer
|| p
[-1]!='/')
557 while((ent
=readdir(pdir
))) {
558 entry
= alloc_entry();
566 entry
->etype
= ET_UNIX
;
568 strcpy(p
, ent
->d_name
);
570 MultiByteToWideChar(CP_UNIXCP
, 0, p
, -1, entry
->data
.cFileName
, MAX_PATH
);
572 lstrcpy(entry
->data
.cFileName
, p
);
575 if (!stat(buffer
, &st
)) {
576 entry
->data
.dwFileAttributes
= p
[0]=='.'? FILE_ATTRIBUTE_HIDDEN
: 0;
578 if (S_ISDIR(st
.st_mode
))
579 entry
->data
.dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
581 entry
->data
.nFileSizeLow
= st
.st_size
& 0xFFFFFFFF;
582 entry
->data
.nFileSizeHigh
= st
.st_size
>> 32;
584 memset(&entry
->data
.ftCreationTime
, 0, sizeof(FILETIME
));
585 time_to_filetime(&st
.st_atime
, &entry
->data
.ftLastAccessTime
);
586 time_to_filetime(&st
.st_mtime
, &entry
->data
.ftLastWriteTime
);
588 entry
->bhfi
.nFileIndexLow
= ent
->d_ino
;
589 entry
->bhfi
.nFileIndexHigh
= 0;
591 entry
->bhfi
.nNumberOfLinks
= st
.st_nlink
;
593 entry
->bhfi_valid
= TRUE
;
595 entry
->data
.nFileSizeLow
= 0;
596 entry
->data
.nFileSizeHigh
= 0;
597 entry
->bhfi_valid
= FALSE
;
602 entry
->expanded
= FALSE
;
603 entry
->scanned
= FALSE
;
604 entry
->level
= level
;
615 dir
->down
= first_entry
;
619 static Entry
* find_entry_unix(Entry
* dir
, LPCTSTR name
)
623 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
625 LPCTSTR q
= entry
->data
.cFileName
;
628 if (!*p
|| *p
==TEXT('/'))
630 } while(*p
++ == *q
++);
636 static Entry
* read_tree_unix(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
638 TCHAR buffer
[MAX_PATH
];
639 Entry
* entry
= &root
->entry
;
643 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
645 entry
->etype
= ET_UNIX
;
648 while(*s
&& *s
!=TEXT('/'))
651 while(*s
== TEXT('/'))
657 read_directory(entry
, buffer
, sortOrder
, hwnd
);
660 entry
->expanded
= TRUE
;
665 entry
= find_entry_unix(entry
, s
);
668 SetCursor(old_cursor
);
673 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
676 #ifdef _SHELL_FOLDERS
679 #define get_strret get_strretW
680 #define path_from_pidl path_from_pidlW
682 #define get_strret get_strretA
683 #define path_from_pidl path_from_pidlA
687 static void free_strret(STRRET
* str
)
689 if (str
->uType
== STRRET_WSTR
)
690 IMalloc_Free(Globals
.iMalloc
, str
->UNION_MEMBER(pOleStr
));
696 static LPSTR
strcpyn(LPSTR dest
, LPCSTR source
, size_t count
)
701 for(s
=source
; count
&&(*d
++=*s
++); )
707 static void get_strretA(STRRET
* str
, const SHITEMID
* shiid
, LPSTR buffer
, int len
)
711 WideCharToMultiByte(CP_ACP
, 0, str
->UNION_MEMBER(pOleStr
), -1, buffer
, len
, NULL
, NULL
);
715 strcpyn(buffer
, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), len
);
719 strcpyn(buffer
, str
->UNION_MEMBER(cStr
), len
);
723 static HRESULT
path_from_pidlA(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPSTR buffer
, int len
)
727 /* SHGDN_FORPARSING: get full path of id list */
728 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, SHGDN_FORPARSING
, &str
);
731 get_strretA(&str
, &pidl
->mkid
, buffer
, len
);
741 static LPWSTR
wcscpyn(LPWSTR dest
, LPCWSTR source
, size_t count
)
746 for(s
=source
; count
&&(*d
++=*s
++); )
752 static void get_strretW(STRRET
* str
, const SHITEMID
* shiid
, LPWSTR buffer
, int len
)
756 wcscpyn(buffer
, str
->UNION_MEMBER(pOleStr
), len
);
760 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), -1, buffer
, len
);
764 MultiByteToWideChar(CP_ACP
, 0, str
->UNION_MEMBER(cStr
), -1, buffer
, len
);
769 static HRESULT
name_from_pidl(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPTSTR buffer
, int len
, SHGDNF flags
)
773 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, flags
, &str
);
776 get_strret(&str
, &pidl
->mkid
, buffer
, len
);
785 static HRESULT
path_from_pidlW(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPWSTR buffer
, int len
)
789 /* SHGDN_FORPARSING: get full path of id list */
790 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, SHGDN_FORPARSING
, &str
);
793 get_strretW(&str
, &pidl
->mkid
, buffer
, len
);
802 /* create an item id list from a file system path */
804 static LPITEMIDLIST
get_path_pidl(LPTSTR path
, HWND hwnd
)
811 LPWSTR buffer
= path
;
813 WCHAR buffer
[MAX_PATH
];
814 MultiByteToWideChar(CP_ACP
, 0, path
, -1, buffer
, MAX_PATH
);
817 hr
= IShellFolder_ParseDisplayName(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
825 /* convert an item id list from relative to absolute (=relative to the desktop) format */
827 static LPITEMIDLIST
get_to_absolute_pidl(Entry
* entry
, HWND hwnd
)
829 if (entry
->up
&& entry
->up
->etype
==ET_SHELL
) {
830 IShellFolder
* folder
= entry
->up
->folder
;
831 WCHAR buffer
[MAX_PATH
];
833 HRESULT hr
= path_from_pidlW(folder
, entry
->pidl
, buffer
, MAX_PATH
);
839 hr
= IShellFolder_ParseDisplayName(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
844 } else if (entry
->etype
== ET_WINDOWS
) {
845 TCHAR path
[MAX_PATH
];
847 get_path(entry
, path
);
849 return get_path_pidl(path
, hwnd
);
850 } else if (entry
->pidl
)
851 return ILClone(entry
->pidl
);
857 static HICON
extract_icon(IShellFolder
* folder
, LPCITEMIDLIST pidl
)
859 IExtractIcon
* pExtract
;
861 if (SUCCEEDED(IShellFolder_GetUIObjectOf(folder
, 0, 1, (LPCITEMIDLIST
*)&pidl
, &IID_IExtractIcon
, 0, (LPVOID
*)&pExtract
))) {
862 TCHAR path
[_MAX_PATH
];
867 if (SUCCEEDED(IExtractIconW_GetIconLocation(pExtract
, GIL_FORSHELL
, path
, _MAX_PATH
, &idx
, &flags
))) {
868 if (!(flags
& GIL_NOTFILENAME
)) {
870 idx
= 0; /* special case for some control panel applications */
872 if ((int)ExtractIconEx(path
, idx
, 0, &hicon
, 1) > 0)
873 flags
&= ~GIL_DONTCACHE
;
875 HICON hIconLarge
= 0;
877 HRESULT hr
= IExtractIconW_Extract(pExtract
, path
, idx
, &hIconLarge
, &hicon
, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON
)));
880 DestroyIcon(hIconLarge
);
891 static Entry
* find_entry_shell(Entry
* dir
, LPCITEMIDLIST pidl
)
895 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
896 if (entry
->pidl
->mkid
.cb
== pidl
->mkid
.cb
&&
897 !memcmp(entry
->pidl
, pidl
, entry
->pidl
->mkid
.cb
))
904 static Entry
* read_tree_shell(Root
* root
, LPITEMIDLIST pidl
, SORT_ORDER sortOrder
, HWND hwnd
)
906 Entry
* entry
= &root
->entry
;
908 LPITEMIDLIST next_pidl
= pidl
;
909 IShellFolder
* folder
;
910 IShellFolder
* child
= NULL
;
913 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
915 #ifndef _NO_EXTENSIONS
916 entry
->etype
= ET_SHELL
;
919 folder
= Globals
.iDesktop
;
922 entry
->pidl
= next_pidl
;
923 entry
->folder
= folder
;
928 /* copy first element of item idlist */
929 next_pidl
= IMalloc_Alloc(Globals
.iMalloc
, pidl
->mkid
.cb
+sizeof(USHORT
));
930 memcpy(next_pidl
, pidl
, pidl
->mkid
.cb
);
931 ((LPITEMIDLIST
)((LPBYTE
)next_pidl
+pidl
->mkid
.cb
))->mkid
.cb
= 0;
933 hr
= IShellFolder_BindToObject(folder
, next_pidl
, 0, &IID_IShellFolder
, (void**)&child
);
937 read_directory(entry
, NULL
, sortOrder
, hwnd
);
940 entry
->expanded
= TRUE
;
942 next
= find_entry_shell(entry
, next_pidl
);
949 /* go to next element */
950 pidl
= (LPITEMIDLIST
) ((LPBYTE
)pidl
+pidl
->mkid
.cb
);
953 SetCursor(old_cursor
);
959 static void fill_w32fdata_shell(IShellFolder
* folder
, LPCITEMIDLIST pidl
, SFGAOF attribs
, WIN32_FIND_DATA
* w32fdata
)
961 if (!(attribs
& SFGAO_FILESYSTEM
) ||
962 FAILED(SHGetDataFromIDList(folder
, pidl
, SHGDFIL_FINDDATA
, w32fdata
, sizeof(WIN32_FIND_DATA
)))) {
963 WIN32_FILE_ATTRIBUTE_DATA fad
;
964 IDataObject
* pDataObj
;
966 STGMEDIUM medium
= {0, {0}, 0};
967 FORMATETC fmt
= {Globals
.cfStrFName
, 0, DVASPECT_CONTENT
, -1, TYMED_HGLOBAL
};
969 HRESULT hr
= IShellFolder_GetUIObjectOf(folder
, 0, 1, &pidl
, &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
972 hr
= IDataObject_GetData(pDataObj
, &fmt
, &medium
);
974 IDataObject_Release(pDataObj
);
977 LPCTSTR path
= (LPCTSTR
)GlobalLock(medium
.UNION_MEMBER(hGlobal
));
978 UINT sem_org
= SetErrorMode(SEM_FAILCRITICALERRORS
);
980 if (GetFileAttributesEx(path
, GetFileExInfoStandard
, &fad
)) {
981 w32fdata
->dwFileAttributes
= fad
.dwFileAttributes
;
982 w32fdata
->ftCreationTime
= fad
.ftCreationTime
;
983 w32fdata
->ftLastAccessTime
= fad
.ftLastAccessTime
;
984 w32fdata
->ftLastWriteTime
= fad
.ftLastWriteTime
;
986 if (!(fad
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)) {
987 w32fdata
->nFileSizeLow
= fad
.nFileSizeLow
;
988 w32fdata
->nFileSizeHigh
= fad
.nFileSizeHigh
;
992 SetErrorMode(sem_org
);
994 GlobalUnlock(medium
.UNION_MEMBER(hGlobal
));
995 GlobalFree(medium
.UNION_MEMBER(hGlobal
));
1000 if (attribs
& (SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
))
1001 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
1003 if (attribs
& SFGAO_READONLY
)
1004 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_READONLY
;
1006 if (attribs
& SFGAO_COMPRESSED
)
1007 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_COMPRESSED
;
1011 static void read_directory_shell(Entry
* dir
, HWND hwnd
)
1013 IShellFolder
* folder
= dir
->folder
;
1014 int level
= dir
->level
+ 1;
1017 IShellFolder
* child
;
1018 IEnumIDList
* idlist
;
1020 Entry
* first_entry
= NULL
;
1027 hr
= IShellFolder_EnumObjects(folder
, hwnd
, SHCONTF_FOLDERS
|SHCONTF_NONFOLDERS
|SHCONTF_INCLUDEHIDDEN
|SHCONTF_SHAREABLE
|SHCONTF_STORAGE
, &idlist
);
1029 if (SUCCEEDED(hr
)) {
1031 #define FETCH_ITEM_COUNT 32
1032 LPITEMIDLIST pidls
[FETCH_ITEM_COUNT
];
1037 memset(pidls
, 0, sizeof(pidls
));
1039 hr
= IEnumIDList_Next(idlist
, FETCH_ITEM_COUNT
, pidls
, &cnt
);
1046 for(n
=0; n
<cnt
; ++n
) {
1047 entry
= alloc_entry();
1050 first_entry
= entry
;
1055 memset(&entry
->data
, 0, sizeof(WIN32_FIND_DATA
));
1056 entry
->bhfi_valid
= FALSE
;
1058 attribs
= ~SFGAO_FILESYSTEM
; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
1060 hr
= IShellFolder_GetAttributesOf(folder
, 1, (LPCITEMIDLIST
*)&pidls
[n
], &attribs
);
1062 if (SUCCEEDED(hr
)) {
1063 if (attribs
!= (SFGAOF
)~SFGAO_FILESYSTEM
) {
1064 fill_w32fdata_shell(folder
, pidls
[n
], attribs
, &entry
->data
);
1066 entry
->bhfi_valid
= TRUE
;
1072 entry
->pidl
= pidls
[n
];
1074 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1075 hr
= IShellFolder_BindToObject(folder
, pidls
[n
], 0, &IID_IShellFolder
, (void**)&child
);
1078 entry
->folder
= child
;
1080 entry
->folder
= NULL
;
1083 entry
->folder
= NULL
;
1085 if (!entry
->data
.cFileName
[0])
1086 /*hr = */name_from_pidl(folder
, pidls
[n
], entry
->data
.cFileName
, MAX_PATH
, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1088 /* get display icons for files and virtual objects */
1089 if (!(entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ||
1090 !(attribs
& SFGAO_FILESYSTEM
)) {
1091 entry
->hicon
= extract_icon(folder
, pidls
[n
]);
1094 entry
->hicon
= (HICON
)-1; /* don't try again later */
1099 entry
->expanded
= FALSE
;
1100 entry
->scanned
= FALSE
;
1101 entry
->level
= level
;
1103 #ifndef _NO_EXTENSIONS
1104 entry
->etype
= ET_SHELL
;
1105 entry
->bhfi_valid
= FALSE
;
1112 IEnumIDList_Release(idlist
);
1118 dir
->down
= first_entry
;
1119 dir
->scanned
= TRUE
;
1122 #endif /* _SHELL_FOLDERS */
1125 /* sort order for different directory/file types */
1134 /* distinguish between ".", ".." and any other directory names */
1135 static int TypeOrderFromDirname(LPCTSTR name
)
1137 if (name
[0] == '.') {
1138 if (name
[1] == '\0')
1139 return TO_DOT
; /* "." */
1141 if (name
[1]=='.' && name
[2]=='\0')
1142 return TO_DOTDOT
; /* ".." */
1145 return TO_OTHER_DIR
; /* anything else */
1148 /* directories first... */
1149 static int compareType(const WIN32_FIND_DATA
* fd1
, const WIN32_FIND_DATA
* fd2
)
1151 int order1
= fd1
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1152 int order2
= fd2
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1154 /* Handle "." and ".." as special case and move them at the very first beginning. */
1155 if (order1
==TO_DIR
&& order2
==TO_DIR
) {
1156 order1
= TypeOrderFromDirname(fd1
->cFileName
);
1157 order2
= TypeOrderFromDirname(fd2
->cFileName
);
1160 return order2
==order1
? 0: order1
<order2
? -1: 1;
1164 static int compareName(const void* arg1
, const void* arg2
)
1166 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1167 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1169 int cmp
= compareType(fd1
, fd2
);
1173 return lstrcmpi(fd1
->cFileName
, fd2
->cFileName
);
1176 static int compareExt(const void* arg1
, const void* arg2
)
1178 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1179 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1180 const TCHAR
*name1
, *name2
, *ext1
, *ext2
;
1182 int cmp
= compareType(fd1
, fd2
);
1186 name1
= fd1
->cFileName
;
1187 name2
= fd2
->cFileName
;
1189 ext1
= _tcsrchr(name1
, TEXT('.'));
1190 ext2
= _tcsrchr(name2
, TEXT('.'));
1202 cmp
= lstrcmpi(ext1
, ext2
);
1206 return lstrcmpi(name1
, name2
);
1209 static int compareSize(const void* arg1
, const void* arg2
)
1211 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1212 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1214 int cmp
= compareType(fd1
, fd2
);
1218 cmp
= fd2
->nFileSizeHigh
- fd1
->nFileSizeHigh
;
1225 cmp
= fd2
->nFileSizeLow
- fd1
->nFileSizeLow
;
1227 return cmp
<0? -1: cmp
>0? 1: 0;
1230 static int compareDate(const void* arg1
, const void* arg2
)
1232 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1233 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1235 int cmp
= compareType(fd1
, fd2
);
1239 return CompareFileTime(&fd2
->ftLastWriteTime
, &fd1
->ftLastWriteTime
);
1243 static int (*sortFunctions
[])(const void* arg1
, const void* arg2
) = {
1244 compareName
, /* SORT_NAME */
1245 compareExt
, /* SORT_EXT */
1246 compareSize
, /* SORT_SIZE */
1247 compareDate
/* SORT_DATE */
1251 static void SortDirectory(Entry
* dir
, SORT_ORDER sortOrder
)
1253 Entry
* entry
= dir
->down
;
1258 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1262 array
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(Entry
*));
1265 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1268 /* call qsort with the appropriate compare function */
1269 qsort(array
, len
, sizeof(array
[0]), sortFunctions
[sortOrder
]);
1271 dir
->down
= array
[0];
1273 for(p
=array
; --len
; p
++)
1278 HeapFree(GetProcessHeap(), 0, array
);
1283 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
1285 TCHAR buffer
[MAX_PATH
];
1290 #ifdef _SHELL_FOLDERS
1291 if (dir
->etype
== ET_SHELL
)
1293 read_directory_shell(dir
, hwnd
);
1295 if (Globals
.prescan_node
) {
1304 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1305 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1306 read_directory_shell(entry
, hwnd
);
1307 SortDirectory(entry
, sortOrder
);
1313 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1314 if (dir
->etype
== ET_UNIX
)
1316 read_directory_unix(dir
, path
);
1318 if (Globals
.prescan_node
) {
1327 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1328 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1329 lstrcpy(d
, entry
->data
.cFileName
);
1330 read_directory_unix(entry
, buffer
);
1331 SortDirectory(entry
, sortOrder
);
1338 read_directory_win(dir
, path
);
1340 if (Globals
.prescan_node
) {
1349 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1350 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1351 lstrcpy(d
, entry
->data
.cFileName
);
1352 read_directory_win(entry
, buffer
);
1353 SortDirectory(entry
, sortOrder
);
1358 SortDirectory(dir
, sortOrder
);
1362 static Entry
* read_tree(Root
* root
, LPCTSTR path
, LPITEMIDLIST pidl
, LPTSTR drv
, SORT_ORDER sortOrder
, HWND hwnd
)
1364 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1365 static const TCHAR sSlash
[] = {'/', '\0'};
1367 static const TCHAR sBackslash
[] = {'\\', '\0'};
1369 #ifdef _SHELL_FOLDERS
1372 /* read shell namespace tree */
1373 root
->drive_type
= DRIVE_UNKNOWN
;
1376 load_string(root
->volname
, IDS_DESKTOP
);
1378 load_string(root
->fs
, IDS_SHELL
);
1380 return read_tree_shell(root
, pidl
, sortOrder
, hwnd
);
1384 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1387 /* read unix file system tree */
1388 root
->drive_type
= GetDriveType(path
);
1390 lstrcat(drv
, sSlash
);
1391 load_string(root
->volname
, IDS_ROOT_FS
);
1393 load_string(root
->fs
, IDS_UNIXFS
);
1395 lstrcpy(root
->path
, sSlash
);
1397 return read_tree_unix(root
, path
, sortOrder
, hwnd
);
1401 /* read WIN32 file system tree */
1402 root
->drive_type
= GetDriveType(path
);
1404 lstrcat(drv
, sBackslash
);
1405 GetVolumeInformation(drv
, root
->volname
, _MAX_FNAME
, 0, 0, &root
->fs_flags
, root
->fs
, _MAX_DIR
);
1407 lstrcpy(root
->path
, drv
);
1409 return read_tree_win(root
, path
, sortOrder
, hwnd
);
1413 /* flags to filter different file types */
1415 TF_DIRECTORIES
= 0x01,
1417 TF_DOCUMENTS
= 0x04,
1424 static ChildWnd
* alloc_child_window(LPCTSTR path
, LPITEMIDLIST pidl
, HWND hwnd
)
1426 TCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
1427 TCHAR dir_path
[MAX_PATH
];
1428 TCHAR b1
[BUFFER_LEN
];
1429 static const TCHAR sAsterics
[] = {'*', '\0'};
1431 ChildWnd
* child
= (ChildWnd
*) malloc(sizeof(ChildWnd
));
1432 Root
* root
= &child
->root
;
1435 memset(child
, 0, sizeof(ChildWnd
));
1437 child
->left
.treePane
= TRUE
;
1438 child
->left
.visible_cols
= 0;
1440 child
->right
.treePane
= FALSE
;
1441 #ifndef _NO_EXTENSIONS
1442 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_INDEX
|COL_LINKS
;
1444 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
;
1447 child
->pos
.length
= sizeof(WINDOWPLACEMENT
);
1448 child
->pos
.flags
= 0;
1449 child
->pos
.showCmd
= SW_SHOWNORMAL
;
1450 child
->pos
.rcNormalPosition
.left
= CW_USEDEFAULT
;
1451 child
->pos
.rcNormalPosition
.top
= CW_USEDEFAULT
;
1452 child
->pos
.rcNormalPosition
.right
= CW_USEDEFAULT
;
1453 child
->pos
.rcNormalPosition
.bottom
= CW_USEDEFAULT
;
1455 child
->focus_pane
= 0;
1456 child
->split_pos
= DEFAULT_SPLIT_POS
;
1457 child
->sortOrder
= SORT_NAME
;
1458 child
->header_wdths_ok
= FALSE
;
1462 lstrcpy(child
->path
, path
);
1464 _tsplitpath(path
, drv
, dir
, name
, ext
);
1467 lstrcpy(child
->filter_pattern
, sAsterics
);
1468 child
->filter_flags
= TF_ALL
;
1470 root
->entry
.level
= 0;
1472 lstrcpy(dir_path
, drv
);
1473 lstrcat(dir_path
, dir
);
1474 entry
= read_tree(root
, dir_path
, pidl
, drv
, child
->sortOrder
, hwnd
);
1476 #ifdef _SHELL_FOLDERS
1477 if (root
->entry
.etype
== ET_SHELL
)
1478 load_string(root
->entry
.data
.cFileName
, IDS_DESKTOP
);
1481 wsprintf(root
->entry
.data
.cFileName
, RS(b1
,IDS_TITLEFMT
), drv
, root
->fs
);
1483 root
->entry
.data
.dwFileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1485 child
->left
.root
= &root
->entry
;
1486 child
->right
.root
= NULL
;
1488 set_curdir(child
, entry
, 0, hwnd
);
1494 /* free all memory associated with a child window */
1495 static void free_child_window(ChildWnd
* child
)
1497 free_entries(&child
->root
.entry
);
1502 /* get full path of specified directory entry */
1503 static void get_path(Entry
* dir
, PTSTR path
)
1509 #ifdef _SHELL_FOLDERS
1510 if (dir
->etype
== ET_SHELL
)
1515 path
[0] = TEXT('\0');
1520 hr
= IShellFolder_GetAttributesOf(dir
->folder
, 1, (LPCITEMIDLIST
*)&dir
->pidl
, &attribs
);
1522 if (SUCCEEDED(hr
) && (attribs
&SFGAO_FILESYSTEM
)) {
1523 IShellFolder
* parent
= dir
->up
? dir
->up
->folder
: Globals
.iDesktop
;
1525 hr
= path_from_pidl(parent
, dir
->pidl
, path
, MAX_PATH
);
1531 for(entry
=dir
; entry
; level
++) {
1537 name
= entry
->data
.cFileName
;
1540 for(l
=0; *s
&& *s
!=TEXT('/') && *s
!=TEXT('\\'); s
++)
1546 memmove(path
+l
+1, path
, len
*sizeof(TCHAR
));
1547 memcpy(path
+1, name
, l
*sizeof(TCHAR
));
1550 #ifndef _NO_EXTENSIONS
1551 if (entry
->etype
== ET_UNIX
)
1552 path
[0] = TEXT('/');
1555 path
[0] = TEXT('\\');
1560 memmove(path
+l
, path
, len
*sizeof(TCHAR
));
1561 memcpy(path
, name
, l
*sizeof(TCHAR
));
1568 #ifndef _NO_EXTENSIONS
1569 if (entry
->etype
== ET_UNIX
)
1570 path
[len
++] = TEXT('/');
1573 path
[len
++] = TEXT('\\');
1576 path
[len
] = TEXT('\0');
1580 static windowOptions
load_registry_settings(void)
1587 RegOpenKeyEx( HKEY_CURRENT_USER
, registry_key
,
1588 0, KEY_QUERY_VALUE
, &hKey
);
1590 size
= sizeof(DWORD
);
1592 if( RegQueryValueEx( hKey
, reg_start_x
, NULL
, &type
,
1593 (LPBYTE
) &opts
.start_x
, &size
) != ERROR_SUCCESS
)
1594 opts
.start_x
= CW_USEDEFAULT
;
1596 if( RegQueryValueEx( hKey
, reg_start_y
, NULL
, &type
,
1597 (LPBYTE
) &opts
.start_y
, &size
) != ERROR_SUCCESS
)
1598 opts
.start_y
= CW_USEDEFAULT
;
1600 if( RegQueryValueEx( hKey
, reg_width
, NULL
, &type
,
1601 (LPBYTE
) &opts
.width
, &size
) != ERROR_SUCCESS
)
1602 opts
.width
= CW_USEDEFAULT
;
1604 if( RegQueryValueEx( hKey
, reg_height
, NULL
, &type
,
1605 (LPBYTE
) &opts
.height
, &size
) != ERROR_SUCCESS
)
1606 opts
.height
= CW_USEDEFAULT
;
1608 RegCloseKey( hKey
);
1613 static void save_registry_settings(void)
1619 wi
.cbSize
= sizeof( WINDOWINFO
);
1620 GetWindowInfo(Globals
.hMainWnd
, &wi
);
1621 width
= wi
.rcWindow
.right
- wi
.rcWindow
.left
;
1622 height
= wi
.rcWindow
.bottom
- wi
.rcWindow
.top
;
1624 if ( RegOpenKeyEx( HKEY_CURRENT_USER
, registry_key
,
1625 0, KEY_SET_VALUE
, &hKey
) != ERROR_SUCCESS
)
1627 /* Unable to save registry settings - try to create key */
1628 if ( RegCreateKeyEx( HKEY_CURRENT_USER
, registry_key
,
1629 0, NULL
, REG_OPTION_NON_VOLATILE
,
1630 KEY_SET_VALUE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
1632 /* FIXME: Cannot create key */
1636 /* Save all of the settings */
1637 RegSetValueEx( hKey
, reg_start_x
, 0, REG_DWORD
,
1638 (LPBYTE
) &wi
.rcWindow
.left
, sizeof(DWORD
) );
1639 RegSetValueEx( hKey
, reg_start_y
, 0, REG_DWORD
,
1640 (LPBYTE
) &wi
.rcWindow
.top
, sizeof(DWORD
) );
1641 RegSetValueEx( hKey
, reg_width
, 0, REG_DWORD
,
1642 (LPBYTE
) &width
, sizeof(DWORD
) );
1643 RegSetValueEx( hKey
, reg_height
, 0, REG_DWORD
,
1644 (LPBYTE
) &height
, sizeof(DWORD
) );
1646 /* TODO: Save more settings here (List vs. Detailed View, etc.) */
1647 RegCloseKey( hKey
);
1650 static void resize_frame_rect(HWND hwnd
, PRECT prect
)
1655 if (IsWindowVisible(Globals
.htoolbar
)) {
1656 SendMessage(Globals
.htoolbar
, WM_SIZE
, 0, 0);
1657 GetClientRect(Globals
.htoolbar
, &rt
);
1658 prect
->top
= rt
.bottom
+3;
1659 prect
->bottom
-= rt
.bottom
+3;
1662 if (IsWindowVisible(Globals
.hdrivebar
)) {
1663 SendMessage(Globals
.hdrivebar
, WM_SIZE
, 0, 0);
1664 GetClientRect(Globals
.hdrivebar
, &rt
);
1665 new_top
= --prect
->top
+ rt
.bottom
+3;
1666 MoveWindow(Globals
.hdrivebar
, 0, prect
->top
, rt
.right
, new_top
, TRUE
);
1667 prect
->top
= new_top
;
1668 prect
->bottom
-= rt
.bottom
+2;
1671 if (IsWindowVisible(Globals
.hstatusbar
)) {
1672 int parts
[] = {300, 500};
1674 SendMessage(Globals
.hstatusbar
, WM_SIZE
, 0, 0);
1675 SendMessage(Globals
.hstatusbar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
1676 GetClientRect(Globals
.hstatusbar
, &rt
);
1677 prect
->bottom
-= rt
.bottom
;
1680 MoveWindow(Globals
.hmdiclient
, prect
->left
-1,prect
->top
-1,prect
->right
+2,prect
->bottom
+1, TRUE
);
1683 static void resize_frame(HWND hwnd
, int cx
, int cy
)
1692 resize_frame_rect(hwnd
, &rect
);
1695 static void resize_frame_client(HWND hwnd
)
1699 GetClientRect(hwnd
, &rect
);
1701 resize_frame_rect(hwnd
, &rect
);
1705 static HHOOK hcbthook
;
1706 static ChildWnd
* newchild
= NULL
;
1708 static LRESULT CALLBACK
CBTProc(int code
, WPARAM wparam
, LPARAM lparam
)
1710 if (code
==HCBT_CREATEWND
&& newchild
) {
1711 ChildWnd
* child
= newchild
;
1714 child
->hwnd
= (HWND
) wparam
;
1715 SetWindowLongPtr(child
->hwnd
, GWLP_USERDATA
, (LPARAM
)child
);
1718 return CallNextHookEx(hcbthook
, code
, wparam
, lparam
);
1721 static HWND
create_child_window(ChildWnd
* child
)
1723 MDICREATESTRUCT mcs
;
1726 mcs
.szClass
= sWINEFILETREE
;
1727 mcs
.szTitle
= (LPTSTR
)child
->path
;
1728 mcs
.hOwner
= Globals
.hInstance
;
1729 mcs
.x
= child
->pos
.rcNormalPosition
.left
;
1730 mcs
.y
= child
->pos
.rcNormalPosition
.top
;
1731 mcs
.cx
= child
->pos
.rcNormalPosition
.right
-child
->pos
.rcNormalPosition
.left
;
1732 mcs
.cy
= child
->pos
.rcNormalPosition
.bottom
-child
->pos
.rcNormalPosition
.top
;
1736 hcbthook
= SetWindowsHookEx(WH_CBT
, CBTProc
, 0, GetCurrentThreadId());
1739 child
->hwnd
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDICREATE
, 0, (LPARAM
)&mcs
);
1741 UnhookWindowsHookEx(hcbthook
);
1745 UnhookWindowsHookEx(hcbthook
);
1747 ListBox_SetItemHeight(child
->left
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1748 ListBox_SetItemHeight(child
->right
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1750 idx
= ListBox_FindItemData(child
->left
.hwnd
, 0, child
->left
.cur
);
1751 ListBox_SetCurSel(child
->left
.hwnd
, idx
);
1757 struct ExecuteDialog
{
1758 TCHAR cmd
[MAX_PATH
];
1762 static INT_PTR CALLBACK
ExecuteDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1764 static struct ExecuteDialog
* dlg
;
1768 dlg
= (struct ExecuteDialog
*) lparam
;
1772 int id
= (int)wparam
;
1775 GetWindowText(GetDlgItem(hwnd
, 201), dlg
->cmd
, MAX_PATH
);
1776 dlg
->cmdshow
= Button_GetState(GetDlgItem(hwnd
,214))&BST_CHECKED
?
1777 SW_SHOWMINIMIZED
: SW_SHOWNORMAL
;
1778 EndDialog(hwnd
, id
);
1779 } else if (id
== IDCANCEL
)
1780 EndDialog(hwnd
, id
);
1789 static INT_PTR CALLBACK
DestinationDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1791 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1795 SetWindowLongPtr(hwnd
, GWLP_USERDATA
, lparam
);
1796 SetWindowText(GetDlgItem(hwnd
, 201), (LPCTSTR
)lparam
);
1800 int id
= (int)wparam
;
1804 LPTSTR dest
= (LPTSTR
) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
1805 GetWindowText(GetDlgItem(hwnd
, 201), dest
, MAX_PATH
);
1806 EndDialog(hwnd
, id
);
1810 EndDialog(hwnd
, id
);
1814 MessageBox(hwnd
, RS(b1
,IDS_NO_IMPL
), RS(b2
,IDS_WINEFILE
), MB_OK
);
1826 struct FilterDialog
{
1827 TCHAR pattern
[MAX_PATH
];
1831 static INT_PTR CALLBACK
FilterDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1833 static struct FilterDialog
* dlg
;
1837 dlg
= (struct FilterDialog
*) lparam
;
1838 SetWindowText(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
);
1839 Button_SetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_DIRECTORIES
), (dlg
->flags
&TF_DIRECTORIES
? BST_CHECKED
: BST_UNCHECKED
));
1840 Button_SetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_PROGRAMS
), dlg
->flags
&TF_PROGRAMS
? BST_CHECKED
: BST_UNCHECKED
);
1841 Button_SetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_DOCUMENTS
), dlg
->flags
&TF_DOCUMENTS
? BST_CHECKED
: BST_UNCHECKED
);
1842 Button_SetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_OTHERS
), dlg
->flags
&TF_OTHERS
? BST_CHECKED
: BST_UNCHECKED
);
1843 Button_SetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_HIDDEN
), dlg
->flags
&TF_HIDDEN
? BST_CHECKED
: BST_UNCHECKED
);
1847 int id
= (int)wparam
;
1852 GetWindowText(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
, MAX_PATH
);
1854 flags
|= Button_GetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_DIRECTORIES
))&BST_CHECKED
? TF_DIRECTORIES
: 0;
1855 flags
|= Button_GetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_PROGRAMS
))&BST_CHECKED
? TF_PROGRAMS
: 0;
1856 flags
|= Button_GetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_DOCUMENTS
))&BST_CHECKED
? TF_DOCUMENTS
: 0;
1857 flags
|= Button_GetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_OTHERS
))&BST_CHECKED
? TF_OTHERS
: 0;
1858 flags
|= Button_GetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_HIDDEN
))&BST_CHECKED
? TF_HIDDEN
: 0;
1862 EndDialog(hwnd
, id
);
1863 } else if (id
== IDCANCEL
)
1864 EndDialog(hwnd
, id
);
1873 struct PropertiesDialog
{
1874 TCHAR path
[MAX_PATH
];
1879 /* Structure used to store enumerated languages and code pages. */
1880 struct LANGANDCODEPAGE
{
1885 static LPCSTR InfoStrings
[] = {
1901 static void PropDlg_DisplayValue(HWND hlbox
, HWND hedit
)
1903 int idx
= ListBox_GetCurSel(hlbox
);
1905 if (idx
!= LB_ERR
) {
1906 LPCTSTR pValue
= (LPCTSTR
) ListBox_GetItemData(hlbox
, idx
);
1909 SetWindowText(hedit
, pValue
);
1913 static void CheckForFileInfo(struct PropertiesDialog
* dlg
, HWND hwnd
, LPCTSTR strFilename
)
1915 static TCHAR sBackSlash
[] = {'\\','\0'};
1916 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'};
1917 static TCHAR sStringFileInfo
[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1918 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1919 DWORD dwVersionDataLen
= GetFileVersionInfoSize(strFilename
, NULL
);
1921 if (dwVersionDataLen
) {
1922 dlg
->pVersionData
= malloc(dwVersionDataLen
);
1924 if (GetFileVersionInfo(strFilename
, 0, dwVersionDataLen
, dlg
->pVersionData
)) {
1928 if (VerQueryValue(dlg
->pVersionData
, sBackSlash
, &pVal
, &nValLen
)) {
1929 if (nValLen
== sizeof(VS_FIXEDFILEINFO
)) {
1930 VS_FIXEDFILEINFO
* pFixedFileInfo
= (VS_FIXEDFILEINFO
*)pVal
;
1931 char buffer
[BUFFER_LEN
];
1933 sprintf(buffer
, "%d.%d.%d.%d",
1934 HIWORD(pFixedFileInfo
->dwFileVersionMS
), LOWORD(pFixedFileInfo
->dwFileVersionMS
),
1935 HIWORD(pFixedFileInfo
->dwFileVersionLS
), LOWORD(pFixedFileInfo
->dwFileVersionLS
));
1937 SetDlgItemTextA(hwnd
, IDC_STATIC_PROP_VERSION
, buffer
);
1941 /* Read the list of languages and code pages. */
1942 if (VerQueryValue(dlg
->pVersionData
, sTranslation
, &pVal
, &nValLen
)) {
1943 struct LANGANDCODEPAGE
* pTranslate
= (struct LANGANDCODEPAGE
*)pVal
;
1944 struct LANGANDCODEPAGE
* pEnd
= (struct LANGANDCODEPAGE
*)((LPBYTE
)pVal
+nValLen
);
1946 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
1948 /* Read the file description for each language and code page. */
1949 for(; pTranslate
<pEnd
; ++pTranslate
) {
1952 for(p
=InfoStrings
; *p
; ++p
) {
1953 TCHAR subblock
[200];
1960 LPCSTR pInfoString
= *p
;
1962 MultiByteToWideChar(CP_ACP
, 0, pInfoString
, -1, infoStr
, 100);
1964 #define infoStr pInfoString
1966 wsprintf(subblock
, sStringFileInfo
, pTranslate
->wLanguage
, pTranslate
->wCodePage
, infoStr
);
1968 /* Retrieve file description for language and code page */
1969 if (VerQueryValue(dlg
->pVersionData
, subblock
, (PVOID
)&pTxt
, &nValLen
)) {
1970 int idx
= ListBox_AddString(hlbox
, infoStr
);
1971 ListBox_SetItemData(hlbox
, idx
, pTxt
);
1976 ListBox_SetCurSel(hlbox
, 0);
1978 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
1984 static INT_PTR CALLBACK
PropertiesDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1986 static struct PropertiesDialog
* dlg
;
1989 case WM_INITDIALOG
: {
1990 static const TCHAR sByteFmt
[] = {'%','s',' ','B','y','t','e','s','\0'};
1991 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1992 LPWIN32_FIND_DATA pWFD
;
1995 dlg
= (struct PropertiesDialog
*) lparam
;
1996 pWFD
= (LPWIN32_FIND_DATA
) &dlg
->entry
.data
;
1998 GetWindowText(hwnd
, b1
, MAX_PATH
);
1999 wsprintf(b2
, b1
, pWFD
->cFileName
);
2000 SetWindowText(hwnd
, b2
);
2002 format_date(&pWFD
->ftLastWriteTime
, b1
, COL_DATE
|COL_TIME
);
2003 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_LASTCHANGE
), b1
);
2005 size
= ((ULONGLONG
)pWFD
->nFileSizeHigh
<< 32) | pWFD
->nFileSizeLow
;
2006 _stprintf(b1
, sLongNumFmt
, size
);
2007 wsprintf(b2
, sByteFmt
, b1
);
2008 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_SIZE
), b2
);
2010 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_FILENAME
), pWFD
->cFileName
);
2011 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_PATH
), dlg
->path
);
2013 Button_SetCheck(GetDlgItem(hwnd
,IDC_CHECK_READONLY
), (pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_READONLY
? BST_CHECKED
: BST_UNCHECKED
));
2014 Button_SetCheck(GetDlgItem(hwnd
,IDC_CHECK_ARCHIVE
), (pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_ARCHIVE
? BST_CHECKED
: BST_UNCHECKED
));
2015 Button_SetCheck(GetDlgItem(hwnd
,IDC_CHECK_COMPRESSED
), (pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_COMPRESSED
? BST_CHECKED
: BST_UNCHECKED
));
2016 Button_SetCheck(GetDlgItem(hwnd
,IDC_CHECK_HIDDEN
), (pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_HIDDEN
? BST_CHECKED
: BST_UNCHECKED
));
2017 Button_SetCheck(GetDlgItem(hwnd
,IDC_CHECK_SYSTEM
), (pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_SYSTEM
? BST_CHECKED
: BST_UNCHECKED
));
2019 CheckForFileInfo(dlg
, hwnd
, dlg
->path
);
2023 int id
= (int)wparam
;
2025 switch(HIWORD(wparam
)) {
2026 case LBN_SELCHANGE
: {
2027 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
2028 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
2033 if (id
==IDOK
|| id
==IDCANCEL
)
2034 EndDialog(hwnd
, id
);
2040 free(dlg
->pVersionData
);
2041 dlg
->pVersionData
= NULL
;
2048 static void show_properties_dlg(Entry
* entry
, HWND hwnd
)
2050 struct PropertiesDialog dlg
;
2052 memset(&dlg
, 0, sizeof(struct PropertiesDialog
));
2053 get_path(entry
, dlg
.path
);
2054 memcpy(&dlg
.entry
, entry
, sizeof(Entry
));
2056 DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_DIALOG_PROPERTIES
), hwnd
, PropertiesDialogDlgProc
, (LPARAM
)&dlg
);
2060 #ifndef _NO_EXTENSIONS
2062 static struct FullScreenParameters
{
2072 static void frame_get_clientspace(HWND hwnd
, PRECT prect
)
2076 if (!IsIconic(hwnd
))
2077 GetClientRect(hwnd
, prect
);
2081 GetWindowPlacement(hwnd
, &wp
);
2083 prect
->left
= prect
->top
= 0;
2084 prect
->right
= wp
.rcNormalPosition
.right
-wp
.rcNormalPosition
.left
-
2085 2*(GetSystemMetrics(SM_CXSIZEFRAME
)+GetSystemMetrics(SM_CXEDGE
));
2086 prect
->bottom
= wp
.rcNormalPosition
.bottom
-wp
.rcNormalPosition
.top
-
2087 2*(GetSystemMetrics(SM_CYSIZEFRAME
)+GetSystemMetrics(SM_CYEDGE
))-
2088 GetSystemMetrics(SM_CYCAPTION
)-GetSystemMetrics(SM_CYMENUSIZE
);
2091 if (IsWindowVisible(Globals
.htoolbar
)) {
2092 GetClientRect(Globals
.htoolbar
, &rt
);
2093 prect
->top
+= rt
.bottom
+2;
2096 if (IsWindowVisible(Globals
.hdrivebar
)) {
2097 GetClientRect(Globals
.hdrivebar
, &rt
);
2098 prect
->top
+= rt
.bottom
+2;
2101 if (IsWindowVisible(Globals
.hstatusbar
)) {
2102 GetClientRect(Globals
.hstatusbar
, &rt
);
2103 prect
->bottom
-= rt
.bottom
;
2107 static BOOL
toggle_fullscreen(HWND hwnd
)
2111 if ((g_fullscreen
.mode
=!g_fullscreen
.mode
)) {
2112 GetWindowRect(hwnd
, &g_fullscreen
.orgPos
);
2113 g_fullscreen
.wasZoomed
= IsZoomed(hwnd
);
2115 Frame_CalcFrameClient(hwnd
, &rt
);
2116 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
2117 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
2119 rt
.left
= g_fullscreen
.orgPos
.left
-rt
.left
;
2120 rt
.top
= g_fullscreen
.orgPos
.top
-rt
.top
;
2121 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+g_fullscreen
.orgPos
.right
-rt
.right
;
2122 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+g_fullscreen
.orgPos
.bottom
-rt
.bottom
;
2124 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
2126 MoveWindow(hwnd
, g_fullscreen
.orgPos
.left
, g_fullscreen
.orgPos
.top
,
2127 g_fullscreen
.orgPos
.right
-g_fullscreen
.orgPos
.left
,
2128 g_fullscreen
.orgPos
.bottom
-g_fullscreen
.orgPos
.top
, TRUE
);
2130 if (g_fullscreen
.wasZoomed
)
2131 ShowWindow(hwnd
, WS_MAXIMIZE
);
2134 return g_fullscreen
.mode
;
2137 static void fullscreen_move(HWND hwnd
)
2140 GetWindowRect(hwnd
, &pos
);
2142 Frame_CalcFrameClient(hwnd
, &rt
);
2143 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
2144 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
2146 rt
.left
= pos
.left
-rt
.left
;
2147 rt
.top
= pos
.top
-rt
.top
;
2148 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+pos
.right
-rt
.right
;
2149 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+pos
.bottom
-rt
.bottom
;
2151 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
2157 static void toggle_child(HWND hwnd
, UINT cmd
, HWND hchild
)
2159 BOOL vis
= IsWindowVisible(hchild
);
2161 CheckMenuItem(Globals
.hMenuOptions
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
2163 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
2165 #ifndef _NO_EXTENSIONS
2166 if (g_fullscreen
.mode
)
2167 fullscreen_move(hwnd
);
2170 resize_frame_client(hwnd
);
2173 static BOOL
activate_drive_window(LPCTSTR path
)
2175 TCHAR drv1
[_MAX_DRIVE
], drv2
[_MAX_DRIVE
];
2178 _tsplitpath(path
, drv1
, 0, 0, 0);
2180 /* search for a already open window for the same drive */
2181 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2182 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(child_wnd
, GWLP_USERDATA
);
2185 _tsplitpath(child
->root
.path
, drv2
, 0, 0, 0);
2187 if (!lstrcmpi(drv2
, drv1
)) {
2188 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2190 if (IsMinimized(child_wnd
))
2191 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2201 static BOOL
activate_fs_window(LPCTSTR filesys
)
2205 /* search for a already open window of the given file system name */
2206 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2207 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(child_wnd
, GWLP_USERDATA
);
2210 if (!lstrcmpi(child
->root
.fs
, filesys
)) {
2211 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2213 if (IsMinimized(child_wnd
))
2214 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2224 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
2226 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2230 if (Globals
.saveSettings
== TRUE
)
2231 save_registry_settings();
2233 DestroyWindow(hwnd
);
2235 /* clear handle variables */
2236 Globals
.hMenuFrame
= 0;
2237 Globals
.hMenuView
= 0;
2238 Globals
.hMenuOptions
= 0;
2239 Globals
.hMainWnd
= 0;
2240 Globals
.hmdiclient
= 0;
2241 Globals
.hdrivebar
= 0;
2248 case WM_INITMENUPOPUP
: {
2249 HWND hwndClient
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2251 if (!SendMessage(hwndClient
, WM_INITMENUPOPUP
, wparam
, lparam
))
2256 UINT cmd
= LOWORD(wparam
);
2257 HWND hwndClient
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2259 if (SendMessage(hwndClient
, WM_DISPATCH_COMMAND
, wparam
, lparam
))
2262 if (cmd
>=ID_DRIVE_FIRST
&& cmd
<=ID_DRIVE_FIRST
+0xFF) {
2263 TCHAR drv
[_MAX_DRIVE
], path
[MAX_PATH
];
2265 LPCTSTR root
= Globals
.drives
;
2268 for(i
=cmd
-ID_DRIVE_FIRST
; i
--; root
++)
2272 if (activate_drive_window(root
))
2275 _tsplitpath(root
, drv
, 0, 0, 0);
2277 if (!SetCurrentDirectory(drv
)) {
2278 display_error(hwnd
, GetLastError());
2282 GetCurrentDirectory(MAX_PATH
, path
); /*TODO: store last directory per drive */
2283 child
= alloc_child_window(path
, NULL
, hwnd
);
2285 if (!create_child_window(child
))
2287 } else switch(cmd
) {
2289 SendMessage(hwnd
, WM_CLOSE
, 0, 0);
2292 case ID_WINDOW_NEW
: {
2293 TCHAR path
[MAX_PATH
];
2296 GetCurrentDirectory(MAX_PATH
, path
);
2297 child
= alloc_child_window(path
, NULL
, hwnd
);
2299 if (!create_child_window(child
))
2307 case ID_WINDOW_CASCADE
:
2308 SendMessage(Globals
.hmdiclient
, WM_MDICASCADE
, 0, 0);
2311 case ID_WINDOW_TILE_HORZ
:
2312 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
2315 case ID_WINDOW_TILE_VERT
:
2316 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
2319 case ID_WINDOW_ARRANGE
:
2320 SendMessage(Globals
.hmdiclient
, WM_MDIICONARRANGE
, 0, 0);
2323 case ID_SELECT_FONT
: {
2324 TCHAR dlg_name
[BUFFER_LEN
], dlg_info
[BUFFER_LEN
];
2328 HDC hdc
= GetDC(hwnd
);
2329 chFont
.lStructSize
= sizeof(CHOOSEFONT
);
2330 chFont
.hwndOwner
= hwnd
;
2332 chFont
.lpLogFont
= &lFont
;
2333 chFont
.Flags
= CF_SCREENFONTS
| CF_FORCEFONTEXIST
| CF_LIMITSIZE
| CF_NOSCRIPTSEL
;
2334 chFont
.rgbColors
= RGB(0,0,0);
2335 chFont
.lCustData
= 0;
2336 chFont
.lpfnHook
= NULL
;
2337 chFont
.lpTemplateName
= NULL
;
2338 chFont
.hInstance
= Globals
.hInstance
;
2339 chFont
.lpszStyle
= NULL
;
2340 chFont
.nFontType
= SIMULATED_FONTTYPE
;
2341 chFont
.nSizeMin
= 0;
2342 chFont
.nSizeMax
= 24;
2344 if (ChooseFont(&chFont
)) {
2348 DeleteObject(Globals
.hfont
);
2349 Globals
.hfont
= CreateFontIndirect(&lFont
);
2350 hFontOld
= SelectFont(hdc
, Globals
.hfont
);
2351 GetTextExtentPoint32(hdc
, sSpace
, 1, &Globals
.spaceSize
);
2353 /* change font in all open child windows */
2354 for(childWnd
=GetWindow(Globals
.hmdiclient
,GW_CHILD
); childWnd
; childWnd
=GetNextWindow(childWnd
,GW_HWNDNEXT
)) {
2355 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(childWnd
, GWLP_USERDATA
);
2356 SetWindowFont(child
->left
.hwnd
, Globals
.hfont
, TRUE
);
2357 SetWindowFont(child
->right
.hwnd
, Globals
.hfont
, TRUE
);
2358 ListBox_SetItemHeight(child
->left
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
2359 ListBox_SetItemHeight(child
->right
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
2360 InvalidateRect(child
->left
.hwnd
, NULL
, TRUE
);
2361 InvalidateRect(child
->right
.hwnd
, NULL
, TRUE
);
2364 SelectFont(hdc
, hFontOld
);
2366 else if (CommDlgExtendedError()) {
2367 LoadString(Globals
.hInstance
, IDS_FONT_SEL_DLG_NAME
, dlg_name
, BUFFER_LEN
);
2368 LoadString(Globals
.hInstance
, IDS_FONT_SEL_ERROR
, dlg_info
, BUFFER_LEN
);
2369 MessageBox(hwnd
, dlg_info
, dlg_name
, MB_OK
);
2372 ReleaseDC(hwnd
, hdc
);
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
== TRUE
? 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 ((int)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
))
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
))
2487 /*TODO: There are even more menu items! */
2489 #ifndef _NO_EXTENSIONS
2492 WineLicense(Globals
.hMainWnd
);
2495 case ID_NO_WARRANTY
:
2496 WineWarranty(Globals
.hMainWnd
);
2500 ShellAbout(hwnd
, RS(b2
,IDS_WINE
), RS(b1
,IDS_WINEFILE
), 0);
2505 ShellAbout(hwnd
, RS(b1
,IDS_WINEFILE
), NULL
, 0);
2507 #endif /* _NO_EXTENSIONS */
2510 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2511 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2512 else */if ((cmd
<IDW_FIRST_CHILD
|| cmd
>=IDW_FIRST_CHILD
+0x100) &&
2513 (cmd
<SC_SIZE
|| cmd
>SC_RESTORE
))
2514 MessageBox(hwnd
, RS(b2
,IDS_NO_IMPL
), RS(b1
,IDS_WINEFILE
), MB_OK
);
2516 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2521 resize_frame(hwnd
, LOWORD(lparam
), HIWORD(lparam
));
2522 break; /* do not pass message to DefFrameProc */
2524 #ifndef _NO_EXTENSIONS
2525 case WM_GETMINMAXINFO
: {
2526 LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
2528 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2529 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2532 case FRM_CALC_CLIENT
:
2533 frame_get_clientspace(hwnd
, (PRECT
)lparam
);
2535 #endif /* _NO_EXTENSIONS */
2538 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2545 static TCHAR g_pos_names
[COLUMNS
][20] = {
2549 static const int g_pos_align
[] = {
2551 HDF_LEFT
, /* Name */
2552 HDF_RIGHT
, /* Size */
2553 HDF_LEFT
, /* CDate */
2554 #ifndef _NO_EXTENSIONS
2555 HDF_LEFT
, /* ADate */
2556 HDF_LEFT
, /* MDate */
2557 HDF_LEFT
, /* Index */
2558 HDF_CENTER
, /* Links */
2560 HDF_CENTER
, /* Attributes */
2561 #ifndef _NO_EXTENSIONS
2562 HDF_LEFT
/* Security */
2566 static void resize_tree(ChildWnd
* child
, int cx
, int cy
)
2568 HDWP hdwp
= BeginDeferWindowPos(4);
2576 cx
= child
->split_pos
+ SPLIT_WIDTH
/2;
2578 #ifndef _NO_EXTENSIONS
2586 Header_Layout(child
->left
.hwndHeader
, &hdl
);
2588 DeferWindowPos(hdwp
, child
->left
.hwndHeader
, wp
.hwndInsertAfter
,
2589 wp
.x
-1, wp
.y
, child
->split_pos
-SPLIT_WIDTH
/2+1, wp
.cy
, wp
.flags
);
2590 DeferWindowPos(hdwp
, child
->right
.hwndHeader
, wp
.hwndInsertAfter
,
2591 rt
.left
+cx
+1, wp
.y
, wp
.cx
-cx
+2, wp
.cy
, wp
.flags
);
2593 #endif /* _NO_EXTENSIONS */
2595 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
);
2596 DeferWindowPos(hdwp
, child
->right
.hwnd
, 0, rt
.left
+cx
+1, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
2598 EndDeferWindowPos(hdwp
);
2602 #ifndef _NO_EXTENSIONS
2604 static HWND
create_header(HWND parent
, Pane
* pane
, int id
)
2609 HWND hwnd
= CreateWindow(WC_HEADER
, 0, WS_CHILD
|WS_VISIBLE
|HDS_HORZ
/*TODO: |HDS_BUTTONS + sort orders*/,
2610 0, 0, 0, 0, parent
, (HMENU
)id
, Globals
.hInstance
, 0);
2614 SetWindowFont(hwnd
, GetStockObject(DEFAULT_GUI_FONT
), FALSE
);
2616 hdi
.mask
= HDI_TEXT
|HDI_WIDTH
|HDI_FORMAT
;
2618 for(idx
=0; idx
<COLUMNS
; idx
++) {
2619 hdi
.pszText
= g_pos_names
[idx
];
2620 hdi
.fmt
= HDF_STRING
| g_pos_align
[idx
];
2621 hdi
.cxy
= pane
->widths
[idx
];
2622 Header_InsertItem(hwnd
, idx
, &hdi
);
2628 #endif /* _NO_EXTENSIONS */
2631 static void init_output(HWND hwnd
)
2633 static const TCHAR s1000
[] = {'1','0','0','0','\0'};
2637 HDC hdc
= GetDC(hwnd
);
2639 if (GetNumberFormat(LOCALE_USER_DEFAULT
, 0, s1000
, 0, b
, 16) > 4)
2640 Globals
.num_sep
= b
[1];
2642 Globals
.num_sep
= TEXT('.');
2644 old_font
= SelectFont(hdc
, Globals
.hfont
);
2645 GetTextExtentPoint32(hdc
, sSpace
, 1, &Globals
.spaceSize
);
2646 SelectFont(hdc
, old_font
);
2647 ReleaseDC(hwnd
, hdc
);
2650 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
);
2653 /* calculate preferred width for all visible columns */
2655 static BOOL
calc_widths(Pane
* pane
, BOOL anyway
)
2657 int col
, x
, cx
, spc
=3*Globals
.spaceSize
.cx
;
2658 int entries
= ListBox_GetCount(pane
->hwnd
);
2659 int orgWidths
[COLUMNS
];
2660 int orgPositions
[COLUMNS
+1];
2666 memcpy(orgWidths
, pane
->widths
, sizeof(orgWidths
));
2667 memcpy(orgPositions
, pane
->positions
, sizeof(orgPositions
));
2670 for(col
=0; col
<COLUMNS
; col
++)
2671 pane
->widths
[col
] = 0;
2673 hdc
= GetDC(pane
->hwnd
);
2674 hfontOld
= SelectFont(hdc
, Globals
.hfont
);
2676 for(cnt
=0; cnt
<entries
; cnt
++) {
2677 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, cnt
);
2686 dis
.hwndItem
= pane
->hwnd
;
2688 dis
.rcItem
.left
= 0;
2690 dis
.rcItem
.right
= 0;
2691 dis
.rcItem
.bottom
= 0;
2692 /*dis.itemData = 0; */
2694 draw_item(pane
, &dis
, entry
, COLUMNS
);
2697 SelectObject(hdc
, hfontOld
);
2698 ReleaseDC(pane
->hwnd
, hdc
);
2701 for(col
=0; col
<COLUMNS
; col
++) {
2702 pane
->positions
[col
] = x
;
2703 cx
= pane
->widths
[col
];
2708 if (cx
< IMAGE_WIDTH
)
2711 pane
->widths
[col
] = cx
;
2717 pane
->positions
[COLUMNS
] = x
;
2719 ListBox_SetHorizontalExtent(pane
->hwnd
, x
);
2722 if (!memcmp(orgWidths
, pane
->widths
, sizeof(orgWidths
)))
2725 /* don't move, if only collapsing an entry */
2726 if (!anyway
&& pane
->widths
[0]<orgWidths
[0] &&
2727 !memcmp(orgWidths
+1, pane
->widths
+1, sizeof(orgWidths
)-sizeof(int))) {
2728 pane
->widths
[0] = orgWidths
[0];
2729 memcpy(pane
->positions
, orgPositions
, sizeof(orgPositions
));
2734 InvalidateRect(pane
->hwnd
, 0, TRUE
);
2740 /* calculate one preferred column width */
2742 static void calc_single_width(Pane
* pane
, int col
)
2746 int entries
= ListBox_GetCount(pane
->hwnd
);
2750 pane
->widths
[col
] = 0;
2752 hdc
= GetDC(pane
->hwnd
);
2753 hfontOld
= SelectFont(hdc
, Globals
.hfont
);
2755 for(cnt
=0; cnt
<entries
; cnt
++) {
2756 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, cnt
);
2764 dis
.hwndItem
= pane
->hwnd
;
2766 dis
.rcItem
.left
= 0;
2768 dis
.rcItem
.right
= 0;
2769 dis
.rcItem
.bottom
= 0;
2770 /*dis.itemData = 0; */
2772 draw_item(pane
, &dis
, entry
, col
);
2775 SelectObject(hdc
, hfontOld
);
2776 ReleaseDC(pane
->hwnd
, hdc
);
2778 cx
= pane
->widths
[col
];
2781 cx
+= 3*Globals
.spaceSize
.cx
;
2783 if (cx
< IMAGE_WIDTH
)
2787 pane
->widths
[col
] = cx
;
2789 x
= pane
->positions
[col
] + cx
;
2791 for(; col
<COLUMNS
; ) {
2792 pane
->positions
[++col
] = x
;
2793 x
+= pane
->widths
[col
];
2796 ListBox_SetHorizontalExtent(pane
->hwnd
, x
);
2800 static BOOL
pattern_match(LPCTSTR str
, LPCTSTR pattern
)
2802 for( ; *str
&&*pattern
; str
++,pattern
++) {
2803 if (*pattern
== '*') {
2805 while(*pattern
== '*');
2811 if (*str
==*pattern
&& pattern_match(str
, pattern
))
2816 else if (*str
!=*pattern
&& *pattern
!='?')
2820 if (*str
|| *pattern
)
2821 if (*pattern
!='*' || pattern
[1]!='\0')
2827 static BOOL
pattern_imatch(LPCTSTR str
, LPCTSTR pattern
)
2829 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2832 lstrcpy(b2
, pattern
);
2836 return pattern_match(b1
, b2
);
2846 static enum FILE_TYPE
get_file_type(LPCTSTR filename
);
2849 /* insert listbox entries after index idx */
2851 static int insert_entries(Pane
* pane
, Entry
* dir
, LPCTSTR pattern
, int filter_flags
, int idx
)
2858 ShowWindow(pane
->hwnd
, SW_HIDE
);
2860 for(; entry
; entry
=entry
->next
) {
2862 if (pane
->treePane
&& !(entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
2866 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
2867 /* don't display entries "." and ".." in the left pane */
2868 if (pane
->treePane
&& entry
->data
.cFileName
[0]==TEXT('.'))
2870 #ifndef _NO_EXTENSIONS
2871 entry
->data
.cFileName
[1]==TEXT('\0') ||
2873 (entry
->data
.cFileName
[1]==TEXT('.') && entry
->data
.cFileName
[2]==TEXT('\0')))
2876 /* filter directories in right pane */
2877 if (!pane
->treePane
&& !(filter_flags
&TF_DIRECTORIES
))
2881 /* filter using the file name pattern */
2883 if (!pattern_imatch(entry
->data
.cFileName
, pattern
))
2886 /* filter system and hidden files */
2887 if (!(filter_flags
&TF_HIDDEN
) && (entry
->data
.dwFileAttributes
&(FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
)))
2890 /* filter looking at the file type */
2891 if ((filter_flags
&(TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
)) != (TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
))
2892 switch(get_file_type(entry
->data
.cFileName
)) {
2894 if (!(filter_flags
& TF_PROGRAMS
))
2899 if (!(filter_flags
& TF_DOCUMENTS
))
2903 default: /* TF_OTHERS */
2904 if (!(filter_flags
& TF_OTHERS
))
2911 ListBox_InsertItemData(pane
->hwnd
, idx
, entry
);
2913 if (pane
->treePane
&& entry
->expanded
)
2914 idx
= insert_entries(pane
, entry
->down
, pattern
, filter_flags
, idx
);
2917 ShowWindow(pane
->hwnd
, SW_SHOW
);
2923 static void format_bytes(LPTSTR buffer
, LONGLONG bytes
)
2925 static const TCHAR sFmtGB
[] = {'%', '.', '1', 'f', ' ', 'G', 'B', '\0'};
2926 static const TCHAR sFmtMB
[] = {'%', '.', '1', 'f', ' ', 'M', 'B', '\0'};
2927 static const TCHAR sFmtkB
[] = {'%', '.', '1', 'f', ' ', 'k', 'B', '\0'};
2929 float fBytes
= (float)bytes
;
2931 if (bytes
>= 1073741824) /* 1 GB */
2932 wsprintf(buffer
, sFmtGB
, fBytes
/1073741824.f
+.5f
);
2933 else if (bytes
>= 1048576) /* 1 MB */
2934 wsprintf(buffer
, sFmtMB
, fBytes
/1048576.f
+.5f
);
2935 else if (bytes
>= 1024) /* 1 kB */
2936 wsprintf(buffer
, sFmtkB
, fBytes
/1024.f
+.5f
);
2938 _stprintf(buffer
, sLongNumFmt
, bytes
);
2941 static void set_space_status(void)
2943 ULARGE_INTEGER ulFreeBytesToCaller
, ulTotalBytes
, ulFreeBytes
;
2944 TCHAR fmt
[64], b1
[64], b2
[64], buffer
[BUFFER_LEN
];
2946 if (GetDiskFreeSpaceEx(NULL
, &ulFreeBytesToCaller
, &ulTotalBytes
, &ulFreeBytes
)) {
2947 format_bytes(b1
, ulFreeBytesToCaller
.QuadPart
);
2948 format_bytes(b2
, ulTotalBytes
.QuadPart
);
2949 wsprintf(buffer
, RS(fmt
,IDS_FREE_SPACE_FMT
), b1
, b2
);
2951 lstrcpy(buffer
, sQMarks
);
2953 SendMessage(Globals
.hstatusbar
, SB_SETTEXT
, 0, (LPARAM
)buffer
);
2957 static WNDPROC g_orgTreeWndProc
;
2959 static void create_tree_window(HWND parent
, Pane
* pane
, int id
, int id_header
, LPCTSTR pattern
, int filter_flags
)
2961 static const TCHAR sListBox
[] = {'L','i','s','t','B','o','x','\0'};
2963 static int s_init
= 0;
2964 Entry
* entry
= pane
->root
;
2966 pane
->hwnd
= CreateWindow(sListBox
, sEmpty
, WS_CHILD
|WS_VISIBLE
|WS_HSCROLL
|WS_VSCROLL
|
2967 LBS_DISABLENOSCROLL
|LBS_NOINTEGRALHEIGHT
|LBS_OWNERDRAWFIXED
|LBS_NOTIFY
,
2968 0, 0, 0, 0, parent
, (HMENU
)id
, Globals
.hInstance
, 0);
2970 SetWindowLongPtr(pane
->hwnd
, GWLP_USERDATA
, (LPARAM
)pane
);
2971 g_orgTreeWndProc
= SubclassWindow(pane
->hwnd
, TreeWndProc
);
2973 SetWindowFont(pane
->hwnd
, Globals
.hfont
, FALSE
);
2975 /* insert entries into listbox */
2977 insert_entries(pane
, entry
, pattern
, filter_flags
, -1);
2979 /* calculate column widths */
2982 init_output(pane
->hwnd
);
2985 calc_widths(pane
, TRUE
);
2987 #ifndef _NO_EXTENSIONS
2988 pane
->hwndHeader
= create_header(parent
, pane
, id_header
);
2993 static void InitChildWindow(ChildWnd
* child
)
2995 create_tree_window(child
->hwnd
, &child
->left
, IDW_TREE_LEFT
, IDW_HEADER_LEFT
, NULL
, TF_ALL
);
2996 create_tree_window(child
->hwnd
, &child
->right
, IDW_TREE_RIGHT
, IDW_HEADER_RIGHT
, child
->filter_pattern
, child
->filter_flags
);
3000 static void format_date(const FILETIME
* ft
, TCHAR
* buffer
, int visible_cols
)
3006 *buffer
= TEXT('\0');
3008 if (!ft
->dwLowDateTime
&& !ft
->dwHighDateTime
)
3011 if (!FileTimeToLocalFileTime(ft
, &lft
))
3012 {err
: lstrcpy(buffer
,sQMarks
); return;}
3014 if (!FileTimeToSystemTime(&lft
, &systime
))
3017 if (visible_cols
& COL_DATE
) {
3018 len
= GetDateFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
, BUFFER_LEN
);
3023 if (visible_cols
& COL_TIME
) {
3025 buffer
[len
-1] = ' ';
3027 buffer
[len
++] = ' ';
3029 if (!GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
+len
, BUFFER_LEN
-len
))
3030 buffer
[len
] = TEXT('\0');
3035 static void calc_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3037 RECT rt
= {0, 0, 0, 0};
3039 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
3041 if (rt
.right
> pane
->widths
[col
])
3042 pane
->widths
[col
] = rt
.right
;
3045 static void calc_tabbed_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3047 RECT rt
= {0, 0, 0, 0};
3049 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
3050 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
3052 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
3053 /*FIXME rt (0,0) ??? */
3055 if (rt
.right
> pane
->widths
[col
])
3056 pane
->widths
[col
] = rt
.right
;
3060 static void output_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
, DWORD flags
)
3062 int x
= dis
->rcItem
.left
;
3065 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
3066 rt
.top
= dis
->rcItem
.top
;
3067 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
3068 rt
.bottom
= dis
->rcItem
.bottom
;
3070 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_SINGLELINE
|DT_NOPREFIX
|flags
);
3073 static void output_tabbed_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3075 int x
= dis
->rcItem
.left
;
3078 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
3079 rt
.top
= dis
->rcItem
.top
;
3080 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
3081 rt
.bottom
= dis
->rcItem
.bottom
;
3083 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
3084 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
3086 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
3089 static void output_number(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3091 int x
= dis
->rcItem
.left
;
3098 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
3099 rt
.top
= dis
->rcItem
.top
;
3100 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
3101 rt
.bottom
= dis
->rcItem
.bottom
;
3106 /* insert number separator characters */
3107 pos
= lstrlen(s
) % 3;
3113 *d
++ = Globals
.num_sep
;
3117 DrawText(dis
->hDC
, b
, d
-b
, &rt
, DT_RIGHT
|DT_SINGLELINE
|DT_NOPREFIX
|DT_END_ELLIPSIS
);
3121 static BOOL
is_exe_file(LPCTSTR ext
)
3123 static const TCHAR executable_extensions
[][4] = {
3128 #ifndef _NO_EXTENSIONS
3132 #endif /* _NO_EXTENSIONS */
3136 TCHAR ext_buffer
[_MAX_EXT
];
3137 const TCHAR (*p
)[4];
3141 for(s
=ext
+1,d
=ext_buffer
; (*d
=tolower(*s
)); s
++)
3144 for(p
=executable_extensions
; (*p
)[0]; p
++)
3145 if (!lstrcmpi(ext_buffer
, *p
))
3151 static BOOL
is_registered_type(LPCTSTR ext
)
3153 /* check if there exists a classname for this file extension in the registry */
3154 if (!RegQueryValue(HKEY_CLASSES_ROOT
, ext
, NULL
, NULL
))
3160 static enum FILE_TYPE
get_file_type(LPCTSTR filename
)
3162 LPCTSTR ext
= _tcsrchr(filename
, '.');
3166 if (is_exe_file(ext
))
3167 return FT_EXECUTABLE
;
3168 else if (is_registered_type(ext
))
3175 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
)
3177 TCHAR buffer
[BUFFER_LEN
];
3179 int visible_cols
= pane
->visible_cols
;
3180 COLORREF bkcolor
, textcolor
;
3181 RECT focusRect
= dis
->rcItem
;
3188 attrs
= entry
->data
.dwFileAttributes
;
3190 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) {
3191 if (entry
->data
.cFileName
[0]==TEXT('.') && entry
->data
.cFileName
[1]==TEXT('.')
3192 && entry
->data
.cFileName
[2]==TEXT('\0'))
3193 img
= IMG_FOLDER_UP
;
3194 #ifndef _NO_EXTENSIONS
3195 else if (entry
->data
.cFileName
[0]==TEXT('.') && entry
->data
.cFileName
[1]==TEXT('\0'))
3196 img
= IMG_FOLDER_CUR
;
3199 #ifdef _NO_EXTENSIONS
3202 (pane
->treePane
&& (dis
->itemState
&ODS_FOCUS
)))
3203 img
= IMG_OPEN_FOLDER
;
3207 switch(get_file_type(entry
->data
.cFileName
)) {
3208 case FT_EXECUTABLE
: img
= IMG_EXECUTABLE
; break;
3209 case FT_DOCUMENT
: img
= IMG_DOCUMENT
; break;
3210 default: img
= IMG_FILE
;
3218 if (pane
->treePane
) {
3220 img_pos
= dis
->rcItem
.left
+ entry
->level
*(IMAGE_WIDTH
+TREE_LINE_DX
);
3222 if (calcWidthCol
== -1) {
3224 int y
= dis
->rcItem
.top
+ IMAGE_HEIGHT
/2;
3227 HRGN hrgn_org
= CreateRectRgn(0, 0, 0, 0);
3230 rt_clip
.left
= dis
->rcItem
.left
;
3231 rt_clip
.top
= dis
->rcItem
.top
;
3232 rt_clip
.right
= dis
->rcItem
.left
+pane
->widths
[col
];
3233 rt_clip
.bottom
= dis
->rcItem
.bottom
;
3235 hrgn
= CreateRectRgnIndirect(&rt_clip
);
3237 if (!GetClipRgn(dis
->hDC
, hrgn_org
)) {
3238 DeleteObject(hrgn_org
);
3242 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
3243 ExtSelectClipRgn(dis
->hDC
, hrgn
, RGN_AND
);
3246 if ((up
=entry
->up
) != NULL
) {
3247 MoveToEx(dis
->hDC
, img_pos
-IMAGE_WIDTH
/2, y
, 0);
3248 LineTo(dis
->hDC
, img_pos
-2, y
);
3250 x
= img_pos
- IMAGE_WIDTH
/2;
3253 x
-= IMAGE_WIDTH
+TREE_LINE_DX
;
3257 && (up
->next
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
3260 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
3261 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
3263 } while((up
=up
->up
) != NULL
);
3266 x
= img_pos
- IMAGE_WIDTH
/2;
3268 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
3269 LineTo(dis
->hDC
, x
, y
);
3273 && (entry
->next
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
)
3276 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
3278 SelectClipRgn(dis
->hDC
, hrgn_org
);
3279 if (hrgn_org
) DeleteObject(hrgn_org
);
3280 /* SelectObject(dis->hDC, holdPen); */
3281 } else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
) {
3282 int right
= img_pos
+ IMAGE_WIDTH
- TREE_LINE_DX
;
3284 if (right
> pane
->widths
[col
])
3285 pane
->widths
[col
] = right
;
3288 img_pos
= dis
->rcItem
.left
;
3291 img_pos
= dis
->rcItem
.left
;
3293 if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3294 pane
->widths
[col
] = IMAGE_WIDTH
;
3297 if (calcWidthCol
== -1) {
3298 focusRect
.left
= img_pos
-2;
3300 #ifdef _NO_EXTENSIONS
3301 if (pane
->treePane
&& entry
) {
3304 DrawText(dis
->hDC
, entry
->data
.cFileName
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
3306 focusRect
.right
= dis
->rcItem
.left
+pane
->positions
[col
+1]+TREE_LINE_DX
+ rt
.right
+2;
3310 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
)
3311 textcolor
= COLOR_COMPRESSED
;
3313 #endif /* _NO_EXTENSIONS */
3314 textcolor
= RGB(0,0,0);
3316 if (dis
->itemState
& ODS_FOCUS
) {
3317 textcolor
= RGB(255,255,255);
3318 bkcolor
= COLOR_SELECTION
;
3320 bkcolor
= RGB(255,255,255);
3323 hbrush
= CreateSolidBrush(bkcolor
);
3324 FillRect(dis
->hDC
, &focusRect
, hbrush
);
3325 DeleteObject(hbrush
);
3327 SetBkMode(dis
->hDC
, TRANSPARENT
);
3328 SetTextColor(dis
->hDC
, textcolor
);
3330 cx
= pane
->widths
[col
];
3332 if (cx
&& img
!=IMG_NONE
) {
3333 if (cx
> IMAGE_WIDTH
)
3336 #ifdef _SHELL_FOLDERS
3337 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
3338 DrawIconEx(dis
->hDC
, img_pos
, dis
->rcItem
.top
, entry
->hicon
, cx
, GetSystemMetrics(SM_CYSMICON
), 0, 0, DI_NORMAL
);
3341 ImageList_DrawEx(Globals
.himl
, img
, dis
->hDC
,
3342 img_pos
, dis
->rcItem
.top
, cx
,
3343 IMAGE_HEIGHT
, bkcolor
, CLR_DEFAULT
, ILD_NORMAL
);
3350 #ifdef _NO_EXTENSIONS
3351 if (img
>= IMG_FOLDER_UP
)
3357 /* ouput file name */
3358 if (calcWidthCol
== -1)
3359 output_text(pane
, dis
, col
, entry
->data
.cFileName
, 0);
3360 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3361 calc_width(pane
, dis
, col
, entry
->data
.cFileName
);
3365 #ifdef _NO_EXTENSIONS
3366 if (!pane
->treePane
) {
3369 /* display file size */
3370 if (visible_cols
& COL_SIZE
) {
3371 #ifdef _NO_EXTENSIONS
3372 if (!(attrs
&FILE_ATTRIBUTE_DIRECTORY
))
3377 size
= ((ULONGLONG
)entry
->data
.nFileSizeHigh
<< 32) | entry
->data
.nFileSizeLow
;
3379 _stprintf(buffer
, sLongNumFmt
, size
);
3381 if (calcWidthCol
== -1)
3382 output_number(pane
, dis
, col
, buffer
);
3383 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3384 calc_width(pane
, dis
, col
, buffer
);/*TODO: not ever time enough */
3390 /* display file date */
3391 if (visible_cols
& (COL_DATE
|COL_TIME
)) {
3392 #ifndef _NO_EXTENSIONS
3393 format_date(&entry
->data
.ftCreationTime
, buffer
, visible_cols
);
3394 if (calcWidthCol
== -1)
3395 output_text(pane
, dis
, col
, buffer
, 0);
3396 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3397 calc_width(pane
, dis
, col
, buffer
);
3400 format_date(&entry
->data
.ftLastAccessTime
, buffer
, visible_cols
);
3401 if (calcWidthCol
== -1)
3402 output_text(pane
, dis
, col
, buffer
, 0);
3403 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3404 calc_width(pane
, dis
, col
, buffer
);
3406 #endif /* _NO_EXTENSIONS */
3408 format_date(&entry
->data
.ftLastWriteTime
, buffer
, visible_cols
);
3409 if (calcWidthCol
== -1)
3410 output_text(pane
, dis
, col
, buffer
, 0);
3411 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3412 calc_width(pane
, dis
, col
, buffer
);
3416 #ifndef _NO_EXTENSIONS
3417 if (entry
->bhfi_valid
) {
3418 ULONGLONG index
= ((ULONGLONG
)entry
->bhfi
.nFileIndexHigh
<< 32) | entry
->bhfi
.nFileIndexLow
;
3420 if (visible_cols
& COL_INDEX
) {
3421 _stprintf(buffer
, sLongHexFmt
, index
);
3423 if (calcWidthCol
== -1)
3424 output_text(pane
, dis
, col
, buffer
, DT_RIGHT
);
3425 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3426 calc_width(pane
, dis
, col
, buffer
);
3431 if (visible_cols
& COL_LINKS
) {
3432 wsprintf(buffer
, sNumFmt
, entry
->bhfi
.nNumberOfLinks
);
3434 if (calcWidthCol
== -1)
3435 output_text(pane
, dis
, col
, buffer
, DT_CENTER
);
3436 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3437 calc_width(pane
, dis
, col
, buffer
);
3443 #endif /* _NO_EXTENSIONS */
3445 /* show file attributes */
3446 if (visible_cols
& COL_ATTRIBUTES
) {
3447 #ifdef _NO_EXTENSIONS
3448 static const TCHAR s4Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3449 lstrcpy(buffer
, s4Tabs
);
3451 static const TCHAR s11Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3452 lstrcpy(buffer
, s11Tabs
);
3455 if (attrs
& FILE_ATTRIBUTE_NORMAL
) buffer
[ 0] = 'N';
3457 if (attrs
& FILE_ATTRIBUTE_READONLY
) buffer
[ 2] = 'R';
3458 if (attrs
& FILE_ATTRIBUTE_HIDDEN
) buffer
[ 4] = 'H';
3459 if (attrs
& FILE_ATTRIBUTE_SYSTEM
) buffer
[ 6] = 'S';
3460 if (attrs
& FILE_ATTRIBUTE_ARCHIVE
) buffer
[ 8] = 'A';
3461 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
) buffer
[10] = 'C';
3462 #ifndef _NO_EXTENSIONS
3463 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) buffer
[12] = 'D';
3464 if (attrs
& FILE_ATTRIBUTE_ENCRYPTED
) buffer
[14] = 'E';
3465 if (attrs
& FILE_ATTRIBUTE_TEMPORARY
) buffer
[16] = 'T';
3466 if (attrs
& FILE_ATTRIBUTE_SPARSE_FILE
) buffer
[18] = 'P';
3467 if (attrs
& FILE_ATTRIBUTE_REPARSE_POINT
) buffer
[20] = 'Q';
3468 if (attrs
& FILE_ATTRIBUTE_OFFLINE
) buffer
[22] = 'O';
3469 if (attrs
& FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
) buffer
[24] = 'X';
3470 #endif /* _NO_EXTENSIONS */
3473 if (calcWidthCol
== -1)
3474 output_tabbed_text(pane
, dis
, col
, buffer
);
3475 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3476 calc_tabbed_width(pane
, dis
, col
, buffer
);
3482 if (flags.security) {
3483 static const TCHAR sSecTabs[] = {
3484 ' ','\t',' ','\t',' ','\t',' ',
3486 ' ','\t',' ','\t',' ','\t',' ',
3488 ' ','\t',' ','\t',' ','\t',' ',
3492 DWORD rights = get_access_mask();
3494 lstrcpy(buffer, sSecTabs);
3496 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
3497 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
3498 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
3499 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
3500 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
3501 if (rights & FILE_EXECUTE) buffer[12] = 'X';
3502 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
3503 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
3504 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
3505 if (rights & WRITE_DAC) buffer[22] = 'C';
3506 if (rights & WRITE_OWNER) buffer[24] = 'O';
3507 if (rights & SYNCHRONIZE) buffer[26] = 'S';
3509 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
3512 if (flags.description) {
3513 get_description(buffer);
3514 output_text(dis, col++, buffer, 0, psize);
3518 #ifdef _NO_EXTENSIONS
3521 /* draw focus frame */
3522 if ((dis
->itemState
&ODS_FOCUS
) && calcWidthCol
==-1) {
3523 /* Currently [04/2000] Wine neither behaves exactly the same */
3524 /* way as WIN 95 nor like Windows NT... */
3529 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
3530 LOGBRUSH lb
= {PS_SOLID
, RGB(255,255,255)};
3531 hpen
= ExtCreatePen(PS_COSMETIC
|PS_ALTERNATE
, 1, &lb
, 0, 0);
3533 hpen
= CreatePen(PS_DOT
, 0, RGB(255,255,255));
3535 lastPen
= SelectPen(dis
->hDC
, hpen
);
3536 lastBrush
= SelectObject(dis
->hDC
, GetStockObject(HOLLOW_BRUSH
));
3537 SetROP2(dis
->hDC
, R2_XORPEN
);
3538 Rectangle(dis
->hDC
, focusRect
.left
, focusRect
.top
, focusRect
.right
, focusRect
.bottom
);
3539 SelectObject(dis
->hDC
, lastBrush
);
3540 SelectObject(dis
->hDC
, lastPen
);
3543 #endif /* _NO_EXTENSIONS */
3547 #ifdef _NO_EXTENSIONS
3549 static void draw_splitbar(HWND hwnd
, int x
)
3552 HDC hdc
= GetDC(hwnd
);
3554 GetClientRect(hwnd
, &rt
);
3556 rt
.left
= x
- SPLIT_WIDTH
/2;
3557 rt
.right
= x
+ SPLIT_WIDTH
/2+1;
3559 InvertRect(hdc
, &rt
);
3561 ReleaseDC(hwnd
, hdc
);
3564 #endif /* _NO_EXTENSIONS */
3567 #ifndef _NO_EXTENSIONS
3569 static void set_header(Pane
* pane
)
3572 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3575 item
.mask
= HDI_WIDTH
;
3578 for(; x
+pane
->widths
[i
]<scroll_pos
&& i
<COLUMNS
; i
++) {
3579 x
+= pane
->widths
[i
];
3580 Header_SetItem(pane
->hwndHeader
, i
, &item
);
3584 x
+= pane
->widths
[i
];
3585 item
.cxy
= x
- scroll_pos
;
3586 Header_SetItem(pane
->hwndHeader
, i
++, &item
);
3588 for(; i
<COLUMNS
; i
++) {
3589 item
.cxy
= pane
->widths
[i
];
3590 x
+= pane
->widths
[i
];
3591 Header_SetItem(pane
->hwndHeader
, i
, &item
);
3596 static LRESULT
pane_notify(Pane
* pane
, NMHDR
* pnmh
)
3598 switch(pnmh
->code
) {
3600 case HDN_ENDTRACK
: {
3601 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3602 int idx
= phdn
->iItem
;
3603 int dx
= phdn
->pitem
->cxy
- pane
->widths
[idx
];
3607 GetClientRect(pane
->hwnd
, &clnt
);
3609 /* move immediate to simulate HDS_FULLDRAG (for now [04/2000] not really needed with WINELIB) */
3610 Header_SetItem(pane
->hwndHeader
, idx
, phdn
->pitem
);
3612 pane
->widths
[idx
] += dx
;
3614 for(i
=idx
; ++i
<=COLUMNS
; )
3615 pane
->positions
[i
] += dx
;
3618 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3622 rt_scr
.left
= pane
->positions
[idx
+1]-scroll_pos
;
3624 rt_scr
.right
= clnt
.right
;
3625 rt_scr
.bottom
= clnt
.bottom
;
3627 rt_clip
.left
= pane
->positions
[idx
]-scroll_pos
;
3629 rt_clip
.right
= clnt
.right
;
3630 rt_clip
.bottom
= clnt
.bottom
;
3632 if (rt_scr
.left
< 0) rt_scr
.left
= 0;
3633 if (rt_clip
.left
< 0) rt_clip
.left
= 0;
3635 ScrollWindowEx(pane
->hwnd
, dx
, 0, &rt_scr
, &rt_clip
, 0, 0, SW_INVALIDATE
);
3637 rt_clip
.right
= pane
->positions
[idx
+1];
3638 RedrawWindow(pane
->hwnd
, &rt_clip
, 0, RDW_INVALIDATE
|RDW_UPDATENOW
);
3640 if (pnmh
->code
== HDN_ENDTRACK
) {
3641 ListBox_SetHorizontalExtent(pane
->hwnd
, pane
->positions
[COLUMNS
]);
3643 if (GetScrollPos(pane
->hwnd
, SB_HORZ
) != scroll_pos
)
3651 case HDN_DIVIDERDBLCLICK
: {
3652 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3655 calc_single_width(pane
, phdn
->iItem
);
3656 item
.mask
= HDI_WIDTH
;
3657 item
.cxy
= pane
->widths
[phdn
->iItem
];
3659 Header_SetItem(pane
->hwndHeader
, phdn
->iItem
, &item
);
3660 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3667 #endif /* _NO_EXTENSIONS */
3670 static void scan_entry(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3672 TCHAR path
[MAX_PATH
];
3673 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
3675 /* delete sub entries in left pane */
3677 LRESULT res
= ListBox_GetItemData(child
->left
.hwnd
, idx
+1);
3678 Entry
* sub
= (Entry
*) res
;
3680 if (res
==LB_ERR
|| !sub
|| sub
->level
<=entry
->level
)
3683 ListBox_DeleteString(child
->left
.hwnd
, idx
+1);
3686 /* empty right pane */
3687 ListBox_ResetContent(child
->right
.hwnd
);
3689 /* release memory */
3690 free_entries(entry
);
3692 /* read contents from disk */
3693 #ifdef _SHELL_FOLDERS
3694 if (entry
->etype
== ET_SHELL
)
3696 read_directory(entry
, NULL
, child
->sortOrder
, hwnd
);
3701 get_path(entry
, path
);
3702 read_directory(entry
, path
, child
->sortOrder
, hwnd
);
3705 /* insert found entries in right pane */
3706 insert_entries(&child
->right
, entry
->down
, child
->filter_pattern
, child
->filter_flags
, -1);
3707 calc_widths(&child
->right
, FALSE
);
3708 #ifndef _NO_EXTENSIONS
3709 set_header(&child
->right
);
3712 child
->header_wdths_ok
= FALSE
;
3714 SetCursor(old_cursor
);
3718 /* expand a directory entry */
3720 static BOOL
expand_entry(ChildWnd
* child
, Entry
* dir
)
3725 if (!dir
|| dir
->expanded
|| !dir
->down
)
3730 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='\0' && p
->next
) {
3733 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='.' &&
3734 p
->data
.cFileName
[2]=='\0' && p
->next
)
3738 /* no subdirectories ? */
3739 if (!(p
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
3742 idx
= ListBox_FindItemData(child
->left
.hwnd
, 0, dir
);
3744 dir
->expanded
= TRUE
;
3746 /* insert entries in left pane */
3747 insert_entries(&child
->left
, p
, NULL
, TF_ALL
, idx
);
3749 if (!child
->header_wdths_ok
) {
3750 if (calc_widths(&child
->left
, FALSE
)) {
3751 #ifndef _NO_EXTENSIONS
3752 set_header(&child
->left
);
3755 child
->header_wdths_ok
= TRUE
;
3763 static void collapse_entry(Pane
* pane
, Entry
* dir
)
3765 int idx
= ListBox_FindItemData(pane
->hwnd
, 0, dir
);
3767 ShowWindow(pane
->hwnd
, SW_HIDE
);
3769 /* hide sub entries */
3771 LRESULT res
= ListBox_GetItemData(pane
->hwnd
, idx
+1);
3772 Entry
* sub
= (Entry
*) res
;
3774 if (res
==LB_ERR
|| !sub
|| sub
->level
<=dir
->level
)
3777 ListBox_DeleteString(pane
->hwnd
, idx
+1);
3780 dir
->expanded
= FALSE
;
3782 ShowWindow(pane
->hwnd
, SW_SHOW
);
3786 static void refresh_right_pane(ChildWnd
* child
)
3788 ListBox_ResetContent(child
->right
.hwnd
);
3789 insert_entries(&child
->right
, child
->right
.root
, child
->filter_pattern
, child
->filter_flags
, -1);
3790 calc_widths(&child
->right
, FALSE
);
3792 #ifndef _NO_EXTENSIONS
3793 set_header(&child
->right
);
3797 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3799 TCHAR path
[MAX_PATH
];
3806 child
->left
.cur
= entry
;
3808 child
->right
.root
= entry
->down
? entry
->down
: entry
;
3809 child
->right
.cur
= entry
;
3811 if (!entry
->scanned
)
3812 scan_entry(child
, entry
, idx
, hwnd
);
3814 refresh_right_pane(child
);
3816 get_path(entry
, path
);
3817 lstrcpy(child
->path
, path
);
3819 if (child
->hwnd
) /* only change window title, if the window already exists */
3820 SetWindowText(child
->hwnd
, path
);
3823 if (SetCurrentDirectory(path
))
3828 static void refresh_child(ChildWnd
* child
)
3830 TCHAR path
[MAX_PATH
], drv
[_MAX_DRIVE
+1];
3834 get_path(child
->left
.cur
, path
);
3835 _tsplitpath(path
, drv
, NULL
, NULL
, NULL
);
3837 child
->right
.root
= NULL
;
3839 scan_entry(child
, &child
->root
.entry
, 0, child
->hwnd
);
3841 #ifdef _SHELL_FOLDERS
3842 if (child
->root
.entry
.etype
== ET_SHELL
)
3843 entry
= read_tree(&child
->root
, NULL
, get_path_pidl(path
,child
->hwnd
), drv
, child
->sortOrder
, child
->hwnd
);
3846 entry
= read_tree(&child
->root
, path
, NULL
, drv
, child
->sortOrder
, child
->hwnd
);
3849 entry
= &child
->root
.entry
;
3851 insert_entries(&child
->left
, child
->root
.entry
.down
, NULL
, TF_ALL
, 0);
3853 set_curdir(child
, entry
, 0, child
->hwnd
);
3855 idx
= ListBox_FindItemData(child
->left
.hwnd
, 0, child
->left
.cur
);
3856 ListBox_SetCurSel(child
->left
.hwnd
, idx
);
3860 static void create_drive_bar(void)
3862 TBBUTTON drivebarBtn
= {0, 0, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0};
3863 #ifndef _NO_EXTENSIONS
3864 TCHAR b1
[BUFFER_LEN
];
3869 GetLogicalDriveStrings(BUFFER_LEN
, Globals
.drives
);
3871 Globals
.hdrivebar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
,
3872 IDW_DRIVEBAR
, 2, Globals
.hInstance
, IDB_DRIVEBAR
, &drivebarBtn
,
3873 0, 16, 13, 16, 13, sizeof(TBBUTTON
));
3875 #ifndef _NO_EXTENSIONS
3877 /* insert unix file system button */
3881 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
3883 drivebarBtn
.idCommand
= ID_DRIVE_UNIX_FS
;
3884 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3885 drivebarBtn
.iString
++;
3887 #ifdef _SHELL_FOLDERS
3888 /* insert shell namespace button */
3889 load_string(b1
, IDS_SHELL
);
3890 b1
[lstrlen(b1
)+1] = '\0';
3891 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
3893 drivebarBtn
.idCommand
= ID_DRIVE_SHELL_NS
;
3894 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3895 drivebarBtn
.iString
++;
3898 /* register windows drive root strings */
3899 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)Globals
.drives
);
3902 drivebarBtn
.idCommand
= ID_DRIVE_FIRST
;
3904 for(p
=Globals
.drives
; *p
; ) {
3905 #ifdef _NO_EXTENSIONS
3906 /* insert drive letter */
3907 TCHAR b
[3] = {tolower(*p
)};
3908 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b
);
3910 switch(GetDriveType(p
)) {
3911 case DRIVE_REMOVABLE
: drivebarBtn
.iBitmap
= 1; break;
3912 case DRIVE_CDROM
: drivebarBtn
.iBitmap
= 3; break;
3913 case DRIVE_REMOTE
: drivebarBtn
.iBitmap
= 4; break;
3914 case DRIVE_RAMDISK
: drivebarBtn
.iBitmap
= 5; break;
3915 default:/*DRIVE_FIXED*/ drivebarBtn
.iBitmap
= 2;
3918 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3919 drivebarBtn
.idCommand
++;
3920 drivebarBtn
.iString
++;
3926 static void refresh_drives(void)
3930 /* destroy drive bar */
3931 DestroyWindow(Globals
.hdrivebar
);
3932 Globals
.hdrivebar
= 0;
3934 /* re-create drive bar */
3937 /* update window layout */
3938 GetClientRect(Globals
.hMainWnd
, &rect
);
3939 SendMessage(Globals
.hMainWnd
, WM_SIZE
, 0, MAKELONG(rect
.right
, rect
.bottom
));
3943 static BOOL
launch_file(HWND hwnd
, LPCTSTR cmd
, UINT nCmdShow
)
3945 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3947 if ((int)hinst
<= 32) {
3948 display_error(hwnd
, GetLastError());
3956 static BOOL
launch_entry(Entry
* entry
, HWND hwnd
, UINT nCmdShow
)
3958 TCHAR cmd
[MAX_PATH
];
3960 #ifdef _SHELL_FOLDERS
3961 if (entry
->etype
== ET_SHELL
) {
3964 SHELLEXECUTEINFO shexinfo
;
3966 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFO
);
3967 shexinfo
.fMask
= SEE_MASK_IDLIST
;
3968 shexinfo
.hwnd
= hwnd
;
3969 shexinfo
.lpVerb
= NULL
;
3970 shexinfo
.lpFile
= NULL
;
3971 shexinfo
.lpParameters
= NULL
;
3972 shexinfo
.lpDirectory
= NULL
;
3973 shexinfo
.nShow
= nCmdShow
;
3974 shexinfo
.lpIDList
= get_to_absolute_pidl(entry
, hwnd
);
3976 if (!ShellExecuteEx(&shexinfo
)) {
3977 display_error(hwnd
, GetLastError());
3981 if (shexinfo
.lpIDList
!= entry
->pidl
)
3982 IMalloc_Free(Globals
.iMalloc
, shexinfo
.lpIDList
);
3988 get_path(entry
, cmd
);
3990 /* start program, open document... */
3991 return launch_file(hwnd
, cmd
, nCmdShow
);
3995 static void activate_entry(ChildWnd
* child
, Pane
* pane
, HWND hwnd
)
3997 Entry
* entry
= pane
->cur
;
4002 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
4003 int scanned_old
= entry
->scanned
;
4006 scan_entry(child
, entry
, ListBox_GetCurSel(child
->left
.hwnd
), hwnd
);
4008 #ifndef _NO_EXTENSIONS
4009 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='\0')
4013 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='.' && entry
->data
.cFileName
[2]=='\0') {
4014 entry
= child
->left
.cur
->up
;
4015 collapse_entry(&child
->left
, entry
);
4017 } else if (entry
->expanded
)
4018 collapse_entry(pane
, child
->left
.cur
);
4020 expand_entry(child
, child
->left
.cur
);
4022 if (!pane
->treePane
) focus_entry
: {
4023 int idx
= ListBox_FindItemData(child
->left
.hwnd
, ListBox_GetCurSel(child
->left
.hwnd
), entry
);
4024 ListBox_SetCurSel(child
->left
.hwnd
, idx
);
4025 set_curdir(child
, entry
, idx
, hwnd
);
4030 calc_widths(pane
, FALSE
);
4032 #ifndef _NO_EXTENSIONS
4037 if (GetKeyState(VK_MENU
) < 0)
4038 show_properties_dlg(entry
, child
->hwnd
);
4040 launch_entry(entry
, child
->hwnd
, SW_SHOWNORMAL
);
4045 static BOOL
pane_command(Pane
* pane
, UINT cmd
)
4049 if (pane
->visible_cols
) {
4050 pane
->visible_cols
= 0;
4051 calc_widths(pane
, TRUE
);
4052 #ifndef _NO_EXTENSIONS
4055 InvalidateRect(pane
->hwnd
, 0, TRUE
);
4056 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
|MF_CHECKED
);
4057 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
);
4058 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
4062 case ID_VIEW_ALL_ATTRIBUTES
:
4063 if (pane
->visible_cols
!= COL_ALL
) {
4064 pane
->visible_cols
= COL_ALL
;
4065 calc_widths(pane
, TRUE
);
4066 #ifndef _NO_EXTENSIONS
4069 InvalidateRect(pane
->hwnd
, 0, TRUE
);
4070 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
);
4071 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
|MF_CHECKED
);
4072 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
4076 #ifndef _NO_EXTENSIONS
4077 case ID_PREFERRED_SIZES
: {
4078 calc_widths(pane
, TRUE
);
4080 InvalidateRect(pane
->hwnd
, 0, TRUE
);
4084 /* TODO: more command ids... */
4094 static void set_sort_order(ChildWnd
* child
, SORT_ORDER sortOrder
)
4096 if (child
->sortOrder
!= sortOrder
) {
4097 child
->sortOrder
= sortOrder
;
4098 refresh_child(child
);
4102 static void update_view_menu(ChildWnd
* child
)
4104 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_NAME
, child
->sortOrder
==SORT_NAME
? MF_CHECKED
: MF_UNCHECKED
);
4105 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_TYPE
, child
->sortOrder
==SORT_EXT
? MF_CHECKED
: MF_UNCHECKED
);
4106 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_SIZE
, child
->sortOrder
==SORT_SIZE
? MF_CHECKED
: MF_UNCHECKED
);
4107 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_DATE
, child
->sortOrder
==SORT_DATE
? MF_CHECKED
: MF_UNCHECKED
);
4111 static BOOL
is_directory(LPCTSTR target
)
4113 /*TODO correctly handle UNIX paths */
4114 DWORD target_attr
= GetFileAttributes(target
);
4116 if (target_attr
== INVALID_FILE_ATTRIBUTES
)
4119 return target_attr
&FILE_ATTRIBUTE_DIRECTORY
? TRUE
: FALSE
;
4122 static BOOL
prompt_target(Pane
* pane
, LPTSTR source
, LPTSTR target
)
4124 TCHAR path
[MAX_PATH
];
4127 get_path(pane
->cur
, path
);
4129 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_SELECT_DESTINATION
), pane
->hwnd
, DestinationDlgProc
, (LPARAM
)path
) != IDOK
)
4132 get_path(pane
->cur
, source
);
4134 /* convert relative targets to absolute paths */
4135 if (path
[0]!='/' && path
[1]!=':') {
4136 get_path(pane
->cur
->up
, target
);
4137 len
= lstrlen(target
);
4139 if (target
[len
-1]!='\\' && target
[len
-1]!='/')
4140 target
[len
++] = '/';
4142 lstrcpy(target
+len
, path
);
4144 lstrcpy(target
, path
);
4146 /* If the target already exists as directory, create a new target below this. */
4147 if (is_directory(path
)) {
4148 TCHAR fname
[_MAX_FNAME
], ext
[_MAX_EXT
];
4149 static const TCHAR sAppend
[] = {'%','s','/','%','s','%','s','\0'};
4151 _tsplitpath(source
, NULL
, NULL
, fname
, ext
);
4153 wsprintf(target
, sAppend
, path
, fname
, ext
);
4160 static IContextMenu2
* s_pctxmenu2
= NULL
;
4161 static IContextMenu3
* s_pctxmenu3
= NULL
;
4163 static void CtxMenu_reset(void)
4169 static IContextMenu
* CtxMenu_query_interfaces(IContextMenu
* pcm1
)
4171 IContextMenu
* pcm
= NULL
;
4175 if (IContextMenu_QueryInterface(pcm1
, &IID_IContextMenu3
, (void**)&pcm
) == NOERROR
)
4176 s_pctxmenu3
= (LPCONTEXTMENU3
)pcm
;
4177 else if (IContextMenu_QueryInterface(pcm1
, &IID_IContextMenu2
, (void**)&pcm
) == NOERROR
)
4178 s_pctxmenu2
= (LPCONTEXTMENU2
)pcm
;
4181 IContextMenu_Release(pcm1
);
4187 static BOOL
CtxMenu_HandleMenuMsg(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4190 if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3
, nmsg
, wparam
, lparam
)))
4195 if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2
, nmsg
, wparam
, lparam
)))
4202 static HRESULT
ShellFolderContextMenu(IShellFolder
* shell_folder
, HWND hwndParent
, int cidl
, LPCITEMIDLIST
* apidl
, int x
, int y
)
4205 BOOL executed
= FALSE
;
4207 HRESULT hr
= IShellFolder_GetUIObjectOf(shell_folder
, hwndParent
, cidl
, apidl
, &IID_IContextMenu
, NULL
, (LPVOID
*)&pcm
);
4208 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
4210 if (SUCCEEDED(hr
)) {
4211 HMENU hmenu
= CreatePopupMenu();
4213 pcm
= CtxMenu_query_interfaces(pcm
);
4216 hr
= IContextMenu_QueryContextMenu(pcm
, hmenu
, 0, FCIDM_SHVIEWFIRST
, FCIDM_SHVIEWLAST
, CMF_NORMAL
);
4218 if (SUCCEEDED(hr
)) {
4219 UINT idCmd
= TrackPopupMenu(hmenu
, TPM_LEFTALIGN
|TPM_RETURNCMD
|TPM_RIGHTBUTTON
, x
, y
, 0, hwndParent
, NULL
);
4224 CMINVOKECOMMANDINFO cmi
;
4226 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFO
);
4228 cmi
.hwnd
= hwndParent
;
4229 cmi
.lpVerb
= (LPCSTR
)(INT_PTR
)(idCmd
- FCIDM_SHVIEWFIRST
);
4230 cmi
.lpParameters
= NULL
;
4231 cmi
.lpDirectory
= NULL
;
4232 cmi
.nShow
= SW_SHOWNORMAL
;
4236 hr
= IContextMenu_InvokeCommand(pcm
, &cmi
);
4243 IContextMenu_Release(pcm
);
4246 return FAILED(hr
)? hr
: executed
? S_OK
: S_FALSE
;
4250 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4252 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
4257 LPDRAWITEMSTRUCT dis
= (LPDRAWITEMSTRUCT
)lparam
;
4258 Entry
* entry
= (Entry
*) dis
->itemData
;
4260 if (dis
->CtlID
== IDW_TREE_LEFT
)
4261 draw_item(&child
->left
, dis
, entry
, -1);
4262 else if (dis
->CtlID
== IDW_TREE_RIGHT
)
4263 draw_item(&child
->right
, dis
, entry
, -1);
4265 goto draw_menu_item
;
4270 InitChildWindow(child
);
4274 free_child_window(child
);
4275 SetWindowLongPtr(hwnd
, GWLP_USERDATA
, 0);
4282 GetClientRect(hwnd
, &rt
);
4283 BeginPaint(hwnd
, &ps
);
4284 rt
.left
= child
->split_pos
-SPLIT_WIDTH
/2;
4285 rt
.right
= child
->split_pos
+SPLIT_WIDTH
/2+1;
4286 lastBrush
= SelectBrush(ps
.hdc
, (HBRUSH
)GetStockObject(COLOR_SPLITBAR
));
4287 Rectangle(ps
.hdc
, rt
.left
, rt
.top
-1, rt
.right
, rt
.bottom
+1);
4288 SelectObject(ps
.hdc
, lastBrush
);
4289 #ifdef _NO_EXTENSIONS
4290 rt
.top
= rt
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
4291 FillRect(ps
.hdc
, &rt
, GetStockObject(BLACK_BRUSH
));
4293 EndPaint(hwnd
, &ps
);
4297 if (LOWORD(lparam
) == HTCLIENT
) {
4300 ScreenToClient(hwnd
, &pt
);
4302 if (pt
.x
>=child
->split_pos
-SPLIT_WIDTH
/2 && pt
.x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
4303 SetCursor(LoadCursor(0, IDC_SIZEWE
));
4309 case WM_LBUTTONDOWN
: {
4311 int x
= GET_X_LPARAM(lparam
);
4313 GetClientRect(hwnd
, &rt
);
4315 if (x
>=child
->split_pos
-SPLIT_WIDTH
/2 && x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
4316 last_split
= child
->split_pos
;
4317 #ifdef _NO_EXTENSIONS
4318 draw_splitbar(hwnd
, last_split
);
4326 if (GetCapture() == hwnd
) {
4327 #ifdef _NO_EXTENSIONS
4329 int x
= LOWORD(lparam
);
4330 draw_splitbar(hwnd
, last_split
);
4332 GetClientRect(hwnd
, &rt
);
4333 child
->split_pos
= x
;
4334 resize_tree(child
, rt
.right
, rt
.bottom
);
4340 #ifdef _NO_EXTENSIONS
4341 case WM_CAPTURECHANGED
:
4342 if (GetCapture()==hwnd
&& last_split
>=0)
4343 draw_splitbar(hwnd
, last_split
);
4348 if (wparam
== VK_ESCAPE
)
4349 if (GetCapture() == hwnd
) {
4351 #ifdef _NO_EXTENSIONS
4352 draw_splitbar(hwnd
, last_split
);
4354 child
->split_pos
= last_split
;
4356 GetClientRect(hwnd
, &rt
);
4357 resize_tree(child
, rt
.right
, rt
.bottom
);
4360 SetCursor(LoadCursor(0, IDC_ARROW
));
4365 if (GetCapture() == hwnd
) {
4367 int x
= LOWORD(lparam
);
4369 #ifdef _NO_EXTENSIONS
4370 HDC hdc
= GetDC(hwnd
);
4371 GetClientRect(hwnd
, &rt
);
4373 rt
.left
= last_split
-SPLIT_WIDTH
/2;
4374 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
4375 InvertRect(hdc
, &rt
);
4378 rt
.left
= x
-SPLIT_WIDTH
/2;
4379 rt
.right
= x
+SPLIT_WIDTH
/2+1;
4380 InvertRect(hdc
, &rt
);
4382 ReleaseDC(hwnd
, hdc
);
4384 GetClientRect(hwnd
, &rt
);
4386 if (x
>=0 && x
<rt
.right
) {
4387 child
->split_pos
= x
;
4388 resize_tree(child
, rt
.right
, rt
.bottom
);
4389 rt
.left
= x
-SPLIT_WIDTH
/2;
4390 rt
.right
= x
+SPLIT_WIDTH
/2+1;
4391 InvalidateRect(hwnd
, &rt
, FALSE
);
4392 UpdateWindow(child
->left
.hwnd
);
4394 UpdateWindow(child
->right
.hwnd
);
4400 #ifndef _NO_EXTENSIONS
4401 case WM_GETMINMAXINFO
:
4402 DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
4404 {LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
4406 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
4407 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
4409 #endif /* _NO_EXTENSIONS */
4412 if (SetCurrentDirectory(child
->path
))
4414 SetFocus(child
->focus_pane
? child
->right
.hwnd
: child
->left
.hwnd
);
4417 case WM_DISPATCH_COMMAND
: {
4418 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4420 switch(LOWORD(wparam
)) {
4421 case ID_WINDOW_NEW
: {
4422 ChildWnd
* new_child
= alloc_child_window(child
->path
, NULL
, hwnd
);
4424 if (!create_child_window(new_child
))
4431 refresh_child(child
);
4435 activate_entry(child
, pane
, hwnd
);
4438 case ID_FILE_MOVE
: {
4439 TCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
4441 if (prompt_target(pane
, source
, target
)) {
4442 SHFILEOPSTRUCT shfo
= {hwnd
, FO_MOVE
, source
, target
};
4444 source
[lstrlen(source
)+1] = '\0';
4445 target
[lstrlen(target
)+1] = '\0';
4447 if (!SHFileOperation(&shfo
))
4448 refresh_child(child
);
4452 case ID_FILE_COPY
: {
4453 TCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
4455 if (prompt_target(pane
, source
, target
)) {
4456 SHFILEOPSTRUCT shfo
= {hwnd
, FO_COPY
, source
, target
};
4458 source
[lstrlen(source
)+1] = '\0';
4459 target
[lstrlen(target
)+1] = '\0';
4461 if (!SHFileOperation(&shfo
))
4462 refresh_child(child
);
4466 case ID_FILE_DELETE
: {
4467 TCHAR path
[BUFFER_LEN
];
4468 SHFILEOPSTRUCT shfo
= {hwnd
, FO_DELETE
, path
};
4470 get_path(pane
->cur
, path
);
4472 path
[lstrlen(path
)+1] = '\0';
4474 if (!SHFileOperation(&shfo
))
4475 refresh_child(child
);
4478 case ID_VIEW_SORT_NAME
:
4479 set_sort_order(child
, SORT_NAME
);
4482 case ID_VIEW_SORT_TYPE
:
4483 set_sort_order(child
, SORT_EXT
);
4486 case ID_VIEW_SORT_SIZE
:
4487 set_sort_order(child
, SORT_SIZE
);
4490 case ID_VIEW_SORT_DATE
:
4491 set_sort_order(child
, SORT_DATE
);
4494 case ID_VIEW_FILTER
: {
4495 struct FilterDialog dlg
;
4497 memset(&dlg
, 0, sizeof(struct FilterDialog
));
4498 lstrcpy(dlg
.pattern
, child
->filter_pattern
);
4499 dlg
.flags
= child
->filter_flags
;
4501 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE
), hwnd
, FilterDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
4502 lstrcpy(child
->filter_pattern
, dlg
.pattern
);
4503 child
->filter_flags
= dlg
.flags
;
4504 refresh_right_pane(child
);
4508 case ID_VIEW_SPLIT
: {
4509 last_split
= child
->split_pos
;
4510 #ifdef _NO_EXTENSIONS
4511 draw_splitbar(hwnd
, last_split
);
4516 case ID_EDIT_PROPERTIES
:
4517 show_properties_dlg(pane
->cur
, child
->hwnd
);
4521 return pane_command(pane
, LOWORD(wparam
));
4527 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4529 switch(HIWORD(wparam
)) {
4530 case LBN_SELCHANGE
: {
4531 int idx
= ListBox_GetCurSel(pane
->hwnd
);
4532 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, idx
);
4534 if (pane
== &child
->left
)
4535 set_curdir(child
, entry
, idx
, hwnd
);
4541 activate_entry(child
, pane
, hwnd
);
4546 #ifndef _NO_EXTENSIONS
4548 NMHDR
* pnmh
= (NMHDR
*) lparam
;
4549 return pane_notify(pnmh
->idFrom
==IDW_HEADER_LEFT
? &child
->left
: &child
->right
, pnmh
);}
4552 #ifdef _SHELL_FOLDERS
4553 case WM_CONTEXTMENU
: {
4558 /* first select the current item in the listbox */
4559 HWND hpanel
= (HWND
) wparam
;
4560 pt_clnt
.x
= pt
.x
= (short)LOWORD(lparam
);
4561 pt_clnt
.y
= pt
.y
= (short)HIWORD(lparam
);
4562 ScreenToClient(hpanel
, &pt_clnt
);
4563 SendMessage(hpanel
, WM_LBUTTONDOWN
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4564 SendMessage(hpanel
, WM_LBUTTONUP
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4566 /* now create the popup menu using shell namespace and IContextMenu */
4567 pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4568 idx
= ListBox_GetCurSel(pane
->hwnd
);
4571 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, idx
);
4573 LPITEMIDLIST pidl_abs
= get_to_absolute_pidl(entry
, hwnd
);
4576 IShellFolder
* parentFolder
;
4577 LPCITEMIDLIST pidlLast
;
4579 /* get and use the parent folder to display correct context menu in all cases */
4580 if (SUCCEEDED(SHBindToParent(pidl_abs
, &IID_IShellFolder
, (LPVOID
*)&parentFolder
, &pidlLast
))) {
4581 if (ShellFolderContextMenu(parentFolder
, hwnd
, 1, &pidlLast
, pt
.x
, pt
.y
) == S_OK
)
4582 refresh_child(child
);
4584 IShellFolder_Release(parentFolder
);
4587 IMalloc_Free(Globals
.iMalloc
, pidl_abs
);
4593 case WM_MEASUREITEM
:
4595 if (!wparam
) /* Is the message menu-related? */
4596 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4601 case WM_INITMENUPOPUP
:
4602 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4605 update_view_menu(child
);
4608 case WM_MENUCHAR
: /* only supported by IContextMenu3 */
4610 LRESULT lResult
= 0;
4612 IContextMenu3_HandleMenuMsg2(s_pctxmenu3
, nmsg
, wparam
, lparam
, &lResult
);
4620 if (wparam
!= SIZE_MINIMIZED
)
4621 resize_tree(child
, LOWORD(lparam
), HIWORD(lparam
));
4625 return DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
4632 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4634 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(GetParent(hwnd
), GWLP_USERDATA
);
4635 Pane
* pane
= (Pane
*) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
4639 #ifndef _NO_EXTENSIONS
4646 child
->focus_pane
= pane
==&child
->right
? 1: 0;
4647 ListBox_SetSel(hwnd
, TRUE
, 1);
4648 /*TODO: check menu items */
4652 if (wparam
== VK_TAB
) {
4653 /*TODO: SetFocus(Globals.hdrivebar) */
4654 SetFocus(child
->focus_pane
? child
->left
.hwnd
: child
->right
.hwnd
);
4658 return CallWindowProc(g_orgTreeWndProc
, hwnd
, nmsg
, wparam
, lparam
);
4662 static void InitInstance(HINSTANCE hinstance
)
4664 static const TCHAR sFont
[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4671 INITCOMMONCONTROLSEX icc
= {
4672 sizeof(INITCOMMONCONTROLSEX
),
4678 setlocale(LC_COLLATE
, ""); /* set collating rules to local settings for compareName */
4680 InitCommonControlsEx(&icc
);
4683 /* register frame window class */
4685 wcFrame
.cbSize
= sizeof(WNDCLASSEX
);
4687 wcFrame
.lpfnWndProc
= FrameWndProc
;
4688 wcFrame
.cbClsExtra
= 0;
4689 wcFrame
.cbWndExtra
= 0;
4690 wcFrame
.hInstance
= hinstance
;
4691 wcFrame
.hIcon
= LoadIcon(hinstance
, MAKEINTRESOURCE(IDI_WINEFILE
));
4692 wcFrame
.hCursor
= LoadCursor(0, IDC_ARROW
);
4693 wcFrame
.hbrBackground
= 0;
4694 wcFrame
.lpszMenuName
= 0;
4695 wcFrame
.lpszClassName
= sWINEFILEFRAME
;
4696 wcFrame
.hIconSm
= (HICON
)LoadImage(hinstance
,
4697 MAKEINTRESOURCE(IDI_WINEFILE
),
4699 GetSystemMetrics(SM_CXSMICON
),
4700 GetSystemMetrics(SM_CYSMICON
),
4703 Globals
.hframeClass
= RegisterClassEx(&wcFrame
);
4706 /* register tree windows class */
4708 wcChild
.style
= CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
;
4709 wcChild
.lpfnWndProc
= ChildWndProc
;
4710 wcChild
.cbClsExtra
= 0;
4711 wcChild
.cbWndExtra
= 0;
4712 wcChild
.hInstance
= hinstance
;
4714 wcChild
.hCursor
= LoadCursor(0, IDC_ARROW
);
4715 wcChild
.hbrBackground
= 0;
4716 wcChild
.lpszMenuName
= 0;
4717 wcChild
.lpszClassName
= sWINEFILETREE
;
4719 hChildClass
= RegisterClass(&wcChild
);
4722 Globals
.haccel
= LoadAccelerators(hinstance
, MAKEINTRESOURCE(IDA_WINEFILE
));
4724 Globals
.hfont
= CreateFont(-MulDiv(8,GetDeviceCaps(hdc
,LOGPIXELSY
),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont
);
4728 Globals
.hInstance
= hinstance
;
4730 #ifdef _SHELL_FOLDERS
4732 CoGetMalloc(MEMCTX_TASK
, &Globals
.iMalloc
);
4733 SHGetDesktopFolder(&Globals
.iDesktop
);
4735 Globals
.cfStrFName
= RegisterClipboardFormatA(CFSTR_FILENAME
);
4737 Globals
.cfStrFName
= RegisterClipboardFormat(CFSTR_FILENAME
);
4741 /* load column strings */
4744 load_string(g_pos_names
[col
++], IDS_COL_NAME
);
4745 load_string(g_pos_names
[col
++], IDS_COL_SIZE
);
4746 load_string(g_pos_names
[col
++], IDS_COL_CDATE
);
4747 #ifndef _NO_EXTENSIONS
4748 load_string(g_pos_names
[col
++], IDS_COL_ADATE
);
4749 load_string(g_pos_names
[col
++], IDS_COL_MDATE
);
4750 load_string(g_pos_names
[col
++], IDS_COL_IDX
);
4751 load_string(g_pos_names
[col
++], IDS_COL_LINKS
);
4753 load_string(g_pos_names
[col
++], IDS_COL_ATTR
);
4754 #ifndef _NO_EXTENSIONS
4755 load_string(g_pos_names
[col
++], IDS_COL_SEC
);
4760 static void show_frame(HWND hwndParent
, int cmdshow
, LPCTSTR path
)
4762 static const TCHAR sMDICLIENT
[] = {'M','D','I','C','L','I','E','N','T','\0'};
4764 TCHAR buffer
[MAX_PATH
], b1
[BUFFER_LEN
];
4766 HMENU hMenuFrame
, hMenuWindow
;
4769 CLIENTCREATESTRUCT ccs
;
4771 if (Globals
.hMainWnd
)
4774 opts
= load_registry_settings();
4775 hMenuFrame
= LoadMenu(Globals
.hInstance
, MAKEINTRESOURCE(IDM_WINEFILE
));
4776 hMenuWindow
= GetSubMenu(hMenuFrame
, GetMenuItemCount(hMenuFrame
)-2);
4778 Globals
.hMenuFrame
= hMenuFrame
;
4779 Globals
.hMenuView
= GetSubMenu(hMenuFrame
, 3);
4780 Globals
.hMenuOptions
= GetSubMenu(hMenuFrame
, 4);
4782 ccs
.hWindowMenu
= hMenuWindow
;
4783 ccs
.idFirstChild
= IDW_FIRST_CHILD
;
4786 /* create main window */
4787 Globals
.hMainWnd
= CreateWindowEx(0, (LPCTSTR
)(int)Globals
.hframeClass
, RS(b1
,IDS_WINE_FILE
), WS_OVERLAPPEDWINDOW
,
4788 opts
.start_x
, opts
.start_y
, opts
.width
, opts
.height
,
4789 hwndParent
, Globals
.hMenuFrame
, Globals
.hInstance
, 0/*lpParam*/);
4792 Globals
.hmdiclient
= CreateWindowEx(0, sMDICLIENT
, NULL
,
4793 WS_CHILD
|WS_CLIPCHILDREN
|WS_VSCROLL
|WS_HSCROLL
|WS_VISIBLE
|WS_BORDER
,
4795 Globals
.hMainWnd
, 0, Globals
.hInstance
, &ccs
);
4797 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_DRIVE_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4798 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_SAVESETTINGS
, MF_BYCOMMAND
);
4803 TBBUTTON toolbarBtns
[] = {
4804 {0, 0, 0, BTNS_SEP
, {0, 0}, 0, 0},
4805 {0, ID_WINDOW_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4806 {1, ID_WINDOW_CASCADE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4807 {2, ID_WINDOW_TILE_HORZ
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4808 {3, ID_WINDOW_TILE_VERT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4810 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4811 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4814 Globals
.htoolbar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
,
4815 IDW_TOOLBAR
, 2, Globals
.hInstance
, IDB_TOOLBAR
, toolbarBtns
,
4816 sizeof(toolbarBtns
)/sizeof(TBBUTTON
), 16, 15, 16, 15, sizeof(TBBUTTON
));
4817 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_TOOL_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4820 Globals
.hstatusbar
= CreateStatusWindow(WS_CHILD
|WS_VISIBLE
, 0, Globals
.hMainWnd
, IDW_STATUSBAR
);
4821 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
4823 /* CreateStatusWindow does not accept WS_BORDER
4824 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
4825 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
4826 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
4828 /*TODO: read paths from registry */
4830 if (!path
|| !*path
) {
4831 GetCurrentDirectory(MAX_PATH
, buffer
);
4835 ShowWindow(Globals
.hMainWnd
, cmdshow
);
4837 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4838 /* Shell Namespace as default: */
4839 child
= alloc_child_window(path
, get_path_pidl(path
,Globals
.hMainWnd
), Globals
.hMainWnd
);
4841 child
= alloc_child_window(path
, NULL
, Globals
.hMainWnd
);
4844 child
->pos
.showCmd
= SW_SHOWMAXIMIZED
;
4845 child
->pos
.rcNormalPosition
.left
= 0;
4846 child
->pos
.rcNormalPosition
.top
= 0;
4847 child
->pos
.rcNormalPosition
.right
= 320;
4848 child
->pos
.rcNormalPosition
.bottom
= 280;
4850 if (!create_child_window(child
))
4853 SetWindowPlacement(child
->hwnd
, &child
->pos
);
4855 Globals
.himl
= ImageList_LoadBitmap(Globals
.hInstance
, MAKEINTRESOURCE(IDB_IMAGES
), 16, 0, RGB(0,255,0));
4857 Globals
.prescan_node
= FALSE
;
4859 UpdateWindow(Globals
.hMainWnd
);
4861 if (path
&& path
[0])
4864 TCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
4865 TCHAR fullname
[_MAX_FNAME
+_MAX_EXT
+1];
4867 memset(name
,0,sizeof(name
));
4868 memset(name
,0,sizeof(ext
));
4869 _tsplitpath(path
, drv
, dir
, name
, ext
);
4872 count
= ListBox_GetCount(child
->right
.hwnd
);
4873 lstrcpy(fullname
,name
);
4874 lstrcat(fullname
,ext
);
4876 for (index
= 0; index
< count
; index
++)
4878 Entry
* entry
= (Entry
*) ListBox_GetItemData(child
->right
.hwnd
,
4880 if (lstrcmp(entry
->data
.cFileName
,fullname
)==0 ||
4881 lstrcmp(entry
->data
.cAlternateFileName
,fullname
)==0)
4883 ListBox_SetCurSel(child
->right
.hwnd
, index
);
4884 SetFocus(child
->right
.hwnd
);
4892 static void ExitInstance(void)
4894 #ifdef _SHELL_FOLDERS
4895 IShellFolder_Release(Globals
.iDesktop
);
4896 IMalloc_Release(Globals
.iMalloc
);
4900 DeleteObject(Globals
.hfont
);
4901 ImageList_Destroy(Globals
.himl
);
4904 #ifdef _NO_EXTENSIONS
4906 /* search for already running win[e]files */
4908 static int g_foundPrevInstance
= 0;
4910 static BOOL CALLBACK
EnumWndProc(HWND hwnd
, LPARAM lparam
)
4914 GetClassName(hwnd
, cls
, 128);
4916 if (!lstrcmp(cls
, (LPCTSTR
)lparam
)) {
4917 g_foundPrevInstance
++;
4924 /* search for window of given class name to allow only one running instance */
4925 static int find_window_class(LPCTSTR classname
)
4927 EnumWindows(EnumWndProc
, (LPARAM
)classname
);
4929 if (g_foundPrevInstance
)
4937 static int winefile_main(HINSTANCE hinstance
, int cmdshow
, LPCTSTR path
)
4941 InitInstance(hinstance
);
4943 show_frame(0, cmdshow
, path
);
4945 while(GetMessage(&msg
, 0, 0, 0)) {
4946 if (Globals
.hmdiclient
&& TranslateMDISysAccel(Globals
.hmdiclient
, &msg
))
4949 if (Globals
.hMainWnd
&& TranslateAccelerator(Globals
.hMainWnd
, Globals
.haccel
, &msg
))
4952 TranslateMessage(&msg
);
4953 DispatchMessage(&msg
);
4962 #if defined(UNICODE) && defined(_MSC_VER)
4963 int APIENTRY
wWinMain(HINSTANCE hinstance
, HINSTANCE previnstance
, LPWSTR cmdline
, int cmdshow
)
4965 int APIENTRY
WinMain(HINSTANCE hinstance
, HINSTANCE previnstance
, LPSTR cmdline
, int cmdshow
)
4968 #ifdef _NO_EXTENSIONS
4969 if (find_window_class(sWINEFILEFRAME
))
4973 #if defined(UNICODE) && !defined(_MSC_VER)
4974 { /* convert ANSI cmdline into WCS path string */
4975 TCHAR buffer
[MAX_PATH
];
4976 MultiByteToWideChar(CP_ACP
, 0, cmdline
, -1, buffer
, MAX_PATH
);
4977 winefile_main(hinstance
, cmdshow
, buffer
);
4980 winefile_main(hinstance
, cmdshow
, cmdline
);