4 * Copyright 2000, 2003, 2004, 2005 Martin Fuchs
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
25 /* for unix filesystem function calls */
27 #include <sys/types.h>
44 #define _MAX_FNAME 256
45 #define _MAX_DIR _MAX_FNAME
46 #define _MAX_EXT _MAX_FNAME
50 #ifdef NONAMELESSUNION
51 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
53 #define UNION_MEMBER(x) x
58 #define DEFAULT_SPLIT_POS 300
60 #define DEFAULT_SPLIT_POS 200
72 typedef struct _Entry
{
83 #ifndef _NO_EXTENSIONS
84 BY_HANDLE_FILE_INFORMATION bhfi
;
86 enum ENTRY_TYPE etype
;
98 TCHAR volname
[_MAX_FNAME
];
108 COL_ATTRIBUTES
= 0x08,
110 #ifdef _NO_EXTENSIONS
111 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
115 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
|COL_INDEX
|COL_LINKS
128 #ifndef _NO_EXTENSIONS
132 #ifndef _NO_EXTENSIONS
138 int positions
[COLUMNS
+1];
150 int focus_pane
; /* 0: left 1: right */
153 BOOL header_wdths_ok
;
155 TCHAR path
[MAX_PATH
];
156 TCHAR filter_pattern
[MAX_PATH
];
160 SORT_ORDER sortOrder
;
165 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
);
166 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
);
167 static void refresh_child(ChildWnd
* child
);
168 static void refresh_drives(void);
169 static void get_path(Entry
* dir
, PTSTR path
);
170 static void format_date(const FILETIME
* ft
, TCHAR
* buffer
, int visible_cols
);
172 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
173 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
174 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
178 WINEFILE_GLOBALS Globals
;
180 static int last_split
;
183 /* some common string constants */
184 const static TCHAR sEmpty
[] = {'\0'};
185 const static TCHAR sSpace
[] = {' ', '\0'};
186 const static TCHAR sNumFmt
[] = {'%','d','\0'};
187 const static TCHAR sQMarks
[] = {'?','?','?','\0'};
189 /* window class names */
190 const static TCHAR sWINEFILEFRAME
[] = {'W','F','S','_','F','r','a','m','e','\0'};
191 const static TCHAR sWINEFILETREE
[] = {'W','F','S','_','T','r','e','e','\0'};
194 /* #define LONGLONGARG _T("I64") */
195 const static TCHAR sLongHexFmt
[] = {'%','I','6','4','X','\0'};
196 const static TCHAR sLongNumFmt
[] = {'%','I','6','4','d','\0'};
198 /* #define LONGLONGARG _T("L") */
199 const static TCHAR sLongHexFmt
[] = {'%','L','X','\0'};
200 const static TCHAR sLongNumFmt
[] = {'%','L','d','\0'};
204 /* load resource string */
205 static LPTSTR
load_string(LPTSTR buffer
, UINT id
)
207 LoadString(Globals
.hInstance
, id
, buffer
, BUFFER_LEN
);
212 #define RS(b, i) load_string(b, i)
215 /* display error message for the specified WIN32 error code */
216 static void display_error(HWND hwnd
, DWORD error
)
218 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
221 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_FROM_SYSTEM
,
222 0, error
, MAKELANGID(LANG_NEUTRAL
,SUBLANG_DEFAULT
), (PTSTR
)&msg
, 0, NULL
))
223 MessageBox(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
225 MessageBox(hwnd
, RS(b1
,IDS_ERROR
), RS(b2
,IDS_WINEFILE
), MB_OK
);
231 /* display network error message using WNetGetLastError() */
232 static void display_network_error(HWND hwnd
)
234 TCHAR msg
[BUFFER_LEN
], provider
[BUFFER_LEN
], b2
[BUFFER_LEN
];
237 if (WNetGetLastError(&error
, msg
, BUFFER_LEN
, provider
, BUFFER_LEN
) == NO_ERROR
)
238 MessageBox(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
244 static VOID
WineLicense(HWND Wnd
)
246 TCHAR cap
[20], text
[1024];
247 LoadString(Globals
.hInstance
, IDS_LICENSE
, text
, 1024);
248 LoadString(Globals
.hInstance
, IDS_LICENSE_CAPTION
, cap
, 20);
249 MessageBox(Wnd
, text
, cap
, MB_ICONINFORMATION
| MB_OK
);
252 static VOID
WineWarranty(HWND Wnd
)
254 TCHAR cap
[20], text
[1024];
255 LoadString(Globals
.hInstance
, IDS_WARRANTY
, text
, 1024);
256 LoadString(Globals
.hInstance
, IDS_WARRANTY_CAPTION
, cap
, 20);
257 MessageBox(Wnd
, text
, cap
, MB_ICONEXCLAMATION
| MB_OK
);
262 /* call vswprintf() in msvcrt.dll */
263 /*TODO: fix swprintf() in non-msvcrt mode, so that this dynamic linking function can be removed */
264 static int msvcrt_swprintf(WCHAR
* buffer
, const WCHAR
* fmt
, ...)
266 static int (__cdecl
*pvswprintf
)(WCHAR
*, const WCHAR
*, va_list) = NULL
;
271 HMODULE hModMsvcrt
= LoadLibraryA("msvcrt");
272 pvswprintf
= (int(__cdecl
*)(WCHAR
*,const WCHAR
*,va_list)) GetProcAddress(hModMsvcrt
, "vswprintf");
276 ret
= (*pvswprintf
)(buffer
, fmt
, ap
);
282 static LPCWSTR
my_wcsrchr(LPCWSTR str
, WCHAR c
)
297 #define _tcsrchr my_wcsrchr
299 #define _tcsrchr strrchr
302 #endif /* __WINE__ */
305 /* allocate and initialise a directory entry */
306 static Entry
* alloc_entry(void)
308 Entry
* entry
= (Entry
*) malloc(sizeof(Entry
));
310 #ifdef _SHELL_FOLDERS
312 entry
->folder
= NULL
;
319 /* free a directory entry */
320 static void free_entry(Entry
* entry
)
322 #ifdef _SHELL_FOLDERS
323 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
324 DestroyIcon(entry
->hicon
);
326 if (entry
->folder
&& entry
->folder
!=Globals
.iDesktop
)
327 IShellFolder_Release(entry
->folder
);
330 IMalloc_Free(Globals
.iMalloc
, entry
->pidl
);
336 /* recursively free all child entries */
337 static void free_entries(Entry
* dir
)
339 Entry
*entry
, *next
=dir
->down
;
355 static void read_directory_win(Entry
* dir
, LPCTSTR path
)
357 Entry
* first_entry
= NULL
;
361 int level
= dir
->level
+ 1;
362 WIN32_FIND_DATA w32fd
;
364 #ifndef _NO_EXTENSIONS
368 TCHAR buffer
[MAX_PATH
], *p
;
369 for(p
=buffer
; *path
; )
376 hFind
= FindFirstFile(buffer
, &w32fd
);
378 if (hFind
!= INVALID_HANDLE_VALUE
) {
380 #ifdef _NO_EXTENSIONS
381 /* hide directory entry "." */
382 if (w32fd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
383 LPCTSTR name
= w32fd
.cFileName
;
385 if (name
[0]=='.' && name
[1]=='\0')
389 entry
= alloc_entry();
397 memcpy(&entry
->data
, &w32fd
, sizeof(WIN32_FIND_DATA
));
400 entry
->expanded
= FALSE
;
401 entry
->scanned
= FALSE
;
402 entry
->level
= level
;
404 #ifndef _NO_EXTENSIONS
405 entry
->etype
= ET_WINDOWS
;
406 entry
->bhfi_valid
= FALSE
;
408 lstrcpy(p
, entry
->data
.cFileName
);
410 hFile
= CreateFile(buffer
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
411 0, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0);
413 if (hFile
!= INVALID_HANDLE_VALUE
) {
414 if (GetFileInformationByHandle(hFile
, &entry
->bhfi
))
415 entry
->bhfi_valid
= TRUE
;
422 } while(FindNextFile(hFind
, &w32fd
));
430 dir
->down
= first_entry
;
435 static Entry
* find_entry_win(Entry
* dir
, LPCTSTR name
)
439 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
441 LPCTSTR q
= entry
->data
.cFileName
;
444 if (!*p
|| *p
==TEXT('\\') || *p
==TEXT('/'))
446 } while(tolower(*p
++) == tolower(*q
++));
449 q
= entry
->data
.cAlternateFileName
;
452 if (!*p
|| *p
==TEXT('\\') || *p
==TEXT('/'))
454 } while(tolower(*p
++) == tolower(*q
++));
461 static Entry
* read_tree_win(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
463 TCHAR buffer
[MAX_PATH
];
464 Entry
* entry
= &root
->entry
;
468 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
470 #ifndef _NO_EXTENSIONS
471 entry
->etype
= ET_WINDOWS
;
475 while(*s
&& *s
!=TEXT('\\') && *s
!=TEXT('/'))
478 while(*s
==TEXT('\\') || *s
==TEXT('/'))
484 read_directory(entry
, buffer
, sortOrder
, hwnd
);
487 entry
->expanded
= TRUE
;
492 entry
= find_entry_win(entry
, s
);
495 SetCursor(old_cursor
);
501 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
503 static BOOL
time_to_filetime(const time_t* t
, FILETIME
* ftime
)
505 struct tm
* tm
= gmtime(t
);
511 stime
.wYear
= tm
->tm_year
+1900;
512 stime
.wMonth
= tm
->tm_mon
+1;
513 /* stime.wDayOfWeek */
514 stime
.wDay
= tm
->tm_mday
;
515 stime
.wHour
= tm
->tm_hour
;
516 stime
.wMinute
= tm
->tm_min
;
517 stime
.wSecond
= tm
->tm_sec
;
519 return SystemTimeToFileTime(&stime
, ftime
);
522 static void read_directory_unix(Entry
* dir
, LPCTSTR path
)
524 Entry
* first_entry
= NULL
;
529 int level
= dir
->level
+ 1;
531 char cpath
[MAX_PATH
];
533 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, cpath
, MAX_PATH
, NULL
, NULL
);
535 const char* cpath
= path
;
538 pdir
= opendir(cpath
);
543 char buffer
[MAX_PATH
], *p
;
546 for(p
=buffer
,s
=cpath
; *s
; )
549 if (p
==buffer
|| p
[-1]!='/')
552 while((ent
=readdir(pdir
))) {
553 entry
= alloc_entry();
561 entry
->etype
= ET_UNIX
;
563 strcpy(p
, ent
->d_name
);
565 MultiByteToWideChar(CP_UNIXCP
, 0, p
, -1, entry
->data
.cFileName
, MAX_PATH
);
567 lstrcpy(entry
->data
.cFileName
, p
);
570 if (!stat(buffer
, &st
)) {
571 entry
->data
.dwFileAttributes
= p
[0]=='.'? FILE_ATTRIBUTE_HIDDEN
: 0;
573 if (S_ISDIR(st
.st_mode
))
574 entry
->data
.dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
576 entry
->data
.nFileSizeLow
= st
.st_size
& 0xFFFFFFFF;
577 entry
->data
.nFileSizeHigh
= st
.st_size
>> 32;
579 memset(&entry
->data
.ftCreationTime
, 0, sizeof(FILETIME
));
580 time_to_filetime(&st
.st_atime
, &entry
->data
.ftLastAccessTime
);
581 time_to_filetime(&st
.st_mtime
, &entry
->data
.ftLastWriteTime
);
583 entry
->bhfi
.nFileIndexLow
= ent
->d_ino
;
584 entry
->bhfi
.nFileIndexHigh
= 0;
586 entry
->bhfi
.nNumberOfLinks
= st
.st_nlink
;
588 entry
->bhfi_valid
= TRUE
;
590 entry
->data
.nFileSizeLow
= 0;
591 entry
->data
.nFileSizeHigh
= 0;
592 entry
->bhfi_valid
= FALSE
;
597 entry
->expanded
= FALSE
;
598 entry
->scanned
= FALSE
;
599 entry
->level
= level
;
610 dir
->down
= first_entry
;
614 static Entry
* find_entry_unix(Entry
* dir
, LPCTSTR name
)
618 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
620 LPCTSTR q
= entry
->data
.cFileName
;
623 if (!*p
|| *p
==TEXT('/'))
625 } while(*p
++ == *q
++);
631 static Entry
* read_tree_unix(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
633 TCHAR buffer
[MAX_PATH
];
634 Entry
* entry
= &root
->entry
;
638 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
640 entry
->etype
= ET_UNIX
;
643 while(*s
&& *s
!=TEXT('/'))
646 while(*s
== TEXT('/'))
652 read_directory(entry
, buffer
, sortOrder
, hwnd
);
655 entry
->expanded
= TRUE
;
660 entry
= find_entry_unix(entry
, s
);
663 SetCursor(old_cursor
);
668 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
671 #ifdef _SHELL_FOLDERS
674 #define get_strret get_strretW
675 #define path_from_pidl path_from_pidlW
677 #define get_strret get_strretA
678 #define path_from_pidl path_from_pidlA
682 static void free_strret(STRRET
* str
)
684 if (str
->uType
== STRRET_WSTR
)
685 IMalloc_Free(Globals
.iMalloc
, str
->UNION_MEMBER(pOleStr
));
691 static LPSTR
strcpyn(LPSTR dest
, LPCSTR source
, size_t count
)
696 for(s
=source
; count
&&(*d
++=*s
++); )
702 static void get_strretA(STRRET
* str
, const SHITEMID
* shiid
, LPSTR buffer
, int len
)
706 WideCharToMultiByte(CP_ACP
, 0, str
->UNION_MEMBER(pOleStr
), -1, buffer
, len
, NULL
, NULL
);
710 strcpyn(buffer
, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), len
);
714 strcpyn(buffer
, str
->UNION_MEMBER(cStr
), len
);
718 static HRESULT
path_from_pidlA(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPSTR buffer
, int len
)
722 /* SHGDN_FORPARSING: get full path of id list */
723 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, SHGDN_FORPARSING
, &str
);
726 get_strretA(&str
, &pidl
->mkid
, buffer
, len
);
736 static LPWSTR
wcscpyn(LPWSTR dest
, LPCWSTR source
, size_t count
)
741 for(s
=source
; count
&&(*d
++=*s
++); )
747 static void get_strretW(STRRET
* str
, const SHITEMID
* shiid
, LPWSTR buffer
, int len
)
751 wcscpyn(buffer
, str
->UNION_MEMBER(pOleStr
), len
);
755 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), -1, buffer
, len
);
759 MultiByteToWideChar(CP_ACP
, 0, str
->UNION_MEMBER(cStr
), -1, buffer
, len
);
764 static HRESULT
name_from_pidl(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPTSTR buffer
, int len
, SHGDNF flags
)
768 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, flags
, &str
);
771 get_strret(&str
, &pidl
->mkid
, buffer
, len
);
780 static HRESULT
path_from_pidlW(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPWSTR buffer
, int len
)
784 /* SHGDN_FORPARSING: get full path of id list */
785 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, SHGDN_FORPARSING
, &str
);
788 get_strretW(&str
, &pidl
->mkid
, buffer
, len
);
797 /* create an item id list from a file system path */
799 static LPITEMIDLIST
get_path_pidl(LPTSTR path
, HWND hwnd
)
806 LPWSTR buffer
= path
;
808 WCHAR buffer
[MAX_PATH
];
809 MultiByteToWideChar(CP_ACP
, 0, path
, -1, buffer
, MAX_PATH
);
812 hr
= IShellFolder_ParseDisplayName(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
820 /* convert an item id list from relative to absolute (=relative to the desktop) format */
822 static LPITEMIDLIST
get_to_absolute_pidl(Entry
* entry
, HWND hwnd
)
824 if (entry
->up
&& entry
->up
->etype
==ET_SHELL
) {
825 IShellFolder
* folder
= entry
->up
->folder
;
826 WCHAR buffer
[MAX_PATH
];
828 HRESULT hr
= path_from_pidlW(folder
, entry
->pidl
, buffer
, MAX_PATH
);
834 hr
= IShellFolder_ParseDisplayName(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
839 } else if (entry
->etype
== ET_WINDOWS
) {
840 TCHAR path
[MAX_PATH
];
842 get_path(entry
, path
);
844 return get_path_pidl(path
, hwnd
);
845 } else if (entry
->pidl
)
846 return ILClone(entry
->pidl
);
852 static HICON
extract_icon(IShellFolder
* folder
, LPCITEMIDLIST pidl
)
854 IExtractIcon
* pExtract
;
856 if (SUCCEEDED(IShellFolder_GetUIObjectOf(folder
, 0, 1, (LPCITEMIDLIST
*)&pidl
, &IID_IExtractIcon
, 0, (LPVOID
*)&pExtract
))) {
857 TCHAR path
[_MAX_PATH
];
862 if (SUCCEEDED((*pExtract
->lpVtbl
->GetIconLocation
)(pExtract
, GIL_FORSHELL
, path
, _MAX_PATH
, &idx
, &flags
))) {
863 if (!(flags
& GIL_NOTFILENAME
)) {
865 idx
= 0; /* special case for some control panel applications */
867 if ((int)ExtractIconEx(path
, idx
, 0, &hicon
, 1) > 0)
868 flags
&= ~GIL_DONTCACHE
;
870 HICON hIconLarge
= 0;
872 HRESULT hr
= (*pExtract
->lpVtbl
->Extract
)(pExtract
, path
, idx
, &hIconLarge
, &hicon
, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON
)));
875 DestroyIcon(hIconLarge
);
886 static Entry
* find_entry_shell(Entry
* dir
, LPCITEMIDLIST pidl
)
890 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
891 if (entry
->pidl
->mkid
.cb
== pidl
->mkid
.cb
&&
892 !memcmp(entry
->pidl
, pidl
, entry
->pidl
->mkid
.cb
))
899 static Entry
* read_tree_shell(Root
* root
, LPITEMIDLIST pidl
, SORT_ORDER sortOrder
, HWND hwnd
)
901 Entry
* entry
= &root
->entry
;
903 LPITEMIDLIST next_pidl
= pidl
;
904 IShellFolder
* folder
;
905 IShellFolder
* child
= NULL
;
908 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
910 #ifndef _NO_EXTENSIONS
911 entry
->etype
= ET_SHELL
;
914 folder
= Globals
.iDesktop
;
917 entry
->pidl
= next_pidl
;
918 entry
->folder
= folder
;
923 /* copy first element of item idlist */
924 next_pidl
= IMalloc_Alloc(Globals
.iMalloc
, pidl
->mkid
.cb
+sizeof(USHORT
));
925 memcpy(next_pidl
, pidl
, pidl
->mkid
.cb
);
926 ((LPITEMIDLIST
)((LPBYTE
)next_pidl
+pidl
->mkid
.cb
))->mkid
.cb
= 0;
928 hr
= IShellFolder_BindToObject(folder
, next_pidl
, 0, &IID_IShellFolder
, (void**)&child
);
932 read_directory(entry
, NULL
, sortOrder
, hwnd
);
935 entry
->expanded
= TRUE
;
937 next
= find_entry_shell(entry
, next_pidl
);
944 /* go to next element */
945 pidl
= (LPITEMIDLIST
) ((LPBYTE
)pidl
+pidl
->mkid
.cb
);
948 SetCursor(old_cursor
);
954 static void fill_w32fdata_shell(IShellFolder
* folder
, LPCITEMIDLIST pidl
, SFGAOF attribs
, WIN32_FIND_DATA
* w32fdata
)
956 if (!(attribs
& SFGAO_FILESYSTEM
) ||
957 FAILED(SHGetDataFromIDList(folder
, pidl
, SHGDFIL_FINDDATA
, w32fdata
, sizeof(WIN32_FIND_DATA
)))) {
958 WIN32_FILE_ATTRIBUTE_DATA fad
;
959 IDataObject
* pDataObj
;
961 STGMEDIUM medium
= {0, {0}, 0};
962 FORMATETC fmt
= {Globals
.cfStrFName
, 0, DVASPECT_CONTENT
, -1, TYMED_HGLOBAL
};
964 HRESULT hr
= IShellFolder_GetUIObjectOf(folder
, 0, 1, &pidl
, &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
967 hr
= IDataObject_GetData(pDataObj
, &fmt
, &medium
);
969 IDataObject_Release(pDataObj
);
972 LPCTSTR path
= (LPCTSTR
)GlobalLock(medium
.UNION_MEMBER(hGlobal
));
973 UINT sem_org
= SetErrorMode(SEM_FAILCRITICALERRORS
);
975 if (GetFileAttributesEx(path
, GetFileExInfoStandard
, &fad
)) {
976 w32fdata
->dwFileAttributes
= fad
.dwFileAttributes
;
977 w32fdata
->ftCreationTime
= fad
.ftCreationTime
;
978 w32fdata
->ftLastAccessTime
= fad
.ftLastAccessTime
;
979 w32fdata
->ftLastWriteTime
= fad
.ftLastWriteTime
;
981 if (!(fad
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)) {
982 w32fdata
->nFileSizeLow
= fad
.nFileSizeLow
;
983 w32fdata
->nFileSizeHigh
= fad
.nFileSizeHigh
;
987 SetErrorMode(sem_org
);
989 GlobalUnlock(medium
.UNION_MEMBER(hGlobal
));
990 GlobalFree(medium
.UNION_MEMBER(hGlobal
));
995 if (attribs
& (SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
))
996 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
998 if (attribs
& SFGAO_READONLY
)
999 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_READONLY
;
1001 if (attribs
& SFGAO_COMPRESSED
)
1002 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_COMPRESSED
;
1006 static void read_directory_shell(Entry
* dir
, HWND hwnd
)
1008 IShellFolder
* folder
= dir
->folder
;
1009 int level
= dir
->level
+ 1;
1012 IShellFolder
* child
;
1013 IEnumIDList
* idlist
;
1015 Entry
* first_entry
= NULL
;
1022 hr
= IShellFolder_EnumObjects(folder
, hwnd
, SHCONTF_FOLDERS
|SHCONTF_NONFOLDERS
|SHCONTF_INCLUDEHIDDEN
|SHCONTF_SHAREABLE
|SHCONTF_STORAGE
, &idlist
);
1024 if (SUCCEEDED(hr
)) {
1026 #define FETCH_ITEM_COUNT 32
1027 LPITEMIDLIST pidls
[FETCH_ITEM_COUNT
];
1032 memset(pidls
, 0, sizeof(pidls
));
1034 hr
= IEnumIDList_Next(idlist
, FETCH_ITEM_COUNT
, pidls
, &cnt
);
1041 for(n
=0; n
<cnt
; ++n
) {
1042 entry
= alloc_entry();
1045 first_entry
= entry
;
1050 memset(&entry
->data
, 0, sizeof(WIN32_FIND_DATA
));
1051 entry
->bhfi_valid
= FALSE
;
1053 attribs
= ~SFGAO_FILESYSTEM
; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
1055 hr
= IShellFolder_GetAttributesOf(folder
, 1, (LPCITEMIDLIST
*)&pidls
[n
], &attribs
);
1057 if (SUCCEEDED(hr
)) {
1058 if (attribs
!= (SFGAOF
)~SFGAO_FILESYSTEM
) {
1059 fill_w32fdata_shell(folder
, pidls
[n
], attribs
, &entry
->data
);
1061 entry
->bhfi_valid
= TRUE
;
1067 entry
->pidl
= pidls
[n
];
1069 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1070 hr
= IShellFolder_BindToObject(folder
, pidls
[n
], 0, &IID_IShellFolder
, (void**)&child
);
1073 entry
->folder
= child
;
1075 entry
->folder
= NULL
;
1078 entry
->folder
= NULL
;
1080 if (!entry
->data
.cFileName
[0])
1081 /*hr = */name_from_pidl(folder
, pidls
[n
], entry
->data
.cFileName
, MAX_PATH
, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1083 /* get display icons for files and virtual objects */
1084 if (!(entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ||
1085 !(attribs
& SFGAO_FILESYSTEM
)) {
1086 entry
->hicon
= extract_icon(folder
, pidls
[n
]);
1089 entry
->hicon
= (HICON
)-1; /* don't try again later */
1094 entry
->expanded
= FALSE
;
1095 entry
->scanned
= FALSE
;
1096 entry
->level
= level
;
1098 #ifndef _NO_EXTENSIONS
1099 entry
->etype
= ET_SHELL
;
1100 entry
->bhfi_valid
= FALSE
;
1107 IEnumIDList_Release(idlist
);
1113 dir
->down
= first_entry
;
1114 dir
->scanned
= TRUE
;
1117 #endif /* _SHELL_FOLDERS */
1120 /* sort order for different directory/file types */
1129 /* distinguish between ".", ".." and any other directory names */
1130 static int TypeOrderFromDirname(LPCTSTR name
)
1132 if (name
[0] == '.') {
1133 if (name
[1] == '\0')
1134 return TO_DOT
; /* "." */
1136 if (name
[1]=='.' && name
[2]=='\0')
1137 return TO_DOTDOT
; /* ".." */
1140 return TO_OTHER_DIR
; /* anything else */
1143 /* directories first... */
1144 static int compareType(const WIN32_FIND_DATA
* fd1
, const WIN32_FIND_DATA
* fd2
)
1146 int order1
= fd1
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1147 int order2
= fd2
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1149 /* Handle "." and ".." as special case and move them at the very first beginning. */
1150 if (order1
==TO_DIR
&& order2
==TO_DIR
) {
1151 order1
= TypeOrderFromDirname(fd1
->cFileName
);
1152 order2
= TypeOrderFromDirname(fd2
->cFileName
);
1155 return order2
==order1
? 0: order1
<order2
? -1: 1;
1159 static int compareName(const void* arg1
, const void* arg2
)
1161 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1162 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1164 int cmp
= compareType(fd1
, fd2
);
1168 return lstrcmpi(fd1
->cFileName
, fd2
->cFileName
);
1171 static int compareExt(const void* arg1
, const void* arg2
)
1173 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1174 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1175 const TCHAR
*name1
, *name2
, *ext1
, *ext2
;
1177 int cmp
= compareType(fd1
, fd2
);
1181 name1
= fd1
->cFileName
;
1182 name2
= fd2
->cFileName
;
1184 ext1
= _tcsrchr(name1
, TEXT('.'));
1185 ext2
= _tcsrchr(name2
, TEXT('.'));
1197 cmp
= lstrcmpi(ext1
, ext2
);
1201 return lstrcmpi(name1
, name2
);
1204 static int compareSize(const void* arg1
, const void* arg2
)
1206 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1207 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1209 int cmp
= compareType(fd1
, fd2
);
1213 cmp
= fd2
->nFileSizeHigh
- fd1
->nFileSizeHigh
;
1220 cmp
= fd2
->nFileSizeLow
- fd1
->nFileSizeLow
;
1222 return cmp
<0? -1: cmp
>0? 1: 0;
1225 static int compareDate(const void* arg1
, const void* arg2
)
1227 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1228 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1230 int cmp
= compareType(fd1
, fd2
);
1234 return CompareFileTime(&fd2
->ftLastWriteTime
, &fd1
->ftLastWriteTime
);
1238 static int (*sortFunctions
[])(const void* arg1
, const void* arg2
) = {
1239 compareName
, /* SORT_NAME */
1240 compareExt
, /* SORT_EXT */
1241 compareSize
, /* SORT_SIZE */
1242 compareDate
/* SORT_DATE */
1246 static void SortDirectory(Entry
* dir
, SORT_ORDER sortOrder
)
1248 Entry
* entry
= dir
->down
;
1253 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1257 array
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(Entry
*));
1260 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1263 /* call qsort with the appropriate compare function */
1264 qsort(array
, len
, sizeof(array
[0]), sortFunctions
[sortOrder
]);
1266 dir
->down
= array
[0];
1268 for(p
=array
; --len
; p
++)
1273 HeapFree(GetProcessHeap(), 0, array
);
1278 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
1280 TCHAR buffer
[MAX_PATH
];
1285 #ifdef _SHELL_FOLDERS
1286 if (dir
->etype
== ET_SHELL
)
1288 read_directory_shell(dir
, hwnd
);
1290 if (Globals
.prescan_node
) {
1299 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1300 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1301 read_directory_shell(entry
, hwnd
);
1302 SortDirectory(entry
, sortOrder
);
1308 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1309 if (dir
->etype
== ET_UNIX
)
1311 read_directory_unix(dir
, path
);
1313 if (Globals
.prescan_node
) {
1322 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1323 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1324 lstrcpy(d
, entry
->data
.cFileName
);
1325 read_directory_unix(entry
, buffer
);
1326 SortDirectory(entry
, sortOrder
);
1333 read_directory_win(dir
, path
);
1335 if (Globals
.prescan_node
) {
1344 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1345 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1346 lstrcpy(d
, entry
->data
.cFileName
);
1347 read_directory_win(entry
, buffer
);
1348 SortDirectory(entry
, sortOrder
);
1353 SortDirectory(dir
, sortOrder
);
1357 static Entry
* read_tree(Root
* root
, LPCTSTR path
, LPITEMIDLIST pidl
, LPTSTR drv
, SORT_ORDER sortOrder
, HWND hwnd
)
1359 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1360 const static TCHAR sSlash
[] = {'/', '\0'};
1362 const static TCHAR sBackslash
[] = {'\\', '\0'};
1364 #ifdef _SHELL_FOLDERS
1367 /* read shell namespace tree */
1368 root
->drive_type
= DRIVE_UNKNOWN
;
1371 load_string(root
->volname
, IDS_DESKTOP
);
1373 load_string(root
->fs
, IDS_SHELL
);
1375 return read_tree_shell(root
, pidl
, sortOrder
, hwnd
);
1379 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1382 /* read unix file system tree */
1383 root
->drive_type
= GetDriveType(path
);
1385 lstrcat(drv
, sSlash
);
1386 load_string(root
->volname
, IDS_ROOT_FS
);
1388 load_string(root
->fs
, IDS_UNIXFS
);
1390 lstrcpy(root
->path
, sSlash
);
1392 return read_tree_unix(root
, path
, sortOrder
, hwnd
);
1396 /* read WIN32 file system tree */
1397 root
->drive_type
= GetDriveType(path
);
1399 lstrcat(drv
, sBackslash
);
1400 GetVolumeInformation(drv
, root
->volname
, _MAX_FNAME
, 0, 0, &root
->fs_flags
, root
->fs
, _MAX_DIR
);
1402 lstrcpy(root
->path
, drv
);
1404 return read_tree_win(root
, path
, sortOrder
, hwnd
);
1408 /* flags to filter different file types */
1410 TF_DIRECTORIES
= 0x01,
1412 TF_DOCUMENTS
= 0x04,
1419 static ChildWnd
* alloc_child_window(LPCTSTR path
, LPITEMIDLIST pidl
, HWND hwnd
)
1421 TCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
1422 TCHAR dir_path
[MAX_PATH
];
1423 TCHAR b1
[BUFFER_LEN
];
1424 const static TCHAR sAsterics
[] = {'*', '\0'};
1426 ChildWnd
* child
= (ChildWnd
*) malloc(sizeof(ChildWnd
));
1427 Root
* root
= &child
->root
;
1430 memset(child
, 0, sizeof(ChildWnd
));
1432 child
->left
.treePane
= TRUE
;
1433 child
->left
.visible_cols
= 0;
1435 child
->right
.treePane
= FALSE
;
1436 #ifndef _NO_EXTENSIONS
1437 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_INDEX
|COL_LINKS
;
1439 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
;
1442 child
->pos
.length
= sizeof(WINDOWPLACEMENT
);
1443 child
->pos
.flags
= 0;
1444 child
->pos
.showCmd
= SW_SHOWNORMAL
;
1445 child
->pos
.rcNormalPosition
.left
= CW_USEDEFAULT
;
1446 child
->pos
.rcNormalPosition
.top
= CW_USEDEFAULT
;
1447 child
->pos
.rcNormalPosition
.right
= CW_USEDEFAULT
;
1448 child
->pos
.rcNormalPosition
.bottom
= CW_USEDEFAULT
;
1450 child
->focus_pane
= 0;
1451 child
->split_pos
= DEFAULT_SPLIT_POS
;
1452 child
->sortOrder
= SORT_NAME
;
1453 child
->header_wdths_ok
= FALSE
;
1457 lstrcpy(child
->path
, path
);
1459 _tsplitpath(path
, drv
, dir
, name
, ext
);
1462 lstrcpy(child
->filter_pattern
, sAsterics
);
1463 child
->filter_flags
= TF_ALL
;
1465 root
->entry
.level
= 0;
1467 lstrcpy(dir_path
, drv
);
1468 lstrcat(dir_path
, dir
);
1469 entry
= read_tree(root
, dir_path
, pidl
, drv
, child
->sortOrder
, hwnd
);
1471 #ifdef _SHELL_FOLDERS
1472 if (root
->entry
.etype
== ET_SHELL
)
1473 load_string(root
->entry
.data
.cFileName
, IDS_DESKTOP
);
1476 wsprintf(root
->entry
.data
.cFileName
, RS(b1
,IDS_TITLEFMT
), drv
, root
->fs
);
1478 root
->entry
.data
.dwFileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1480 child
->left
.root
= &root
->entry
;
1481 child
->right
.root
= NULL
;
1483 set_curdir(child
, entry
, 0, hwnd
);
1489 /* free all memory associated with a child window */
1490 static void free_child_window(ChildWnd
* child
)
1492 free_entries(&child
->root
.entry
);
1497 /* get full path of specified directory entry */
1498 static void get_path(Entry
* dir
, PTSTR path
)
1504 #ifdef _SHELL_FOLDERS
1505 if (dir
->etype
== ET_SHELL
)
1510 path
[0] = TEXT('\0');
1515 hr
= IShellFolder_GetAttributesOf(dir
->folder
, 1, (LPCITEMIDLIST
*)&dir
->pidl
, &attribs
);
1517 if (SUCCEEDED(hr
) && (attribs
&SFGAO_FILESYSTEM
)) {
1518 IShellFolder
* parent
= dir
->up
? dir
->up
->folder
: Globals
.iDesktop
;
1520 hr
= path_from_pidl(parent
, dir
->pidl
, path
, MAX_PATH
);
1526 for(entry
=dir
; entry
; level
++) {
1532 name
= entry
->data
.cFileName
;
1535 for(l
=0; *s
&& *s
!=TEXT('/') && *s
!=TEXT('\\'); s
++)
1541 memmove(path
+l
+1, path
, len
*sizeof(TCHAR
));
1542 memcpy(path
+1, name
, l
*sizeof(TCHAR
));
1545 #ifndef _NO_EXTENSIONS
1546 if (entry
->etype
== ET_UNIX
)
1547 path
[0] = TEXT('/');
1550 path
[0] = TEXT('\\');
1555 memmove(path
+l
, path
, len
*sizeof(TCHAR
));
1556 memcpy(path
, name
, l
*sizeof(TCHAR
));
1563 #ifndef _NO_EXTENSIONS
1564 if (entry
->etype
== ET_UNIX
)
1565 path
[len
++] = TEXT('/');
1568 path
[len
++] = TEXT('\\');
1571 path
[len
] = TEXT('\0');
1576 static void resize_frame_rect(HWND hwnd
, PRECT prect
)
1581 if (IsWindowVisible(Globals
.htoolbar
)) {
1582 SendMessage(Globals
.htoolbar
, WM_SIZE
, 0, 0);
1583 GetClientRect(Globals
.htoolbar
, &rt
);
1584 prect
->top
= rt
.bottom
+3;
1585 prect
->bottom
-= rt
.bottom
+3;
1588 if (IsWindowVisible(Globals
.hdrivebar
)) {
1589 SendMessage(Globals
.hdrivebar
, WM_SIZE
, 0, 0);
1590 GetClientRect(Globals
.hdrivebar
, &rt
);
1591 new_top
= --prect
->top
+ rt
.bottom
+3;
1592 MoveWindow(Globals
.hdrivebar
, 0, prect
->top
, rt
.right
, new_top
, TRUE
);
1593 prect
->top
= new_top
;
1594 prect
->bottom
-= rt
.bottom
+2;
1597 if (IsWindowVisible(Globals
.hstatusbar
)) {
1598 int parts
[] = {300, 500};
1600 SendMessage(Globals
.hstatusbar
, WM_SIZE
, 0, 0);
1601 SendMessage(Globals
.hstatusbar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
1602 GetClientRect(Globals
.hstatusbar
, &rt
);
1603 prect
->bottom
-= rt
.bottom
;
1606 MoveWindow(Globals
.hmdiclient
, prect
->left
-1,prect
->top
-1,prect
->right
+2,prect
->bottom
+1, TRUE
);
1609 static void resize_frame(HWND hwnd
, int cx
, int cy
)
1618 resize_frame_rect(hwnd
, &rect
);
1621 static void resize_frame_client(HWND hwnd
)
1625 GetClientRect(hwnd
, &rect
);
1627 resize_frame_rect(hwnd
, &rect
);
1631 static HHOOK hcbthook
;
1632 static ChildWnd
* newchild
= NULL
;
1634 static LRESULT CALLBACK
CBTProc(int code
, WPARAM wparam
, LPARAM lparam
)
1636 if (code
==HCBT_CREATEWND
&& newchild
) {
1637 ChildWnd
* child
= newchild
;
1640 child
->hwnd
= (HWND
) wparam
;
1641 SetWindowLongPtr(child
->hwnd
, GWLP_USERDATA
, (LPARAM
)child
);
1644 return CallNextHookEx(hcbthook
, code
, wparam
, lparam
);
1647 static HWND
create_child_window(ChildWnd
* child
)
1649 MDICREATESTRUCT mcs
;
1652 mcs
.szClass
= sWINEFILETREE
;
1653 mcs
.szTitle
= (LPTSTR
)child
->path
;
1654 mcs
.hOwner
= Globals
.hInstance
;
1655 mcs
.x
= child
->pos
.rcNormalPosition
.left
;
1656 mcs
.y
= child
->pos
.rcNormalPosition
.top
;
1657 mcs
.cx
= child
->pos
.rcNormalPosition
.right
-child
->pos
.rcNormalPosition
.left
;
1658 mcs
.cy
= child
->pos
.rcNormalPosition
.bottom
-child
->pos
.rcNormalPosition
.top
;
1662 hcbthook
= SetWindowsHookEx(WH_CBT
, CBTProc
, 0, GetCurrentThreadId());
1665 child
->hwnd
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDICREATE
, 0, (LPARAM
)&mcs
);
1667 UnhookWindowsHookEx(hcbthook
);
1671 UnhookWindowsHookEx(hcbthook
);
1673 (void)ListBox_SetItemHeight(child
->left
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1674 (void)ListBox_SetItemHeight(child
->right
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1676 idx
= ListBox_FindItemData(child
->left
.hwnd
, 0, child
->left
.cur
);
1677 (void)ListBox_SetCurSel(child
->left
.hwnd
, idx
);
1683 struct ExecuteDialog
{
1684 TCHAR cmd
[MAX_PATH
];
1688 static INT_PTR CALLBACK
ExecuteDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1690 static struct ExecuteDialog
* dlg
;
1694 dlg
= (struct ExecuteDialog
*) lparam
;
1698 int id
= (int)wparam
;
1701 GetWindowText(GetDlgItem(hwnd
, 201), dlg
->cmd
, MAX_PATH
);
1702 dlg
->cmdshow
= Button_GetState(GetDlgItem(hwnd
,214))&BST_CHECKED
?
1703 SW_SHOWMINIMIZED
: SW_SHOWNORMAL
;
1704 EndDialog(hwnd
, id
);
1705 } else if (id
== IDCANCEL
)
1706 EndDialog(hwnd
, id
);
1715 static INT_PTR CALLBACK
DestinationDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1717 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1721 SetWindowLongPtr(hwnd
, GWLP_USERDATA
, lparam
);
1722 SetWindowText(GetDlgItem(hwnd
, 201), (LPCTSTR
)lparam
);
1726 int id
= (int)wparam
;
1730 LPTSTR dest
= (LPTSTR
) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
1731 GetWindowText(GetDlgItem(hwnd
, 201), dest
, MAX_PATH
);
1732 EndDialog(hwnd
, id
);
1736 EndDialog(hwnd
, id
);
1740 MessageBox(hwnd
, RS(b1
,IDS_NO_IMPL
), RS(b2
,IDS_WINEFILE
), MB_OK
);
1752 struct FilterDialog
{
1753 TCHAR pattern
[MAX_PATH
];
1757 static INT_PTR CALLBACK
FilterDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1759 static struct FilterDialog
* dlg
;
1763 dlg
= (struct FilterDialog
*) lparam
;
1764 SetWindowText(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
);
1765 Button_SetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_DIRECTORIES
), (dlg
->flags
&TF_DIRECTORIES
? BST_CHECKED
: BST_UNCHECKED
));
1766 Button_SetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_PROGRAMS
), dlg
->flags
&TF_PROGRAMS
? BST_CHECKED
: BST_UNCHECKED
);
1767 Button_SetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_DOCUMENTS
), dlg
->flags
&TF_DOCUMENTS
? BST_CHECKED
: BST_UNCHECKED
);
1768 Button_SetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_OTHERS
), dlg
->flags
&TF_OTHERS
? BST_CHECKED
: BST_UNCHECKED
);
1769 Button_SetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_HIDDEN
), dlg
->flags
&TF_HIDDEN
? BST_CHECKED
: BST_UNCHECKED
);
1773 int id
= (int)wparam
;
1778 GetWindowText(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
, MAX_PATH
);
1780 flags
|= Button_GetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_DIRECTORIES
))&BST_CHECKED
? TF_DIRECTORIES
: 0;
1781 flags
|= Button_GetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_PROGRAMS
))&BST_CHECKED
? TF_PROGRAMS
: 0;
1782 flags
|= Button_GetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_DOCUMENTS
))&BST_CHECKED
? TF_DOCUMENTS
: 0;
1783 flags
|= Button_GetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_OTHERS
))&BST_CHECKED
? TF_OTHERS
: 0;
1784 flags
|= Button_GetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_HIDDEN
))&BST_CHECKED
? TF_HIDDEN
: 0;
1788 EndDialog(hwnd
, id
);
1789 } else if (id
== IDCANCEL
)
1790 EndDialog(hwnd
, id
);
1799 struct PropertiesDialog
{
1800 TCHAR path
[MAX_PATH
];
1805 /* Structure used to store enumerated languages and code pages. */
1806 struct LANGANDCODEPAGE
{
1811 static LPCSTR InfoStrings
[] = {
1827 static void PropDlg_DisplayValue(HWND hlbox
, HWND hedit
)
1829 int idx
= ListBox_GetCurSel(hlbox
);
1831 if (idx
!= LB_ERR
) {
1832 LPCTSTR pValue
= (LPCTSTR
) ListBox_GetItemData(hlbox
, idx
);
1835 SetWindowText(hedit
, pValue
);
1839 static void CheckForFileInfo(struct PropertiesDialog
* dlg
, HWND hwnd
, LPCTSTR strFilename
)
1841 static TCHAR sBackSlash
[] = {'\\','\0'};
1842 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'};
1843 static TCHAR sStringFileInfo
[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1844 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1845 DWORD dwVersionDataLen
= GetFileVersionInfoSize((LPTSTR
)strFilename
, NULL
); /* VC6 and MinGW headers use LPTSTR instead of LPCTSTR */
1847 if (dwVersionDataLen
) {
1848 dlg
->pVersionData
= malloc(dwVersionDataLen
);
1850 if (GetFileVersionInfo((LPTSTR
)strFilename
, 0, dwVersionDataLen
, dlg
->pVersionData
)) { /* VC6 and MinGW headers use LPTSTR instead of LPCTSTR */
1854 if (VerQueryValue(dlg
->pVersionData
, sBackSlash
, &pVal
, &nValLen
)) {
1855 if (nValLen
== sizeof(VS_FIXEDFILEINFO
)) {
1856 VS_FIXEDFILEINFO
* pFixedFileInfo
= (VS_FIXEDFILEINFO
*)pVal
;
1857 char buffer
[BUFFER_LEN
];
1859 sprintf(buffer
, "%d.%d.%d.%d",
1860 HIWORD(pFixedFileInfo
->dwFileVersionMS
), LOWORD(pFixedFileInfo
->dwFileVersionMS
),
1861 HIWORD(pFixedFileInfo
->dwFileVersionLS
), LOWORD(pFixedFileInfo
->dwFileVersionLS
));
1863 SetDlgItemTextA(hwnd
, IDC_STATIC_PROP_VERSION
, buffer
);
1867 /* Read the list of languages and code pages. */
1868 if (VerQueryValue(dlg
->pVersionData
, sTranslation
, &pVal
, &nValLen
)) {
1869 struct LANGANDCODEPAGE
* pTranslate
= (struct LANGANDCODEPAGE
*)pVal
;
1870 struct LANGANDCODEPAGE
* pEnd
= (struct LANGANDCODEPAGE
*)((LPBYTE
)pVal
+nValLen
);
1872 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
1874 /* Read the file description for each language and code page. */
1875 for(; pTranslate
<pEnd
; ++pTranslate
) {
1878 for(p
=InfoStrings
; *p
; ++p
) {
1879 TCHAR subblock
[200];
1886 LPCSTR pInfoString
= *p
;
1888 MultiByteToWideChar(CP_ACP
, 0, pInfoString
, -1, infoStr
, 100);
1890 #define infoStr pInfoString
1892 wsprintf(subblock
, sStringFileInfo
, pTranslate
->wLanguage
, pTranslate
->wCodePage
, infoStr
);
1894 /* Retrieve file description for language and code page */
1895 if (VerQueryValue(dlg
->pVersionData
, subblock
, (PVOID
)&pTxt
, &nValLen
)) {
1896 int idx
= ListBox_AddString(hlbox
, infoStr
);
1897 (void)ListBox_SetItemData(hlbox
, idx
, pTxt
);
1902 (void)ListBox_SetCurSel(hlbox
, 0);
1904 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
1910 static INT_PTR CALLBACK
PropertiesDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1912 static struct PropertiesDialog
* dlg
;
1915 case WM_INITDIALOG
: {
1916 const static TCHAR sByteFmt
[] = {'%','s',' ','B','y','t','e','s','\0'};
1917 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1918 LPWIN32_FIND_DATA pWFD
;
1921 dlg
= (struct PropertiesDialog
*) lparam
;
1922 pWFD
= (LPWIN32_FIND_DATA
) &dlg
->entry
.data
;
1924 GetWindowText(hwnd
, b1
, MAX_PATH
);
1925 wsprintf(b2
, b1
, pWFD
->cFileName
);
1926 SetWindowText(hwnd
, b2
);
1928 format_date(&pWFD
->ftLastWriteTime
, b1
, COL_DATE
|COL_TIME
);
1929 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_LASTCHANGE
), b1
);
1931 size
= ((ULONGLONG
)pWFD
->nFileSizeHigh
<< 32) | pWFD
->nFileSizeLow
;
1932 _stprintf(b1
, sLongNumFmt
, size
);
1933 wsprintf(b2
, sByteFmt
, b1
);
1934 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_SIZE
), b2
);
1936 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_FILENAME
), pWFD
->cFileName
);
1937 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_PATH
), dlg
->path
);
1939 Button_SetCheck(GetDlgItem(hwnd
,IDC_CHECK_READONLY
), (pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_READONLY
? BST_CHECKED
: BST_UNCHECKED
));
1940 Button_SetCheck(GetDlgItem(hwnd
,IDC_CHECK_ARCHIVE
), (pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_ARCHIVE
? BST_CHECKED
: BST_UNCHECKED
));
1941 Button_SetCheck(GetDlgItem(hwnd
,IDC_CHECK_COMPRESSED
), (pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_COMPRESSED
? BST_CHECKED
: BST_UNCHECKED
));
1942 Button_SetCheck(GetDlgItem(hwnd
,IDC_CHECK_HIDDEN
), (pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_HIDDEN
? BST_CHECKED
: BST_UNCHECKED
));
1943 Button_SetCheck(GetDlgItem(hwnd
,IDC_CHECK_SYSTEM
), (pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_SYSTEM
? BST_CHECKED
: BST_UNCHECKED
));
1945 CheckForFileInfo(dlg
, hwnd
, dlg
->path
);
1949 int id
= (int)wparam
;
1951 switch(HIWORD(wparam
)) {
1952 case LBN_SELCHANGE
: {
1953 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
1954 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
1959 if (id
==IDOK
|| id
==IDCANCEL
)
1960 EndDialog(hwnd
, id
);
1966 free(dlg
->pVersionData
);
1967 dlg
->pVersionData
= NULL
;
1974 static void show_properties_dlg(Entry
* entry
, HWND hwnd
)
1976 struct PropertiesDialog dlg
;
1978 memset(&dlg
, 0, sizeof(struct PropertiesDialog
));
1979 get_path(entry
, dlg
.path
);
1980 memcpy(&dlg
.entry
, entry
, sizeof(Entry
));
1982 DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_DIALOG_PROPERTIES
), hwnd
, PropertiesDialogDlgProc
, (LPARAM
)&dlg
);
1986 #ifndef _NO_EXTENSIONS
1988 static struct FullScreenParameters
{
1998 static void frame_get_clientspace(HWND hwnd
, PRECT prect
)
2002 if (!IsIconic(hwnd
))
2003 GetClientRect(hwnd
, prect
);
2007 GetWindowPlacement(hwnd
, &wp
);
2009 prect
->left
= prect
->top
= 0;
2010 prect
->right
= wp
.rcNormalPosition
.right
-wp
.rcNormalPosition
.left
-
2011 2*(GetSystemMetrics(SM_CXSIZEFRAME
)+GetSystemMetrics(SM_CXEDGE
));
2012 prect
->bottom
= wp
.rcNormalPosition
.bottom
-wp
.rcNormalPosition
.top
-
2013 2*(GetSystemMetrics(SM_CYSIZEFRAME
)+GetSystemMetrics(SM_CYEDGE
))-
2014 GetSystemMetrics(SM_CYCAPTION
)-GetSystemMetrics(SM_CYMENUSIZE
);
2017 if (IsWindowVisible(Globals
.htoolbar
)) {
2018 GetClientRect(Globals
.htoolbar
, &rt
);
2019 prect
->top
+= rt
.bottom
+2;
2022 if (IsWindowVisible(Globals
.hdrivebar
)) {
2023 GetClientRect(Globals
.hdrivebar
, &rt
);
2024 prect
->top
+= rt
.bottom
+2;
2027 if (IsWindowVisible(Globals
.hstatusbar
)) {
2028 GetClientRect(Globals
.hstatusbar
, &rt
);
2029 prect
->bottom
-= rt
.bottom
;
2033 static BOOL
toggle_fullscreen(HWND hwnd
)
2037 if ((g_fullscreen
.mode
=!g_fullscreen
.mode
)) {
2038 GetWindowRect(hwnd
, &g_fullscreen
.orgPos
);
2039 g_fullscreen
.wasZoomed
= IsZoomed(hwnd
);
2041 (void)Frame_CalcFrameClient(hwnd
, &rt
);
2042 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
2043 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
2045 rt
.left
= g_fullscreen
.orgPos
.left
-rt
.left
;
2046 rt
.top
= g_fullscreen
.orgPos
.top
-rt
.top
;
2047 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+g_fullscreen
.orgPos
.right
-rt
.right
;
2048 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+g_fullscreen
.orgPos
.bottom
-rt
.bottom
;
2050 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
2052 MoveWindow(hwnd
, g_fullscreen
.orgPos
.left
, g_fullscreen
.orgPos
.top
,
2053 g_fullscreen
.orgPos
.right
-g_fullscreen
.orgPos
.left
,
2054 g_fullscreen
.orgPos
.bottom
-g_fullscreen
.orgPos
.top
, TRUE
);
2056 if (g_fullscreen
.wasZoomed
)
2057 ShowWindow(hwnd
, WS_MAXIMIZE
);
2060 return g_fullscreen
.mode
;
2063 static void fullscreen_move(HWND hwnd
)
2066 GetWindowRect(hwnd
, &pos
);
2068 (void)Frame_CalcFrameClient(hwnd
, &rt
);
2069 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
2070 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
2072 rt
.left
= pos
.left
-rt
.left
;
2073 rt
.top
= pos
.top
-rt
.top
;
2074 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+pos
.right
-rt
.right
;
2075 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+pos
.bottom
-rt
.bottom
;
2077 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
2083 static void toggle_child(HWND hwnd
, UINT cmd
, HWND hchild
)
2085 BOOL vis
= IsWindowVisible(hchild
);
2087 CheckMenuItem(Globals
.hMenuOptions
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
2089 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
2091 #ifndef _NO_EXTENSIONS
2092 if (g_fullscreen
.mode
)
2093 fullscreen_move(hwnd
);
2096 resize_frame_client(hwnd
);
2099 static BOOL
activate_drive_window(LPCTSTR path
)
2101 TCHAR drv1
[_MAX_DRIVE
], drv2
[_MAX_DRIVE
];
2104 _tsplitpath(path
, drv1
, 0, 0, 0);
2106 /* search for a already open window for the same drive */
2107 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2108 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(child_wnd
, GWLP_USERDATA
);
2111 _tsplitpath(child
->root
.path
, drv2
, 0, 0, 0);
2113 if (!lstrcmpi(drv2
, drv1
)) {
2114 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2116 if (IsMinimized(child_wnd
))
2117 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2127 static BOOL
activate_fs_window(LPCTSTR filesys
)
2131 /* search for a already open window of the given file system name */
2132 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2133 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(child_wnd
, GWLP_USERDATA
);
2136 if (!lstrcmpi(child
->root
.fs
, filesys
)) {
2137 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2139 if (IsMinimized(child_wnd
))
2140 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2150 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
2152 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2156 DestroyWindow(hwnd
);
2158 /* clear handle variables */
2159 Globals
.hMenuFrame
= 0;
2160 Globals
.hMenuView
= 0;
2161 Globals
.hMenuOptions
= 0;
2162 Globals
.hMainWnd
= 0;
2163 Globals
.hmdiclient
= 0;
2164 Globals
.hdrivebar
= 0;
2171 case WM_INITMENUPOPUP
: {
2172 HWND hwndClient
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2174 if (!SendMessage(hwndClient
, WM_INITMENUPOPUP
, wparam
, lparam
))
2179 UINT cmd
= LOWORD(wparam
);
2180 HWND hwndClient
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2182 if (SendMessage(hwndClient
, WM_DISPATCH_COMMAND
, wparam
, lparam
))
2185 if (cmd
>=ID_DRIVE_FIRST
&& cmd
<=ID_DRIVE_FIRST
+0xFF) {
2186 TCHAR drv
[_MAX_DRIVE
], path
[MAX_PATH
];
2188 LPCTSTR root
= Globals
.drives
;
2191 for(i
=cmd
-ID_DRIVE_FIRST
; i
--; root
++)
2195 if (activate_drive_window(root
))
2198 _tsplitpath(root
, drv
, 0, 0, 0);
2200 if (!SetCurrentDirectory(drv
)) {
2201 display_error(hwnd
, GetLastError());
2205 GetCurrentDirectory(MAX_PATH
, path
); /*TODO: store last directory per drive */
2206 child
= alloc_child_window(path
, NULL
, hwnd
);
2208 if (!create_child_window(child
))
2210 } else switch(cmd
) {
2212 SendMessage(hwnd
, WM_CLOSE
, 0, 0);
2215 case ID_WINDOW_NEW
: {
2216 TCHAR path
[MAX_PATH
];
2219 GetCurrentDirectory(MAX_PATH
, path
);
2220 child
= alloc_child_window(path
, NULL
, hwnd
);
2222 if (!create_child_window(child
))
2230 case ID_WINDOW_CASCADE
:
2231 SendMessage(Globals
.hmdiclient
, WM_MDICASCADE
, 0, 0);
2234 case ID_WINDOW_TILE_HORZ
:
2235 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
2238 case ID_WINDOW_TILE_VERT
:
2239 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
2242 case ID_WINDOW_ARRANGE
:
2243 SendMessage(Globals
.hmdiclient
, WM_MDIICONARRANGE
, 0, 0);
2246 case ID_SELECT_FONT
: {
2247 TCHAR dlg_name
[BUFFER_LEN
], dlg_info
[BUFFER_LEN
];
2251 HDC hdc
= GetDC(hwnd
);
2252 chFont
.lStructSize
= sizeof(CHOOSEFONT
);
2253 chFont
.hwndOwner
= hwnd
;
2255 chFont
.lpLogFont
= &lFont
;
2256 chFont
.Flags
= CF_SCREENFONTS
| CF_FORCEFONTEXIST
| CF_LIMITSIZE
| CF_NOSCRIPTSEL
;
2257 chFont
.rgbColors
= RGB(0,0,0);
2258 chFont
.lCustData
= 0;
2259 chFont
.lpfnHook
= NULL
;
2260 chFont
.lpTemplateName
= NULL
;
2261 chFont
.hInstance
= Globals
.hInstance
;
2262 chFont
.lpszStyle
= NULL
;
2263 chFont
.nFontType
= SIMULATED_FONTTYPE
;
2264 chFont
.nSizeMin
= 0;
2265 chFont
.nSizeMax
= 24;
2267 if (ChooseFont(&chFont
)) {
2271 DeleteObject(Globals
.hfont
);
2272 Globals
.hfont
= CreateFontIndirect(&lFont
);
2273 hFontOld
= SelectFont(hdc
, Globals
.hfont
);
2274 GetTextExtentPoint32(hdc
, sSpace
, 1, &Globals
.spaceSize
);
2276 /* change font in all open child windows */
2277 for(childWnd
=GetWindow(Globals
.hmdiclient
,GW_CHILD
); childWnd
; childWnd
=GetNextWindow(childWnd
,GW_HWNDNEXT
)) {
2278 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(childWnd
, GWLP_USERDATA
);
2279 SetWindowFont(child
->left
.hwnd
, Globals
.hfont
, TRUE
);
2280 SetWindowFont(child
->right
.hwnd
, Globals
.hfont
, TRUE
);
2281 (void)ListBox_SetItemHeight(child
->left
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
2282 (void)ListBox_SetItemHeight(child
->right
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
2283 InvalidateRect(child
->left
.hwnd
, NULL
, TRUE
);
2284 InvalidateRect(child
->right
.hwnd
, NULL
, TRUE
);
2287 (void)SelectFont(hdc
, hFontOld
);
2289 else if (CommDlgExtendedError()) {
2290 LoadString(Globals
.hInstance
, IDS_FONT_SEL_DLG_NAME
, dlg_name
, BUFFER_LEN
);
2291 LoadString(Globals
.hInstance
, IDS_FONT_SEL_ERROR
, dlg_info
, BUFFER_LEN
);
2292 MessageBox(hwnd
, dlg_info
, dlg_name
, MB_OK
);
2295 ReleaseDC(hwnd
, hdc
);
2299 case ID_VIEW_TOOL_BAR
:
2300 toggle_child(hwnd
, cmd
, Globals
.htoolbar
);
2303 case ID_VIEW_DRIVE_BAR
:
2304 toggle_child(hwnd
, cmd
, Globals
.hdrivebar
);
2307 case ID_VIEW_STATUSBAR
:
2308 toggle_child(hwnd
, cmd
, Globals
.hstatusbar
);
2312 struct ExecuteDialog dlg
;
2314 memset(&dlg
, 0, sizeof(struct ExecuteDialog
));
2316 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_EXECUTE
), hwnd
, ExecuteDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
2317 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, dlg
.cmd
/*file*/, NULL
/*parameters*/, NULL
/*dir*/, dlg
.cmdshow
);
2319 if ((int)hinst
<= 32)
2320 display_error(hwnd
, GetLastError());
2324 case ID_CONNECT_NETWORK_DRIVE
: {
2325 DWORD ret
= WNetConnectionDialog(hwnd
, RESOURCETYPE_DISK
);
2326 if (ret
== NO_ERROR
)
2328 else if (ret
!= (DWORD
)-1) {
2329 if (ret
== ERROR_EXTENDED_ERROR
)
2330 display_network_error(hwnd
);
2332 display_error(hwnd
, ret
);
2336 case ID_DISCONNECT_NETWORK_DRIVE
: {
2337 DWORD ret
= WNetDisconnectDialog(hwnd
, RESOURCETYPE_DISK
);
2338 if (ret
== NO_ERROR
)
2340 else if (ret
!= (DWORD
)-1) {
2341 if (ret
== ERROR_EXTENDED_ERROR
)
2342 display_network_error(hwnd
);
2344 display_error(hwnd
, ret
);
2348 #ifndef __MINGW32__ /* SHFormatDrive missing in MinGW (as of 13.5.2005) */
2349 case ID_FORMAT_DISK
: {
2350 UINT sem_org
= SetErrorMode(0); /* Get the current Error Mode settings. */
2351 SetErrorMode(sem_org
& ~SEM_FAILCRITICALERRORS
); /* Force O/S to handle */
2352 SHFormatDrive(hwnd
, 0 /* A: */, SHFMT_ID_DEFAULT
, 0);
2353 SetErrorMode(sem_org
); /* Put it back the way it was. */
2358 WinHelp(hwnd
, RS(b1
,IDS_WINEFILE
), HELP_INDEX
, 0);
2361 #ifndef _NO_EXTENSIONS
2362 case ID_VIEW_FULLSCREEN
:
2363 CheckMenuItem(Globals
.hMenuOptions
, cmd
, toggle_fullscreen(hwnd
)?MF_CHECKED
:0);
2367 case ID_DRIVE_UNIX_FS
: {
2368 TCHAR path
[MAX_PATH
];
2370 char cpath
[MAX_PATH
];
2374 if (activate_fs_window(RS(b1
,IDS_UNIXFS
)))
2379 getcwd(cpath
, MAX_PATH
);
2380 MultiByteToWideChar(CP_UNIXCP
, 0, cpath
, -1, path
, MAX_PATH
);
2382 getcwd(path
, MAX_PATH
);
2384 child
= alloc_child_window(path
, NULL
, hwnd
);
2386 if (!create_child_window(child
))
2391 #ifdef _SHELL_FOLDERS
2392 case ID_DRIVE_SHELL_NS
: {
2393 TCHAR path
[MAX_PATH
];
2396 if (activate_fs_window(RS(b1
,IDS_SHELL
)))
2399 GetCurrentDirectory(MAX_PATH
, path
);
2400 child
= alloc_child_window(path
, get_path_pidl(path
,hwnd
), hwnd
);
2402 if (!create_child_window(child
))
2408 /*TODO: There are even more menu items! */
2410 #ifndef _NO_EXTENSIONS
2413 WineLicense(Globals
.hMainWnd
);
2416 case ID_NO_WARRANTY
:
2417 WineWarranty(Globals
.hMainWnd
);
2421 ShellAbout(hwnd
, RS(b2
,IDS_WINE
), RS(b1
,IDS_WINEFILE
), 0);
2426 ShellAbout(hwnd
, RS(b1
,IDS_WINEFILE
), NULL
, 0);
2428 #endif /* _NO_EXTENSIONS */
2431 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2432 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2433 else */if ((cmd
<IDW_FIRST_CHILD
|| cmd
>=IDW_FIRST_CHILD
+0x100) &&
2434 (cmd
<SC_SIZE
|| cmd
>SC_RESTORE
))
2435 MessageBox(hwnd
, RS(b2
,IDS_NO_IMPL
), RS(b1
,IDS_WINEFILE
), MB_OK
);
2437 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2442 resize_frame(hwnd
, LOWORD(lparam
), HIWORD(lparam
));
2443 break; /* do not pass message to DefFrameProc */
2445 #ifndef _NO_EXTENSIONS
2446 case WM_GETMINMAXINFO
: {
2447 LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
2449 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2450 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2453 case FRM_CALC_CLIENT
:
2454 frame_get_clientspace(hwnd
, (PRECT
)lparam
);
2456 #endif /* _NO_EXTENSIONS */
2459 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2466 static TCHAR g_pos_names
[COLUMNS
][20] = {
2470 static const int g_pos_align
[] = {
2472 HDF_LEFT
, /* Name */
2473 HDF_RIGHT
, /* Size */
2474 HDF_LEFT
, /* CDate */
2475 #ifndef _NO_EXTENSIONS
2476 HDF_LEFT
, /* ADate */
2477 HDF_LEFT
, /* MDate */
2478 HDF_LEFT
, /* Index */
2479 HDF_CENTER
, /* Links */
2481 HDF_CENTER
, /* Attributes */
2482 #ifndef _NO_EXTENSIONS
2483 HDF_LEFT
/* Security */
2487 static void resize_tree(ChildWnd
* child
, int cx
, int cy
)
2489 HDWP hdwp
= BeginDeferWindowPos(4);
2497 cx
= child
->split_pos
+ SPLIT_WIDTH
/2;
2499 #ifndef _NO_EXTENSIONS
2507 (void)Header_Layout(child
->left
.hwndHeader
, &hdl
);
2509 DeferWindowPos(hdwp
, child
->left
.hwndHeader
, wp
.hwndInsertAfter
,
2510 wp
.x
-1, wp
.y
, child
->split_pos
-SPLIT_WIDTH
/2+1, wp
.cy
, wp
.flags
);
2511 DeferWindowPos(hdwp
, child
->right
.hwndHeader
, wp
.hwndInsertAfter
,
2512 rt
.left
+cx
+1, wp
.y
, wp
.cx
-cx
+2, wp
.cy
, wp
.flags
);
2514 #endif /* _NO_EXTENSIONS */
2516 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
);
2517 DeferWindowPos(hdwp
, child
->right
.hwnd
, 0, rt
.left
+cx
+1, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
2519 EndDeferWindowPos(hdwp
);
2523 #ifndef _NO_EXTENSIONS
2525 static HWND
create_header(HWND parent
, Pane
* pane
, int id
)
2530 HWND hwnd
= CreateWindow(WC_HEADER
, 0, WS_CHILD
|WS_VISIBLE
|HDS_HORZ
/*TODO: |HDS_BUTTONS + sort orders*/,
2531 0, 0, 0, 0, parent
, (HMENU
)id
, Globals
.hInstance
, 0);
2535 SetWindowFont(hwnd
, GetStockObject(DEFAULT_GUI_FONT
), FALSE
);
2537 hdi
.mask
= HDI_TEXT
|HDI_WIDTH
|HDI_FORMAT
;
2539 for(idx
=0; idx
<COLUMNS
; idx
++) {
2540 hdi
.pszText
= g_pos_names
[idx
];
2541 hdi
.fmt
= HDF_STRING
| g_pos_align
[idx
];
2542 hdi
.cxy
= pane
->widths
[idx
];
2543 (void)Header_InsertItem(hwnd
, idx
, &hdi
);
2549 #endif /* _NO_EXTENSIONS */
2552 static void init_output(HWND hwnd
)
2554 const static TCHAR s1000
[] = {'1','0','0','0','\0'};
2558 HDC hdc
= GetDC(hwnd
);
2560 if (GetNumberFormat(LOCALE_USER_DEFAULT
, 0, s1000
, 0, b
, 16) > 4)
2561 Globals
.num_sep
= b
[1];
2563 Globals
.num_sep
= TEXT('.');
2565 old_font
= SelectFont(hdc
, Globals
.hfont
);
2566 GetTextExtentPoint32(hdc
, sSpace
, 1, &Globals
.spaceSize
);
2567 (void)SelectFont(hdc
, old_font
);
2568 ReleaseDC(hwnd
, hdc
);
2571 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
);
2574 /* calculate preferred width for all visible columns */
2576 static BOOL
calc_widths(Pane
* pane
, BOOL anyway
)
2578 int col
, x
, cx
, spc
=3*Globals
.spaceSize
.cx
;
2579 int entries
= ListBox_GetCount(pane
->hwnd
);
2580 int orgWidths
[COLUMNS
];
2581 int orgPositions
[COLUMNS
+1];
2587 memcpy(orgWidths
, pane
->widths
, sizeof(orgWidths
));
2588 memcpy(orgPositions
, pane
->positions
, sizeof(orgPositions
));
2591 for(col
=0; col
<COLUMNS
; col
++)
2592 pane
->widths
[col
] = 0;
2594 hdc
= GetDC(pane
->hwnd
);
2595 hfontOld
= SelectFont(hdc
, Globals
.hfont
);
2597 for(cnt
=0; cnt
<entries
; cnt
++) {
2598 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, cnt
);
2607 dis
.hwndItem
= pane
->hwnd
;
2609 dis
.rcItem
.left
= 0;
2611 dis
.rcItem
.right
= 0;
2612 dis
.rcItem
.bottom
= 0;
2613 /*dis.itemData = 0; */
2615 draw_item(pane
, &dis
, entry
, COLUMNS
);
2618 SelectObject(hdc
, hfontOld
);
2619 ReleaseDC(pane
->hwnd
, hdc
);
2622 for(col
=0; col
<COLUMNS
; col
++) {
2623 pane
->positions
[col
] = x
;
2624 cx
= pane
->widths
[col
];
2629 if (cx
< IMAGE_WIDTH
)
2632 pane
->widths
[col
] = cx
;
2638 pane
->positions
[COLUMNS
] = x
;
2640 ListBox_SetHorizontalExtent(pane
->hwnd
, x
);
2643 if (!memcmp(orgWidths
, pane
->widths
, sizeof(orgWidths
)))
2646 /* don't move, if only collapsing an entry */
2647 if (!anyway
&& pane
->widths
[0]<orgWidths
[0] &&
2648 !memcmp(orgWidths
+1, pane
->widths
+1, sizeof(orgWidths
)-sizeof(int))) {
2649 pane
->widths
[0] = orgWidths
[0];
2650 memcpy(pane
->positions
, orgPositions
, sizeof(orgPositions
));
2655 InvalidateRect(pane
->hwnd
, 0, TRUE
);
2661 /* calculate one preferred column width */
2663 static void calc_single_width(Pane
* pane
, int col
)
2667 int entries
= ListBox_GetCount(pane
->hwnd
);
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
);
2685 dis
.hwndItem
= pane
->hwnd
;
2687 dis
.rcItem
.left
= 0;
2689 dis
.rcItem
.right
= 0;
2690 dis
.rcItem
.bottom
= 0;
2691 /*dis.itemData = 0; */
2693 draw_item(pane
, &dis
, entry
, col
);
2696 SelectObject(hdc
, hfontOld
);
2697 ReleaseDC(pane
->hwnd
, hdc
);
2699 cx
= pane
->widths
[col
];
2702 cx
+= 3*Globals
.spaceSize
.cx
;
2704 if (cx
< IMAGE_WIDTH
)
2708 pane
->widths
[col
] = cx
;
2710 x
= pane
->positions
[col
] + cx
;
2712 for(; col
<COLUMNS
; ) {
2713 pane
->positions
[++col
] = x
;
2714 x
+= pane
->widths
[col
];
2717 ListBox_SetHorizontalExtent(pane
->hwnd
, x
);
2721 static BOOL
pattern_match(LPCTSTR str
, LPCTSTR pattern
)
2723 for( ; *str
&&*pattern
; str
++,pattern
++) {
2724 if (*pattern
== '*') {
2726 while(*pattern
== '*');
2732 if (*str
==*pattern
&& pattern_match(str
, pattern
))
2737 else if (*str
!=*pattern
&& *pattern
!='?')
2741 if (*str
|| *pattern
)
2742 if (*pattern
!='*' || pattern
[1]!='\0')
2748 static BOOL
pattern_imatch(LPCTSTR str
, LPCTSTR pattern
)
2750 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2753 lstrcpy(b2
, pattern
);
2757 return pattern_match(b1
, b2
);
2767 static enum FILE_TYPE
get_file_type(LPCTSTR filename
);
2770 /* insert listbox entries after index idx */
2772 static int insert_entries(Pane
* pane
, Entry
* dir
, LPCTSTR pattern
, int filter_flags
, int idx
)
2779 ShowWindow(pane
->hwnd
, SW_HIDE
);
2781 for(; entry
; entry
=entry
->next
) {
2783 if (pane
->treePane
&& !(entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
2787 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
2788 /* don't display entries "." and ".." in the left pane */
2789 if (pane
->treePane
&& entry
->data
.cFileName
[0]==TEXT('.'))
2791 #ifndef _NO_EXTENSIONS
2792 entry
->data
.cFileName
[1]==TEXT('\0') ||
2794 (entry
->data
.cFileName
[1]==TEXT('.') && entry
->data
.cFileName
[2]==TEXT('\0')))
2797 /* filter directories in right pane */
2798 if (!pane
->treePane
&& !(filter_flags
&TF_DIRECTORIES
))
2802 /* filter using the file name pattern */
2804 if (!pattern_imatch(entry
->data
.cFileName
, pattern
))
2807 /* filter system and hidden files */
2808 if (!(filter_flags
&TF_HIDDEN
) && (entry
->data
.dwFileAttributes
&(FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
)))
2811 /* filter looking at the file type */
2812 if ((filter_flags
&(TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
)) != (TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
))
2813 switch(get_file_type(entry
->data
.cFileName
)) {
2815 if (!(filter_flags
& TF_PROGRAMS
))
2820 if (!(filter_flags
& TF_DOCUMENTS
))
2824 default: /* TF_OTHERS */
2825 if (!(filter_flags
& TF_OTHERS
))
2832 (void)ListBox_InsertItemData(pane
->hwnd
, idx
, entry
);
2834 if (pane
->treePane
&& entry
->expanded
)
2835 idx
= insert_entries(pane
, entry
->down
, pattern
, filter_flags
, idx
);
2838 ShowWindow(pane
->hwnd
, SW_SHOW
);
2844 static void format_bytes(LPTSTR buffer
, LONGLONG bytes
)
2846 const static TCHAR sFmtGB
[] = {'%', '.', '1', 'f', ' ', 'G', 'B', '\0'};
2847 const static TCHAR sFmtMB
[] = {'%', '.', '1', 'f', ' ', 'M', 'B', '\0'};
2848 const static TCHAR sFmtkB
[] = {'%', '.', '1', 'f', ' ', 'k', 'B', '\0'};
2850 float fBytes
= (float)bytes
;
2852 #ifdef __WINE__ /* work around for incorrect implementation of wsprintf()/_stprintf() in WINE */
2853 if (bytes
>= 1073741824) /* 1 GB */
2854 wsprintf(buffer
, sFmtGB
, fBytes
/1073741824.f
+.5f
);
2855 else if (bytes
>= 1048576) /* 1 MB */
2856 wsprintf(buffer
, sFmtMB
, fBytes
/1048576.f
+.5f
);
2857 else if (bytes
>= 1024) /* 1 kB */
2858 wsprintf(buffer
, sFmtkB
, fBytes
/1024.f
+.5f
);
2860 if (bytes
>= 1073741824) /* 1 GB */
2861 _stprintf(buffer
, sFmtGB
, fBytes
/1073741824.f
+.5f
);
2862 else if (bytes
>= 1048576) /* 1 MB */
2863 _stprintf(buffer
, sFmtMB
, fBytes
/1048576.f
+.5f
);
2864 else if (bytes
>= 1024) /* 1 kB */
2865 _stprintf(buffer
, sFmtkB
, fBytes
/1024.f
+.5f
);
2868 _stprintf(buffer
, sLongNumFmt
, bytes
);
2871 static void set_space_status(void)
2873 ULARGE_INTEGER ulFreeBytesToCaller
, ulTotalBytes
, ulFreeBytes
;
2874 TCHAR fmt
[64], b1
[64], b2
[64], buffer
[BUFFER_LEN
];
2876 if (GetDiskFreeSpaceEx(NULL
, &ulFreeBytesToCaller
, &ulTotalBytes
, &ulFreeBytes
)) {
2877 format_bytes(b1
, ulFreeBytesToCaller
.QuadPart
);
2878 format_bytes(b2
, ulTotalBytes
.QuadPart
);
2879 wsprintf(buffer
, RS(fmt
,IDS_FREE_SPACE_FMT
), b1
, b2
);
2881 lstrcpy(buffer
, sQMarks
);
2883 SendMessage(Globals
.hstatusbar
, SB_SETTEXT
, 0, (LPARAM
)buffer
);
2887 static WNDPROC g_orgTreeWndProc
;
2889 static void create_tree_window(HWND parent
, Pane
* pane
, int id
, int id_header
, LPCTSTR pattern
, int filter_flags
)
2891 const static TCHAR sListBox
[] = {'L','i','s','t','B','o','x','\0'};
2893 static int s_init
= 0;
2894 Entry
* entry
= pane
->root
;
2896 pane
->hwnd
= CreateWindow(sListBox
, sEmpty
, WS_CHILD
|WS_VISIBLE
|WS_HSCROLL
|WS_VSCROLL
|
2897 LBS_DISABLENOSCROLL
|LBS_NOINTEGRALHEIGHT
|LBS_OWNERDRAWFIXED
|LBS_NOTIFY
,
2898 0, 0, 0, 0, parent
, (HMENU
)id
, Globals
.hInstance
, 0);
2900 SetWindowLongPtr(pane
->hwnd
, GWLP_USERDATA
, (LPARAM
)pane
);
2901 g_orgTreeWndProc
= SubclassWindow(pane
->hwnd
, TreeWndProc
);
2903 SetWindowFont(pane
->hwnd
, Globals
.hfont
, FALSE
);
2905 /* insert entries into listbox */
2907 insert_entries(pane
, entry
, pattern
, filter_flags
, -1);
2909 /* calculate column widths */
2912 init_output(pane
->hwnd
);
2915 calc_widths(pane
, TRUE
);
2917 #ifndef _NO_EXTENSIONS
2918 pane
->hwndHeader
= create_header(parent
, pane
, id_header
);
2923 static void InitChildWindow(ChildWnd
* child
)
2925 create_tree_window(child
->hwnd
, &child
->left
, IDW_TREE_LEFT
, IDW_HEADER_LEFT
, NULL
, TF_ALL
);
2926 create_tree_window(child
->hwnd
, &child
->right
, IDW_TREE_RIGHT
, IDW_HEADER_RIGHT
, child
->filter_pattern
, child
->filter_flags
);
2930 static void format_date(const FILETIME
* ft
, TCHAR
* buffer
, int visible_cols
)
2936 *buffer
= TEXT('\0');
2938 if (!ft
->dwLowDateTime
&& !ft
->dwHighDateTime
)
2941 if (!FileTimeToLocalFileTime(ft
, &lft
))
2942 {err
: lstrcpy(buffer
,sQMarks
); return;}
2944 if (!FileTimeToSystemTime(&lft
, &systime
))
2947 if (visible_cols
& COL_DATE
) {
2948 len
= GetDateFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
, BUFFER_LEN
);
2953 if (visible_cols
& COL_TIME
) {
2955 buffer
[len
-1] = ' ';
2957 buffer
[len
++] = ' ';
2959 if (!GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
+len
, BUFFER_LEN
-len
))
2960 buffer
[len
] = TEXT('\0');
2965 static void calc_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2967 RECT rt
= {0, 0, 0, 0};
2969 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
2971 if (rt
.right
> pane
->widths
[col
])
2972 pane
->widths
[col
] = rt
.right
;
2975 static void calc_tabbed_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2977 RECT rt
= {0, 0, 0, 0};
2979 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2980 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2982 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2983 /*FIXME rt (0,0) ??? */
2985 if (rt
.right
> pane
->widths
[col
])
2986 pane
->widths
[col
] = rt
.right
;
2990 static void output_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
, DWORD flags
)
2992 int x
= dis
->rcItem
.left
;
2995 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2996 rt
.top
= dis
->rcItem
.top
;
2997 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2998 rt
.bottom
= dis
->rcItem
.bottom
;
3000 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_SINGLELINE
|DT_NOPREFIX
|flags
);
3003 static void output_tabbed_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3005 int x
= dis
->rcItem
.left
;
3008 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
3009 rt
.top
= dis
->rcItem
.top
;
3010 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
3011 rt
.bottom
= dis
->rcItem
.bottom
;
3013 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
3014 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
3016 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
3019 static void output_number(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3021 int x
= dis
->rcItem
.left
;
3028 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
3029 rt
.top
= dis
->rcItem
.top
;
3030 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
3031 rt
.bottom
= dis
->rcItem
.bottom
;
3036 /* insert number separator characters */
3037 pos
= lstrlen(s
) % 3;
3043 *d
++ = Globals
.num_sep
;
3047 DrawText(dis
->hDC
, b
, d
-b
, &rt
, DT_RIGHT
|DT_SINGLELINE
|DT_NOPREFIX
|DT_END_ELLIPSIS
);
3051 static BOOL
is_exe_file(LPCTSTR ext
)
3053 static const TCHAR executable_extensions
[][4] = {
3058 #ifndef _NO_EXTENSIONS
3062 #endif /* _NO_EXTENSIONS */
3066 TCHAR ext_buffer
[_MAX_EXT
];
3067 const TCHAR (*p
)[4];
3071 for(s
=ext
+1,d
=ext_buffer
; (*d
=tolower(*s
)); s
++)
3074 for(p
=executable_extensions
; (*p
)[0]; p
++)
3075 if (!lstrcmpi(ext_buffer
, *p
))
3081 static BOOL
is_registered_type(LPCTSTR ext
)
3083 /* check if there exists a classname for this file extension in the registry */
3084 if (!RegQueryValue(HKEY_CLASSES_ROOT
, ext
, NULL
, NULL
))
3090 static enum FILE_TYPE
get_file_type(LPCTSTR filename
)
3092 LPCTSTR ext
= _tcsrchr(filename
, '.');
3096 if (is_exe_file(ext
))
3097 return FT_EXECUTABLE
;
3098 else if (is_registered_type(ext
))
3105 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
)
3107 TCHAR buffer
[BUFFER_LEN
];
3109 int visible_cols
= pane
->visible_cols
;
3110 COLORREF bkcolor
, textcolor
;
3111 RECT focusRect
= dis
->rcItem
;
3118 attrs
= entry
->data
.dwFileAttributes
;
3120 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) {
3121 if (entry
->data
.cFileName
[0]==TEXT('.') && entry
->data
.cFileName
[1]==TEXT('.')
3122 && entry
->data
.cFileName
[2]==TEXT('\0'))
3123 img
= IMG_FOLDER_UP
;
3124 #ifndef _NO_EXTENSIONS
3125 else if (entry
->data
.cFileName
[0]==TEXT('.') && entry
->data
.cFileName
[1]==TEXT('\0'))
3126 img
= IMG_FOLDER_CUR
;
3129 #ifdef _NO_EXTENSIONS
3132 (pane
->treePane
&& (dis
->itemState
&ODS_FOCUS
)))
3133 img
= IMG_OPEN_FOLDER
;
3137 switch(get_file_type(entry
->data
.cFileName
)) {
3138 case FT_EXECUTABLE
: img
= IMG_EXECUTABLE
; break;
3139 case FT_DOCUMENT
: img
= IMG_DOCUMENT
; break;
3140 default: img
= IMG_FILE
;
3148 if (pane
->treePane
) {
3150 img_pos
= dis
->rcItem
.left
+ entry
->level
*(IMAGE_WIDTH
+TREE_LINE_DX
);
3152 if (calcWidthCol
== -1) {
3154 int y
= dis
->rcItem
.top
+ IMAGE_HEIGHT
/2;
3157 HRGN hrgn_org
= CreateRectRgn(0, 0, 0, 0);
3160 rt_clip
.left
= dis
->rcItem
.left
;
3161 rt_clip
.top
= dis
->rcItem
.top
;
3162 rt_clip
.right
= dis
->rcItem
.left
+pane
->widths
[col
];
3163 rt_clip
.bottom
= dis
->rcItem
.bottom
;
3165 hrgn
= CreateRectRgnIndirect(&rt_clip
);
3167 if (!GetClipRgn(dis
->hDC
, hrgn_org
)) {
3168 DeleteObject(hrgn_org
);
3172 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
3173 ExtSelectClipRgn(dis
->hDC
, hrgn
, RGN_AND
);
3176 if ((up
=entry
->up
) != NULL
) {
3177 MoveToEx(dis
->hDC
, img_pos
-IMAGE_WIDTH
/2, y
, 0);
3178 LineTo(dis
->hDC
, img_pos
-2, y
);
3180 x
= img_pos
- IMAGE_WIDTH
/2;
3183 x
-= IMAGE_WIDTH
+TREE_LINE_DX
;
3187 && (up
->next
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
3190 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
3191 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
3193 } while((up
=up
->up
) != NULL
);
3196 x
= img_pos
- IMAGE_WIDTH
/2;
3198 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
3199 LineTo(dis
->hDC
, x
, y
);
3203 && (entry
->next
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
)
3206 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
3208 SelectClipRgn(dis
->hDC
, hrgn_org
);
3209 if (hrgn_org
) DeleteObject(hrgn_org
);
3210 /* SelectObject(dis->hDC, holdPen); */
3211 } else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
) {
3212 int right
= img_pos
+ IMAGE_WIDTH
- TREE_LINE_DX
;
3214 if (right
> pane
->widths
[col
])
3215 pane
->widths
[col
] = right
;
3218 img_pos
= dis
->rcItem
.left
;
3221 img_pos
= dis
->rcItem
.left
;
3223 if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3224 pane
->widths
[col
] = IMAGE_WIDTH
;
3227 if (calcWidthCol
== -1) {
3228 focusRect
.left
= img_pos
- 2;
3230 #ifdef _NO_EXTENSIONS
3231 if (pane
->treePane
&& entry
) {
3234 DrawText(dis
->hDC
, entry
->data
.cFileName
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
3236 focusRect
.right
= dis
->rcItem
.left
+pane
->positions
[col
+1]+TREE_LINE_DX
+ rt
.right
+2;
3240 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
)
3241 textcolor
= COLOR_COMPRESSED
;
3243 #endif /* _NO_EXTENSIONS */
3244 textcolor
= RGB(0,0,0);
3246 if (dis
->itemState
& ODS_FOCUS
) {
3247 textcolor
= COLOR_SELECTION_TXT
;
3248 bkcolor
= COLOR_SELECTION
;
3250 bkcolor
= GetSysColor(COLOR_WINDOW
);
3253 hbrush
= CreateSolidBrush(bkcolor
);
3254 FillRect(dis
->hDC
, &focusRect
, hbrush
);
3255 DeleteObject(hbrush
);
3257 SetBkMode(dis
->hDC
, TRANSPARENT
);
3258 SetTextColor(dis
->hDC
, textcolor
);
3260 cx
= pane
->widths
[col
];
3262 if (cx
&& img
!=IMG_NONE
) {
3263 if (cx
> IMAGE_WIDTH
)
3266 #ifdef _SHELL_FOLDERS
3267 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
3268 DrawIconEx(dis
->hDC
, img_pos
, dis
->rcItem
.top
, entry
->hicon
, cx
, GetSystemMetrics(SM_CYSMICON
), 0, 0, DI_NORMAL
);
3271 ImageList_DrawEx(Globals
.himl
, img
, dis
->hDC
,
3272 img_pos
, dis
->rcItem
.top
, cx
,
3273 IMAGE_HEIGHT
, bkcolor
, CLR_DEFAULT
, ILD_NORMAL
);
3280 #ifdef _NO_EXTENSIONS
3281 if (img
>= IMG_FOLDER_UP
)
3287 /* ouput file name */
3288 if (calcWidthCol
== -1)
3289 output_text(pane
, dis
, col
, entry
->data
.cFileName
, 0);
3290 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3291 calc_width(pane
, dis
, col
, entry
->data
.cFileName
);
3295 #ifdef _NO_EXTENSIONS
3296 if (!pane
->treePane
) {
3299 /* display file size */
3300 if (visible_cols
& COL_SIZE
) {
3301 #ifdef _NO_EXTENSIONS
3302 if (!(attrs
&FILE_ATTRIBUTE_DIRECTORY
))
3307 size
= ((ULONGLONG
)entry
->data
.nFileSizeHigh
<< 32) | entry
->data
.nFileSizeLow
;
3309 _stprintf(buffer
, sLongNumFmt
, size
);
3311 if (calcWidthCol
== -1)
3312 output_number(pane
, dis
, col
, buffer
);
3313 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3314 calc_width(pane
, dis
, col
, buffer
);/*TODO: not in every case time enough */
3320 /* display file date */
3321 if (visible_cols
& (COL_DATE
|COL_TIME
)) {
3322 #ifndef _NO_EXTENSIONS
3323 format_date(&entry
->data
.ftCreationTime
, buffer
, visible_cols
);
3324 if (calcWidthCol
== -1)
3325 output_text(pane
, dis
, col
, buffer
, 0);
3326 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3327 calc_width(pane
, dis
, col
, buffer
);
3330 format_date(&entry
->data
.ftLastAccessTime
, buffer
, visible_cols
);
3331 if (calcWidthCol
== -1)
3332 output_text(pane
, dis
, col
, buffer
, 0);
3333 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3334 calc_width(pane
, dis
, col
, buffer
);
3336 #endif /* _NO_EXTENSIONS */
3338 format_date(&entry
->data
.ftLastWriteTime
, buffer
, visible_cols
);
3339 if (calcWidthCol
== -1)
3340 output_text(pane
, dis
, col
, buffer
, 0);
3341 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3342 calc_width(pane
, dis
, col
, buffer
);
3346 #ifndef _NO_EXTENSIONS
3347 if (entry
->bhfi_valid
) {
3348 ULONGLONG index
= ((ULONGLONG
)entry
->bhfi
.nFileIndexHigh
<< 32) | entry
->bhfi
.nFileIndexLow
;
3350 if (visible_cols
& COL_INDEX
) {
3351 _stprintf(buffer
, sLongHexFmt
, index
);
3353 if (calcWidthCol
== -1)
3354 output_text(pane
, dis
, col
, buffer
, DT_RIGHT
);
3355 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3356 calc_width(pane
, dis
, col
, buffer
);
3361 if (visible_cols
& COL_LINKS
) {
3362 wsprintf(buffer
, sNumFmt
, entry
->bhfi
.nNumberOfLinks
);
3364 if (calcWidthCol
== -1)
3365 output_text(pane
, dis
, col
, buffer
, DT_CENTER
);
3366 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3367 calc_width(pane
, dis
, col
, buffer
);
3373 #endif /* _NO_EXTENSIONS */
3375 /* show file attributes */
3376 if (visible_cols
& COL_ATTRIBUTES
) {
3377 #ifdef _NO_EXTENSIONS
3378 const static TCHAR s4Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3379 lstrcpy(buffer
, s4Tabs
);
3381 const static TCHAR s11Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3382 lstrcpy(buffer
, s11Tabs
);
3385 if (attrs
& FILE_ATTRIBUTE_NORMAL
) buffer
[ 0] = 'N';
3387 if (attrs
& FILE_ATTRIBUTE_READONLY
) buffer
[ 2] = 'R';
3388 if (attrs
& FILE_ATTRIBUTE_HIDDEN
) buffer
[ 4] = 'H';
3389 if (attrs
& FILE_ATTRIBUTE_SYSTEM
) buffer
[ 6] = 'S';
3390 if (attrs
& FILE_ATTRIBUTE_ARCHIVE
) buffer
[ 8] = 'A';
3391 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
) buffer
[10] = 'C';
3392 #ifndef _NO_EXTENSIONS
3393 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) buffer
[12] = 'D';
3394 if (attrs
& FILE_ATTRIBUTE_ENCRYPTED
) buffer
[14] = 'E';
3395 if (attrs
& FILE_ATTRIBUTE_TEMPORARY
) buffer
[16] = 'T';
3396 if (attrs
& FILE_ATTRIBUTE_SPARSE_FILE
) buffer
[18] = 'P';
3397 if (attrs
& FILE_ATTRIBUTE_REPARSE_POINT
) buffer
[20] = 'Q';
3398 if (attrs
& FILE_ATTRIBUTE_OFFLINE
) buffer
[22] = 'O';
3399 if (attrs
& FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
) buffer
[24] = 'X';
3400 #endif /* _NO_EXTENSIONS */
3403 if (calcWidthCol
== -1)
3404 output_tabbed_text(pane
, dis
, col
, buffer
);
3405 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3406 calc_tabbed_width(pane
, dis
, col
, buffer
);
3412 if (flags.security) {
3413 const static TCHAR sSecTabs[] = {
3414 ' ','\t',' ','\t',' ','\t',' ',
3416 ' ','\t',' ','\t',' ','\t',' ',
3418 ' ','\t',' ','\t',' ','\t',' ',
3422 DWORD rights = get_access_mask();
3424 lstrcpy(buffer, sSecTabs);
3426 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
3427 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
3428 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
3429 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
3430 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
3431 if (rights & FILE_EXECUTE) buffer[12] = 'X';
3432 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
3433 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
3434 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
3435 if (rights & WRITE_DAC) buffer[22] = 'C';
3436 if (rights & WRITE_OWNER) buffer[24] = 'O';
3437 if (rights & SYNCHRONIZE) buffer[26] = 'S';
3439 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
3442 if (flags.description) {
3443 get_description(buffer);
3444 output_text(dis, col++, buffer, 0, psize);
3448 #ifdef _NO_EXTENSIONS
3451 /* draw focus frame */
3452 if ((dis
->itemState
&ODS_FOCUS
) && calcWidthCol
==-1) {
3453 /* Currently [04/2000] Wine neither behaves exactly the same */
3454 /* way as WIN 95 nor like Windows NT... */
3459 if (!(GetVersion() & 0x80000000)) { /* Windows NT or higher? */
3460 LOGBRUSH lb
= {PS_SOLID
, RGB(255,255,255)};
3461 hpen
= ExtCreatePen(PS_COSMETIC
|PS_ALTERNATE
, 1, &lb
, 0, 0);
3463 hpen
= CreatePen(PS_DOT
, 0, RGB(255,255,255));
3465 lastPen
= SelectPen(dis
->hDC
, hpen
);
3466 lastBrush
= SelectObject(dis
->hDC
, GetStockObject(HOLLOW_BRUSH
));
3467 SetROP2(dis
->hDC
, R2_XORPEN
);
3468 Rectangle(dis
->hDC
, focusRect
.left
, focusRect
.top
, focusRect
.right
, focusRect
.bottom
);
3469 SelectObject(dis
->hDC
, lastBrush
);
3470 SelectObject(dis
->hDC
, lastPen
);
3473 #endif /* _NO_EXTENSIONS */
3477 #ifdef _NO_EXTENSIONS
3479 static void draw_splitbar(HWND hwnd
, int x
)
3482 HDC hdc
= GetDC(hwnd
);
3484 GetClientRect(hwnd
, &rt
);
3486 rt
.left
= x
- SPLIT_WIDTH
/2;
3487 rt
.right
= x
+ SPLIT_WIDTH
/2+1;
3489 InvertRect(hdc
, &rt
);
3491 ReleaseDC(hwnd
, hdc
);
3494 #endif /* _NO_EXTENSIONS */
3497 #ifndef _NO_EXTENSIONS
3499 static void set_header(Pane
* pane
)
3502 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3505 item
.mask
= HDI_WIDTH
;
3508 for(; x
+pane
->widths
[i
]<scroll_pos
&& i
<COLUMNS
; i
++) {
3509 x
+= pane
->widths
[i
];
3510 (void)Header_SetItem(pane
->hwndHeader
, i
, &item
);
3514 x
+= pane
->widths
[i
];
3515 item
.cxy
= x
- scroll_pos
;
3516 (void)Header_SetItem(pane
->hwndHeader
, i
++, &item
);
3518 for(; i
<COLUMNS
; i
++) {
3519 item
.cxy
= pane
->widths
[i
];
3520 x
+= pane
->widths
[i
];
3521 (void)Header_SetItem(pane
->hwndHeader
, i
, &item
);
3526 static LRESULT
pane_notify(Pane
* pane
, NMHDR
* pnmh
)
3528 switch(pnmh
->code
) {
3530 case HDN_ENDTRACK
: {
3531 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3532 int idx
= phdn
->iItem
;
3533 int dx
= phdn
->pitem
->cxy
- pane
->widths
[idx
];
3537 GetClientRect(pane
->hwnd
, &clnt
);
3539 /* move immediate to simulate HDS_FULLDRAG (for now [04/2000] not really needed with WINELIB) */
3540 (void)Header_SetItem(pane
->hwndHeader
, idx
, phdn
->pitem
);
3542 pane
->widths
[idx
] += dx
;
3544 for(i
=idx
; ++i
<=COLUMNS
; )
3545 pane
->positions
[i
] += dx
;
3548 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3552 rt_scr
.left
= pane
->positions
[idx
+1]-scroll_pos
;
3554 rt_scr
.right
= clnt
.right
;
3555 rt_scr
.bottom
= clnt
.bottom
;
3557 rt_clip
.left
= pane
->positions
[idx
]-scroll_pos
;
3559 rt_clip
.right
= clnt
.right
;
3560 rt_clip
.bottom
= clnt
.bottom
;
3562 if (rt_scr
.left
< 0) rt_scr
.left
= 0;
3563 if (rt_clip
.left
< 0) rt_clip
.left
= 0;
3565 ScrollWindowEx(pane
->hwnd
, dx
, 0, &rt_scr
, &rt_clip
, 0, 0, SW_INVALIDATE
);
3567 rt_clip
.right
= pane
->positions
[idx
+1];
3568 RedrawWindow(pane
->hwnd
, &rt_clip
, 0, RDW_INVALIDATE
|RDW_UPDATENOW
);
3570 if (pnmh
->code
== HDN_ENDTRACK
) {
3571 ListBox_SetHorizontalExtent(pane
->hwnd
, pane
->positions
[COLUMNS
]);
3573 if (GetScrollPos(pane
->hwnd
, SB_HORZ
) != scroll_pos
)
3581 case HDN_DIVIDERDBLCLICK
: {
3582 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3585 calc_single_width(pane
, phdn
->iItem
);
3586 item
.mask
= HDI_WIDTH
;
3587 item
.cxy
= pane
->widths
[phdn
->iItem
];
3589 (void)Header_SetItem(pane
->hwndHeader
, phdn
->iItem
, &item
);
3590 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3597 #endif /* _NO_EXTENSIONS */
3600 static void scan_entry(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3602 TCHAR path
[MAX_PATH
];
3603 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
3605 /* delete sub entries in left pane */
3607 LRESULT res
= ListBox_GetItemData(child
->left
.hwnd
, idx
+1);
3608 Entry
* sub
= (Entry
*) res
;
3610 if (res
==LB_ERR
|| !sub
|| sub
->level
<=entry
->level
)
3613 (void)ListBox_DeleteString(child
->left
.hwnd
, idx
+1);
3616 /* empty right pane */
3617 (void)ListBox_ResetContent(child
->right
.hwnd
);
3619 /* release memory */
3620 free_entries(entry
);
3622 /* read contents from disk */
3623 #ifdef _SHELL_FOLDERS
3624 if (entry
->etype
== ET_SHELL
)
3626 read_directory(entry
, NULL
, child
->sortOrder
, hwnd
);
3631 get_path(entry
, path
);
3632 read_directory(entry
, path
, child
->sortOrder
, hwnd
);
3635 /* insert found entries in right pane */
3636 insert_entries(&child
->right
, entry
->down
, child
->filter_pattern
, child
->filter_flags
, -1);
3637 calc_widths(&child
->right
, FALSE
);
3638 #ifndef _NO_EXTENSIONS
3639 set_header(&child
->right
);
3642 child
->header_wdths_ok
= FALSE
;
3644 SetCursor(old_cursor
);
3648 /* expand a directory entry */
3650 static BOOL
expand_entry(ChildWnd
* child
, Entry
* dir
)
3655 if (!dir
|| dir
->expanded
|| !dir
->down
)
3660 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='\0' && p
->next
) {
3663 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='.' &&
3664 p
->data
.cFileName
[2]=='\0' && p
->next
)
3668 /* no subdirectories ? */
3669 if (!(p
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
3672 idx
= ListBox_FindItemData(child
->left
.hwnd
, 0, dir
);
3674 dir
->expanded
= TRUE
;
3676 /* insert entries in left pane */
3677 insert_entries(&child
->left
, p
, NULL
, TF_ALL
, idx
);
3679 if (!child
->header_wdths_ok
) {
3680 if (calc_widths(&child
->left
, FALSE
)) {
3681 #ifndef _NO_EXTENSIONS
3682 set_header(&child
->left
);
3685 child
->header_wdths_ok
= TRUE
;
3693 static void collapse_entry(Pane
* pane
, Entry
* dir
)
3695 int idx
= ListBox_FindItemData(pane
->hwnd
, 0, dir
);
3697 ShowWindow(pane
->hwnd
, SW_HIDE
);
3699 /* hide sub entries */
3701 LRESULT res
= ListBox_GetItemData(pane
->hwnd
, idx
+1);
3702 Entry
* sub
= (Entry
*) res
;
3704 if (res
==LB_ERR
|| !sub
|| sub
->level
<=dir
->level
)
3707 (void)ListBox_DeleteString(pane
->hwnd
, idx
+1);
3710 dir
->expanded
= FALSE
;
3712 ShowWindow(pane
->hwnd
, SW_SHOW
);
3716 static void refresh_right_pane(ChildWnd
* child
)
3718 (void)ListBox_ResetContent(child
->right
.hwnd
);
3719 insert_entries(&child
->right
, child
->right
.root
, child
->filter_pattern
, child
->filter_flags
, -1);
3720 calc_widths(&child
->right
, FALSE
);
3722 #ifndef _NO_EXTENSIONS
3723 set_header(&child
->right
);
3727 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3729 TCHAR path
[MAX_PATH
];
3736 child
->left
.cur
= entry
;
3738 child
->right
.root
= entry
->down
? entry
->down
: entry
;
3739 child
->right
.cur
= entry
;
3741 if (!entry
->scanned
)
3742 scan_entry(child
, entry
, idx
, hwnd
);
3744 refresh_right_pane(child
);
3746 get_path(entry
, path
);
3747 lstrcpy(child
->path
, path
);
3749 if (child
->hwnd
) /* only change window title, if the window already exists */
3750 SetWindowText(child
->hwnd
, path
);
3753 if (SetCurrentDirectory(path
))
3758 static void refresh_child(ChildWnd
* child
)
3760 TCHAR path
[MAX_PATH
], drv
[_MAX_DRIVE
+1];
3764 get_path(child
->left
.cur
, path
);
3765 _tsplitpath(path
, drv
, NULL
, NULL
, NULL
);
3767 child
->right
.root
= NULL
;
3769 scan_entry(child
, &child
->root
.entry
, 0, child
->hwnd
);
3771 #ifdef _SHELL_FOLDERS
3772 if (child
->root
.entry
.etype
== ET_SHELL
)
3773 entry
= read_tree(&child
->root
, NULL
, get_path_pidl(path
,child
->hwnd
), drv
, child
->sortOrder
, child
->hwnd
);
3776 entry
= read_tree(&child
->root
, path
, NULL
, drv
, child
->sortOrder
, child
->hwnd
);
3779 entry
= &child
->root
.entry
;
3781 insert_entries(&child
->left
, child
->root
.entry
.down
, NULL
, TF_ALL
, 0);
3783 set_curdir(child
, entry
, 0, child
->hwnd
);
3785 idx
= ListBox_FindItemData(child
->left
.hwnd
, 0, child
->left
.cur
);
3786 (void)ListBox_SetCurSel(child
->left
.hwnd
, idx
);
3790 static void create_drive_bar(void)
3792 TBBUTTON drivebarBtn
= {0, 0, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0};
3793 #ifndef _NO_EXTENSIONS
3794 TCHAR b1
[BUFFER_LEN
];
3799 GetLogicalDriveStrings(BUFFER_LEN
, Globals
.drives
);
3801 Globals
.hdrivebar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
,
3802 IDW_DRIVEBAR
, 2, Globals
.hInstance
, IDB_DRIVEBAR
, &drivebarBtn
,
3803 0, 16, 13, 16, 13, sizeof(TBBUTTON
));
3805 #ifndef _NO_EXTENSIONS
3807 /* insert unix file system button */
3811 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
3813 drivebarBtn
.idCommand
= ID_DRIVE_UNIX_FS
;
3814 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3815 drivebarBtn
.iString
++;
3817 #ifdef _SHELL_FOLDERS
3818 /* insert shell namespace button */
3819 load_string(b1
, IDS_SHELL
);
3820 b1
[lstrlen(b1
)+1] = '\0';
3821 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
3823 drivebarBtn
.idCommand
= ID_DRIVE_SHELL_NS
;
3824 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3825 drivebarBtn
.iString
++;
3828 /* register windows drive root strings */
3829 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)Globals
.drives
);
3832 drivebarBtn
.idCommand
= ID_DRIVE_FIRST
;
3834 for(p
=Globals
.drives
; *p
; ) {
3835 #ifdef _NO_EXTENSIONS
3836 /* insert drive letter */
3837 TCHAR b
[3] = {tolower(*p
)};
3838 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b
);
3840 switch(GetDriveType(p
)) {
3841 case DRIVE_REMOVABLE
: drivebarBtn
.iBitmap
= 1; break;
3842 case DRIVE_CDROM
: drivebarBtn
.iBitmap
= 3; break;
3843 case DRIVE_REMOTE
: drivebarBtn
.iBitmap
= 4; break;
3844 case DRIVE_RAMDISK
: drivebarBtn
.iBitmap
= 5; break;
3845 default:/*DRIVE_FIXED*/ drivebarBtn
.iBitmap
= 2;
3848 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3849 drivebarBtn
.idCommand
++;
3850 drivebarBtn
.iString
++;
3856 static void refresh_drives(void)
3860 /* destroy drive bar */
3861 DestroyWindow(Globals
.hdrivebar
);
3862 Globals
.hdrivebar
= 0;
3864 /* re-create drive bar */
3867 /* update window layout */
3868 GetClientRect(Globals
.hMainWnd
, &rect
);
3869 SendMessage(Globals
.hMainWnd
, WM_SIZE
, 0, MAKELONG(rect
.right
, rect
.bottom
));
3873 static BOOL
launch_file(HWND hwnd
, LPCTSTR cmd
, UINT nCmdShow
)
3875 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3877 if ((int)hinst
<= 32) {
3878 display_error(hwnd
, GetLastError());
3886 static BOOL
launch_entry(Entry
* entry
, HWND hwnd
, UINT nCmdShow
)
3888 TCHAR cmd
[MAX_PATH
];
3890 #ifdef _SHELL_FOLDERS
3891 if (entry
->etype
== ET_SHELL
) {
3894 SHELLEXECUTEINFO shexinfo
;
3896 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFO
);
3897 shexinfo
.fMask
= SEE_MASK_IDLIST
;
3898 shexinfo
.hwnd
= hwnd
;
3899 shexinfo
.lpVerb
= NULL
;
3900 shexinfo
.lpFile
= NULL
;
3901 shexinfo
.lpParameters
= NULL
;
3902 shexinfo
.lpDirectory
= NULL
;
3903 shexinfo
.nShow
= nCmdShow
;
3904 shexinfo
.lpIDList
= get_to_absolute_pidl(entry
, hwnd
);
3906 if (!ShellExecuteEx(&shexinfo
)) {
3907 display_error(hwnd
, GetLastError());
3911 if (shexinfo
.lpIDList
!= entry
->pidl
)
3912 IMalloc_Free(Globals
.iMalloc
, shexinfo
.lpIDList
);
3918 get_path(entry
, cmd
);
3920 /* start program, open document... */
3921 return launch_file(hwnd
, cmd
, nCmdShow
);
3925 static void activate_entry(ChildWnd
* child
, Pane
* pane
, HWND hwnd
)
3927 Entry
* entry
= pane
->cur
;
3932 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
3933 int scanned_old
= entry
->scanned
;
3936 scan_entry(child
, entry
, ListBox_GetCurSel(child
->left
.hwnd
), hwnd
);
3938 #ifndef _NO_EXTENSIONS
3939 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='\0')
3943 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='.' && entry
->data
.cFileName
[2]=='\0') {
3944 entry
= child
->left
.cur
->up
;
3945 collapse_entry(&child
->left
, entry
);
3947 } else if (entry
->expanded
)
3948 collapse_entry(pane
, child
->left
.cur
);
3950 expand_entry(child
, child
->left
.cur
);
3952 if (!pane
->treePane
) focus_entry
: {
3953 int idx
= ListBox_FindItemData(child
->left
.hwnd
, ListBox_GetCurSel(child
->left
.hwnd
), entry
);
3954 (void)ListBox_SetCurSel(child
->left
.hwnd
, idx
);
3955 set_curdir(child
, entry
, idx
, hwnd
);
3960 calc_widths(pane
, FALSE
);
3962 #ifndef _NO_EXTENSIONS
3967 if (GetKeyState(VK_MENU
) < 0)
3968 show_properties_dlg(entry
, child
->hwnd
);
3970 launch_entry(entry
, child
->hwnd
, SW_SHOWNORMAL
);
3975 static BOOL
pane_command(Pane
* pane
, UINT cmd
)
3979 if (pane
->visible_cols
) {
3980 pane
->visible_cols
= 0;
3981 calc_widths(pane
, TRUE
);
3982 #ifndef _NO_EXTENSIONS
3985 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3986 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
|MF_CHECKED
);
3987 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
);
3988 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
3992 case ID_VIEW_ALL_ATTRIBUTES
:
3993 if (pane
->visible_cols
!= COL_ALL
) {
3994 pane
->visible_cols
= COL_ALL
;
3995 calc_widths(pane
, TRUE
);
3996 #ifndef _NO_EXTENSIONS
3999 InvalidateRect(pane
->hwnd
, 0, TRUE
);
4000 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
);
4001 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
|MF_CHECKED
);
4002 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
4006 #ifndef _NO_EXTENSIONS
4007 case ID_PREFERRED_SIZES
: {
4008 calc_widths(pane
, TRUE
);
4010 InvalidateRect(pane
->hwnd
, 0, TRUE
);
4014 /* TODO: more command ids... */
4024 static void set_sort_order(ChildWnd
* child
, SORT_ORDER sortOrder
)
4026 if (child
->sortOrder
!= sortOrder
) {
4027 child
->sortOrder
= sortOrder
;
4028 refresh_child(child
);
4032 static void update_view_menu(ChildWnd
* child
)
4034 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_NAME
, child
->sortOrder
==SORT_NAME
? MF_CHECKED
: MF_UNCHECKED
);
4035 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_TYPE
, child
->sortOrder
==SORT_EXT
? MF_CHECKED
: MF_UNCHECKED
);
4036 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_SIZE
, child
->sortOrder
==SORT_SIZE
? MF_CHECKED
: MF_UNCHECKED
);
4037 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_DATE
, child
->sortOrder
==SORT_DATE
? MF_CHECKED
: MF_UNCHECKED
);
4041 static BOOL
is_directory(LPCTSTR target
)
4043 /*TODO correctly handle UNIX paths */
4044 DWORD target_attr
= GetFileAttributes(target
);
4046 if (target_attr
== INVALID_FILE_ATTRIBUTES
)
4049 return target_attr
&FILE_ATTRIBUTE_DIRECTORY
? TRUE
: FALSE
;
4052 static BOOL
prompt_target(Pane
* pane
, LPTSTR source
, LPTSTR target
)
4054 TCHAR path
[MAX_PATH
];
4057 get_path(pane
->cur
, path
);
4059 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_SELECT_DESTINATION
), pane
->hwnd
, DestinationDlgProc
, (LPARAM
)path
) != IDOK
)
4062 get_path(pane
->cur
, source
);
4064 /* convert relative targets to absolute paths */
4065 if (path
[0]!='/' && path
[1]!=':') {
4066 get_path(pane
->cur
->up
, target
);
4067 len
= lstrlen(target
);
4069 if (target
[len
-1]!='\\' && target
[len
-1]!='/')
4070 target
[len
++] = '/';
4072 lstrcpy(target
+len
, path
);
4074 lstrcpy(target
, path
);
4076 /* If the target already exists as directory, create a new target below this. */
4077 if (is_directory(path
)) {
4078 TCHAR fname
[_MAX_FNAME
], ext
[_MAX_EXT
];
4079 const static TCHAR sAppend
[] = {'%','s','/','%','s','%','s','\0'};
4081 _tsplitpath(source
, NULL
, NULL
, fname
, ext
);
4083 wsprintf(target
, sAppend
, path
, fname
, ext
);
4090 static IContextMenu2
* s_pctxmenu2
= NULL
;
4092 #ifndef __MINGW32__ /* IContextMenu3 missing in MinGW (as of 6.2.2005) */
4093 static IContextMenu3
* s_pctxmenu3
= NULL
;
4096 static void CtxMenu_reset(void)
4100 #ifndef __MINGW32__ /* IContextMenu3 missing in MinGW (as of 6.2.2005) */
4105 static IContextMenu
* CtxMenu_query_interfaces(IContextMenu
* pcm1
)
4107 IContextMenu
* pcm
= NULL
;
4111 #ifndef __MINGW32__ /* IContextMenu3 missing in MinGW (as of 6.2.2005) */
4112 if (IUnknown_QueryInterface(pcm1
, &IID_IContextMenu3
, (void**)&pcm
) == NOERROR
)
4113 s_pctxmenu3
= (LPCONTEXTMENU3
)pcm
;
4116 if (IUnknown_QueryInterface(pcm1
, &IID_IContextMenu2
, (void**)&pcm
) == NOERROR
)
4117 s_pctxmenu2
= (LPCONTEXTMENU2
)pcm
;
4120 IUnknown_Release(pcm1
);
4126 static BOOL
CtxMenu_HandleMenuMsg(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4128 #ifndef __MINGW32__ /* IContextMenu3 missing in MinGW (as of 6.2.2005) */
4130 if (SUCCEEDED((*s_pctxmenu3
->lpVtbl
->HandleMenuMsg
)(s_pctxmenu3
, nmsg
, wparam
, lparam
)))
4136 if (SUCCEEDED((*s_pctxmenu2
->lpVtbl
->HandleMenuMsg
)(s_pctxmenu2
, nmsg
, wparam
, lparam
)))
4143 static HRESULT
ShellFolderContextMenu(IShellFolder
* shell_folder
, HWND hwndParent
, int cidl
, LPCITEMIDLIST
* apidl
, int x
, int y
)
4146 BOOL executed
= FALSE
;
4148 HRESULT hr
= IShellFolder_GetUIObjectOf(shell_folder
, hwndParent
, cidl
, apidl
, &IID_IContextMenu
, NULL
, (LPVOID
*)&pcm
);
4149 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
4151 if (SUCCEEDED(hr
)) {
4152 HMENU hmenu
= CreatePopupMenu();
4154 pcm
= CtxMenu_query_interfaces(pcm
);
4157 hr
= (*pcm
->lpVtbl
->QueryContextMenu
)(pcm
, hmenu
, 0, FCIDM_SHVIEWFIRST
, FCIDM_SHVIEWLAST
, CMF_NORMAL
);
4159 if (SUCCEEDED(hr
)) {
4160 UINT idCmd
= TrackPopupMenu(hmenu
, TPM_LEFTALIGN
|TPM_RETURNCMD
|TPM_RIGHTBUTTON
, x
, y
, 0, hwndParent
, NULL
);
4165 CMINVOKECOMMANDINFO cmi
;
4167 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFO
);
4169 cmi
.hwnd
= hwndParent
;
4170 cmi
.lpVerb
= (LPCSTR
)(INT_PTR
)(idCmd
- FCIDM_SHVIEWFIRST
);
4171 cmi
.lpParameters
= NULL
;
4172 cmi
.lpDirectory
= NULL
;
4173 cmi
.nShow
= SW_SHOWNORMAL
;
4177 hr
= (*pcm
->lpVtbl
->InvokeCommand
)(pcm
, &cmi
);
4184 IUnknown_Release(pcm
);
4187 return FAILED(hr
)? hr
: executed
? S_OK
: S_FALSE
;
4191 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4193 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
4198 LPDRAWITEMSTRUCT dis
= (LPDRAWITEMSTRUCT
)lparam
;
4199 Entry
* entry
= (Entry
*) dis
->itemData
;
4201 if (dis
->CtlID
== IDW_TREE_LEFT
)
4202 draw_item(&child
->left
, dis
, entry
, -1);
4203 else if (dis
->CtlID
== IDW_TREE_RIGHT
)
4204 draw_item(&child
->right
, dis
, entry
, -1);
4206 goto draw_menu_item
;
4211 InitChildWindow(child
);
4215 free_child_window(child
);
4216 SetWindowLongPtr(hwnd
, GWLP_USERDATA
, 0);
4223 GetClientRect(hwnd
, &rt
);
4224 BeginPaint(hwnd
, &ps
);
4225 rt
.left
= child
->split_pos
-SPLIT_WIDTH
/2;
4226 rt
.right
= child
->split_pos
+SPLIT_WIDTH
/2+1;
4227 lastBrush
= SelectBrush(ps
.hdc
, (HBRUSH
)GetStockObject(COLOR_SPLITBAR
));
4228 Rectangle(ps
.hdc
, rt
.left
, rt
.top
-1, rt
.right
, rt
.bottom
+1);
4229 SelectObject(ps
.hdc
, lastBrush
);
4230 #ifdef _NO_EXTENSIONS
4231 rt
.top
= rt
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
4232 FillRect(ps
.hdc
, &rt
, GetStockObject(BLACK_BRUSH
));
4234 EndPaint(hwnd
, &ps
);
4238 if (LOWORD(lparam
) == HTCLIENT
) {
4241 ScreenToClient(hwnd
, &pt
);
4243 if (pt
.x
>=child
->split_pos
-SPLIT_WIDTH
/2 && pt
.x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
4244 SetCursor(LoadCursor(0, IDC_SIZEWE
));
4250 case WM_LBUTTONDOWN
: {
4252 int x
= GET_X_LPARAM(lparam
);
4254 GetClientRect(hwnd
, &rt
);
4256 if (x
>=child
->split_pos
-SPLIT_WIDTH
/2 && x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
4257 last_split
= child
->split_pos
;
4258 #ifdef _NO_EXTENSIONS
4259 draw_splitbar(hwnd
, last_split
);
4267 if (GetCapture() == hwnd
) {
4268 #ifdef _NO_EXTENSIONS
4270 int x
= LOWORD(lparam
);
4271 draw_splitbar(hwnd
, last_split
);
4273 GetClientRect(hwnd
, &rt
);
4274 child
->split_pos
= x
;
4275 resize_tree(child
, rt
.right
, rt
.bottom
);
4281 #ifdef _NO_EXTENSIONS
4282 case WM_CAPTURECHANGED
:
4283 if (GetCapture()==hwnd
&& last_split
>=0)
4284 draw_splitbar(hwnd
, last_split
);
4289 if (wparam
== VK_ESCAPE
)
4290 if (GetCapture() == hwnd
) {
4292 #ifdef _NO_EXTENSIONS
4293 draw_splitbar(hwnd
, last_split
);
4295 child
->split_pos
= last_split
;
4297 GetClientRect(hwnd
, &rt
);
4298 resize_tree(child
, rt
.right
, rt
.bottom
);
4301 SetCursor(LoadCursor(0, IDC_ARROW
));
4306 if (GetCapture() == hwnd
) {
4308 int x
= LOWORD(lparam
);
4310 #ifdef _NO_EXTENSIONS
4311 HDC hdc
= GetDC(hwnd
);
4312 GetClientRect(hwnd
, &rt
);
4314 rt
.left
= last_split
-SPLIT_WIDTH
/2;
4315 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
4316 InvertRect(hdc
, &rt
);
4319 rt
.left
= x
-SPLIT_WIDTH
/2;
4320 rt
.right
= x
+SPLIT_WIDTH
/2+1;
4321 InvertRect(hdc
, &rt
);
4323 ReleaseDC(hwnd
, hdc
);
4325 GetClientRect(hwnd
, &rt
);
4327 if (x
>=0 && x
<rt
.right
) {
4328 child
->split_pos
= x
;
4329 resize_tree(child
, rt
.right
, rt
.bottom
);
4330 rt
.left
= x
-SPLIT_WIDTH
/2;
4331 rt
.right
= x
+SPLIT_WIDTH
/2+1;
4332 InvalidateRect(hwnd
, &rt
, FALSE
);
4333 UpdateWindow(child
->left
.hwnd
);
4335 UpdateWindow(child
->right
.hwnd
);
4341 #ifndef _NO_EXTENSIONS
4342 case WM_GETMINMAXINFO
:
4343 DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
4345 {LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
4347 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
4348 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
4350 #endif /* _NO_EXTENSIONS */
4353 if (SetCurrentDirectory(child
->path
))
4355 SetFocus(child
->focus_pane
? child
->right
.hwnd
: child
->left
.hwnd
);
4358 case WM_DISPATCH_COMMAND
: {
4359 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4361 switch(LOWORD(wparam
)) {
4362 case ID_WINDOW_NEW
: {
4363 ChildWnd
* new_child
= alloc_child_window(child
->path
, NULL
, hwnd
);
4365 if (!create_child_window(new_child
))
4372 refresh_child(child
);
4376 activate_entry(child
, pane
, hwnd
);
4379 case ID_FILE_MOVE
: {
4380 TCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
4382 if (prompt_target(pane
, source
, target
)) {
4383 SHFILEOPSTRUCT shfo
= {hwnd
, FO_MOVE
, source
, target
};
4385 source
[lstrlen(source
)+1] = '\0';
4386 target
[lstrlen(target
)+1] = '\0';
4388 if (!SHFileOperation(&shfo
))
4389 refresh_child(child
);
4393 case ID_FILE_COPY
: {
4394 TCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
4396 if (prompt_target(pane
, source
, target
)) {
4397 SHFILEOPSTRUCT shfo
= {hwnd
, FO_COPY
, source
, target
};
4399 source
[lstrlen(source
)+1] = '\0';
4400 target
[lstrlen(target
)+1] = '\0';
4402 if (!SHFileOperation(&shfo
))
4403 refresh_child(child
);
4407 case ID_FILE_DELETE
: {
4408 TCHAR path
[BUFFER_LEN
];
4409 SHFILEOPSTRUCT shfo
= {hwnd
, FO_DELETE
, path
};
4411 get_path(pane
->cur
, path
);
4413 path
[lstrlen(path
)+1] = '\0';
4415 if (!SHFileOperation(&shfo
))
4416 refresh_child(child
);
4419 case ID_VIEW_SORT_NAME
:
4420 set_sort_order(child
, SORT_NAME
);
4423 case ID_VIEW_SORT_TYPE
:
4424 set_sort_order(child
, SORT_EXT
);
4427 case ID_VIEW_SORT_SIZE
:
4428 set_sort_order(child
, SORT_SIZE
);
4431 case ID_VIEW_SORT_DATE
:
4432 set_sort_order(child
, SORT_DATE
);
4435 case ID_VIEW_FILTER
: {
4436 struct FilterDialog dlg
;
4438 memset(&dlg
, 0, sizeof(struct FilterDialog
));
4439 lstrcpy(dlg
.pattern
, child
->filter_pattern
);
4440 dlg
.flags
= child
->filter_flags
;
4442 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE
), hwnd
, FilterDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
4443 lstrcpy(child
->filter_pattern
, dlg
.pattern
);
4444 child
->filter_flags
= dlg
.flags
;
4445 refresh_right_pane(child
);
4449 case ID_VIEW_SPLIT
: {
4450 last_split
= child
->split_pos
;
4451 #ifdef _NO_EXTENSIONS
4452 draw_splitbar(hwnd
, last_split
);
4457 case ID_EDIT_PROPERTIES
:
4458 show_properties_dlg(pane
->cur
, child
->hwnd
);
4462 return pane_command(pane
, LOWORD(wparam
));
4468 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4470 switch(HIWORD(wparam
)) {
4471 case LBN_SELCHANGE
: {
4472 int idx
= ListBox_GetCurSel(pane
->hwnd
);
4473 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, idx
);
4475 if (pane
== &child
->left
)
4476 set_curdir(child
, entry
, idx
, hwnd
);
4482 activate_entry(child
, pane
, hwnd
);
4487 #ifndef _NO_EXTENSIONS
4489 NMHDR
* pnmh
= (NMHDR
*) lparam
;
4490 return pane_notify(pnmh
->idFrom
==IDW_HEADER_LEFT
? &child
->left
: &child
->right
, pnmh
);}
4493 #ifdef _SHELL_FOLDERS
4494 case WM_CONTEXTMENU
: {
4499 /* first select the current item in the listbox */
4500 HWND hpanel
= (HWND
) wparam
;
4501 pt_clnt
.x
= pt
.x
= (short)LOWORD(lparam
);
4502 pt_clnt
.y
= pt
.y
= (short)HIWORD(lparam
);
4503 ScreenToClient(hpanel
, &pt_clnt
);
4504 SendMessage(hpanel
, WM_LBUTTONDOWN
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4505 SendMessage(hpanel
, WM_LBUTTONUP
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4507 /* now create the popup menu using shell namespace and IContextMenu */
4508 pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4509 idx
= ListBox_GetCurSel(pane
->hwnd
);
4512 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, idx
);
4514 LPITEMIDLIST pidl_abs
= get_to_absolute_pidl(entry
, hwnd
);
4517 IShellFolder
* parentFolder
;
4518 LPCITEMIDLIST pidlLast
;
4520 /* get and use the parent folder to display correct context menu in all cases */
4521 if (SUCCEEDED(SHBindToParent(pidl_abs
, &IID_IShellFolder
, (LPVOID
*)&parentFolder
, &pidlLast
))) {
4522 if (ShellFolderContextMenu(parentFolder
, hwnd
, 1, &pidlLast
, pt
.x
, pt
.y
) == S_OK
)
4523 refresh_child(child
);
4525 IShellFolder_Release(parentFolder
);
4528 IMalloc_Free(Globals
.iMalloc
, pidl_abs
);
4534 case WM_MEASUREITEM
:
4536 if (!wparam
) /* Is the message menu-related? */
4537 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4542 case WM_INITMENUPOPUP
:
4543 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4546 update_view_menu(child
);
4549 #ifndef __MINGW32__ /* IContextMenu3 missing in MinGW (as of 6.2.2005) */
4550 case WM_MENUCHAR
: /* only supported by IContextMenu3 */
4552 LRESULT lResult
= 0;
4554 (*s_pctxmenu3
->lpVtbl
->HandleMenuMsg2
)(s_pctxmenu3
, nmsg
, wparam
, lparam
, &lResult
);
4563 if (wparam
!= SIZE_MINIMIZED
)
4564 resize_tree(child
, LOWORD(lparam
), HIWORD(lparam
));
4568 return DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
4575 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4577 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(GetParent(hwnd
), GWLP_USERDATA
);
4578 Pane
* pane
= (Pane
*) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
4582 #ifndef _NO_EXTENSIONS
4589 child
->focus_pane
= pane
==&child
->right
? 1: 0;
4590 (void)ListBox_SetSel(hwnd
, TRUE
, 1);
4591 /*TODO: check menu items */
4595 if (wparam
== VK_TAB
) {
4596 /*TODO: SetFocus(Globals.hdrivebar) */
4597 SetFocus(child
->focus_pane
? child
->left
.hwnd
: child
->right
.hwnd
);
4601 return CallWindowProc(g_orgTreeWndProc
, hwnd
, nmsg
, wparam
, lparam
);
4605 static void InitInstance(HINSTANCE hinstance
)
4607 const static TCHAR sFont
[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4614 INITCOMMONCONTROLSEX icc
= {
4615 sizeof(INITCOMMONCONTROLSEX
),
4621 setlocale(LC_COLLATE
, ""); /* set collating rules to local settings for compareName */
4623 InitCommonControlsEx(&icc
);
4626 /* register frame window class */
4628 wcFrame
.cbSize
= sizeof(WNDCLASSEX
);
4630 wcFrame
.lpfnWndProc
= FrameWndProc
;
4631 wcFrame
.cbClsExtra
= 0;
4632 wcFrame
.cbWndExtra
= 0;
4633 wcFrame
.hInstance
= hinstance
;
4634 wcFrame
.hIcon
= LoadIcon(hinstance
, MAKEINTRESOURCE(IDI_WINEFILE
));
4635 wcFrame
.hCursor
= LoadCursor(0, IDC_ARROW
);
4636 wcFrame
.hbrBackground
= 0;
4637 wcFrame
.lpszMenuName
= 0;
4638 wcFrame
.lpszClassName
= sWINEFILEFRAME
;
4639 wcFrame
.hIconSm
= (HICON
)LoadImage(hinstance
,
4640 MAKEINTRESOURCE(IDI_WINEFILE
),
4642 GetSystemMetrics(SM_CXSMICON
),
4643 GetSystemMetrics(SM_CYSMICON
),
4646 Globals
.hframeClass
= RegisterClassEx(&wcFrame
);
4649 /* register tree windows class */
4651 wcChild
.style
= CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
;
4652 wcChild
.lpfnWndProc
= ChildWndProc
;
4653 wcChild
.cbClsExtra
= 0;
4654 wcChild
.cbWndExtra
= 0;
4655 wcChild
.hInstance
= hinstance
;
4657 wcChild
.hCursor
= LoadCursor(0, IDC_ARROW
);
4658 wcChild
.hbrBackground
= 0;
4659 wcChild
.lpszMenuName
= 0;
4660 wcChild
.lpszClassName
= sWINEFILETREE
;
4662 hChildClass
= RegisterClass(&wcChild
);
4665 Globals
.haccel
= LoadAccelerators(hinstance
, MAKEINTRESOURCE(IDA_WINEFILE
));
4667 Globals
.hfont
= CreateFont(-MulDiv(8,GetDeviceCaps(hdc
,LOGPIXELSY
),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont
);
4671 Globals
.hInstance
= hinstance
;
4673 #ifdef _SHELL_FOLDERS
4675 CoGetMalloc(MEMCTX_TASK
, &Globals
.iMalloc
);
4676 SHGetDesktopFolder(&Globals
.iDesktop
);
4678 Globals
.cfStrFName
= RegisterClipboardFormatA(CFSTR_FILENAME
);
4680 Globals
.cfStrFName
= RegisterClipboardFormat(CFSTR_FILENAME
);
4684 /* load column strings */
4687 load_string(g_pos_names
[col
++], IDS_COL_NAME
);
4688 load_string(g_pos_names
[col
++], IDS_COL_SIZE
);
4689 load_string(g_pos_names
[col
++], IDS_COL_CDATE
);
4690 #ifndef _NO_EXTENSIONS
4691 load_string(g_pos_names
[col
++], IDS_COL_ADATE
);
4692 load_string(g_pos_names
[col
++], IDS_COL_MDATE
);
4693 load_string(g_pos_names
[col
++], IDS_COL_IDX
);
4694 load_string(g_pos_names
[col
++], IDS_COL_LINKS
);
4696 load_string(g_pos_names
[col
++], IDS_COL_ATTR
);
4697 #ifndef _NO_EXTENSIONS
4698 load_string(g_pos_names
[col
++], IDS_COL_SEC
);
4703 static void show_frame(HWND hwndParent
, int cmdshow
, LPCTSTR path
)
4705 const static TCHAR sMDICLIENT
[] = {'M','D','I','C','L','I','E','N','T','\0'};
4707 TCHAR buffer
[MAX_PATH
], b1
[BUFFER_LEN
];
4709 HMENU hMenuFrame
, hMenuWindow
;
4711 CLIENTCREATESTRUCT ccs
;
4713 if (Globals
.hMainWnd
)
4716 hMenuFrame
= LoadMenu(Globals
.hInstance
, MAKEINTRESOURCE(IDM_WINEFILE
));
4717 hMenuWindow
= GetSubMenu(hMenuFrame
, GetMenuItemCount(hMenuFrame
)-2);
4719 Globals
.hMenuFrame
= hMenuFrame
;
4720 Globals
.hMenuView
= GetSubMenu(hMenuFrame
, 3);
4721 Globals
.hMenuOptions
= GetSubMenu(hMenuFrame
, 4);
4723 ccs
.hWindowMenu
= hMenuWindow
;
4724 ccs
.idFirstChild
= IDW_FIRST_CHILD
;
4727 /* create main window */
4728 Globals
.hMainWnd
= CreateWindowEx(0, (LPCTSTR
)(int)Globals
.hframeClass
, RS(b1
,IDS_WINE_FILE
), WS_OVERLAPPEDWINDOW
,
4729 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
4730 hwndParent
, Globals
.hMenuFrame
, Globals
.hInstance
, 0/*lpParam*/);
4733 Globals
.hmdiclient
= CreateWindowEx(0, sMDICLIENT
, NULL
,
4734 WS_CHILD
|WS_CLIPCHILDREN
|WS_VSCROLL
|WS_HSCROLL
|WS_VISIBLE
|WS_BORDER
,
4736 Globals
.hMainWnd
, 0, Globals
.hInstance
, &ccs
);
4739 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_DRIVE_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4744 TBBUTTON toolbarBtns
[] = {
4745 {0, 0, 0, BTNS_SEP
, {0, 0}, 0, 0},
4746 {0, ID_WINDOW_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4747 {1, ID_WINDOW_CASCADE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4748 {2, ID_WINDOW_TILE_HORZ
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4749 {3, ID_WINDOW_TILE_VERT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4751 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4752 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4755 Globals
.htoolbar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
,
4756 IDW_TOOLBAR
, 2, Globals
.hInstance
, IDB_TOOLBAR
, toolbarBtns
,
4757 sizeof(toolbarBtns
)/sizeof(TBBUTTON
), 16, 15, 16, 15, sizeof(TBBUTTON
));
4758 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_TOOL_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4761 Globals
.hstatusbar
= CreateStatusWindow(WS_CHILD
|WS_VISIBLE
, 0, Globals
.hMainWnd
, IDW_STATUSBAR
);
4762 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
4764 /* CreateStatusWindow does not accept WS_BORDER
4765 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
4766 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
4767 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
4769 /*TODO: read paths and window placements from registry */
4771 if (!path
|| !*path
) {
4772 GetCurrentDirectory(MAX_PATH
, buffer
);
4776 ShowWindow(Globals
.hMainWnd
, cmdshow
);
4778 //#if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4779 // // Shell Namespace as default:
4780 // child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
4782 child
= alloc_child_window(path
, NULL
, Globals
.hMainWnd
);
4785 child
->pos
.showCmd
= SW_SHOWMAXIMIZED
;
4786 child
->pos
.rcNormalPosition
.left
= 0;
4787 child
->pos
.rcNormalPosition
.top
= 0;
4788 child
->pos
.rcNormalPosition
.right
= 320;
4789 child
->pos
.rcNormalPosition
.bottom
= 280;
4791 if (!create_child_window(child
))
4794 SetWindowPlacement(child
->hwnd
, &child
->pos
);
4796 Globals
.himl
= ImageList_LoadBitmap(Globals
.hInstance
, MAKEINTRESOURCE(IDB_IMAGES
), 16, 0, RGB(0,255,0));
4798 Globals
.prescan_node
= FALSE
;
4800 UpdateWindow(Globals
.hMainWnd
);
4802 if (path
&& path
[0])
4805 TCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
4806 TCHAR fullname
[_MAX_FNAME
+_MAX_EXT
+1];
4808 memset(name
,0,sizeof(name
));
4809 memset(name
,0,sizeof(ext
));
4810 _tsplitpath(path
, drv
, dir
, name
, ext
);
4813 count
= ListBox_GetCount(child
->right
.hwnd
);
4814 lstrcpy(fullname
,name
);
4815 lstrcat(fullname
,ext
);
4817 for (index
= 0; index
< count
; index
++)
4819 Entry
* entry
= (Entry
*) ListBox_GetItemData(child
->right
.hwnd
,
4821 if (lstrcmp(entry
->data
.cFileName
,fullname
)==0 ||
4822 lstrcmp(entry
->data
.cAlternateFileName
,fullname
)==0)
4824 (void)ListBox_SetCurSel(child
->right
.hwnd
, index
);
4825 SetFocus(child
->right
.hwnd
);
4833 static void ExitInstance(void)
4835 #ifdef _SHELL_FOLDERS
4836 IShellFolder_Release(Globals
.iDesktop
);
4837 IMalloc_Release(Globals
.iMalloc
);
4841 DeleteObject(Globals
.hfont
);
4842 ImageList_Destroy(Globals
.himl
);
4845 #ifdef _NO_EXTENSIONS
4847 /* search for already running win[e]files */
4849 static int g_foundPrevInstance
= 0;
4851 static BOOL CALLBACK
EnumWndProc(HWND hwnd
, LPARAM lparam
)
4855 GetClassName(hwnd
, cls
, 128);
4857 if (!lstrcmp(cls
, (LPCTSTR
)lparam
)) {
4858 g_foundPrevInstance
++;
4865 /* search for window of given class name to allow only one running instance */
4866 static int find_window_class(LPCTSTR classname
)
4868 EnumWindows(EnumWndProc
, (LPARAM
)classname
);
4870 if (g_foundPrevInstance
)
4878 static int winefile_main(HINSTANCE hinstance
, int cmdshow
, LPCTSTR path
)
4882 InitInstance(hinstance
);
4884 if (cmdshow
== SW_SHOWNORMAL
)
4885 /*TODO: read window placement from registry */
4886 cmdshow
= SW_MAXIMIZE
;
4888 show_frame(0, cmdshow
, path
);
4890 while(GetMessage(&msg
, 0, 0, 0)) {
4891 if (Globals
.hmdiclient
&& TranslateMDISysAccel(Globals
.hmdiclient
, &msg
))
4894 if (Globals
.hMainWnd
&& TranslateAccelerator(Globals
.hMainWnd
, Globals
.haccel
, &msg
))
4897 TranslateMessage(&msg
);
4898 DispatchMessage(&msg
);
4907 #if defined(UNICODE) && defined(_MSC_VER)
4908 int APIENTRY
wWinMain(HINSTANCE hinstance
, HINSTANCE previnstance
, LPWSTR cmdline
, int cmdshow
)
4910 int APIENTRY
WinMain(HINSTANCE hinstance
, HINSTANCE previnstance
, LPSTR cmdline
, int cmdshow
)
4913 #ifdef _NO_EXTENSIONS
4914 if (find_window_class(sWINEFILEFRAME
))
4918 #if defined(UNICODE) && !defined(_MSC_VER)
4919 { /* convert ANSI cmdline into WCS path string */
4920 TCHAR buffer
[MAX_PATH
];
4921 MultiByteToWideChar(CP_ACP
, 0, cmdline
, -1, buffer
, MAX_PATH
);
4922 winefile_main(hinstance
, cmdshow
, buffer
);
4925 winefile_main(hinstance
, cmdshow
, cmdline
);