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
32 #define _MAX_FNAME 256
33 #define _MAX_DIR _MAX_FNAME
34 #define _MAX_EXT _MAX_FNAME
38 #ifdef NONAMELESSUNION
39 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
41 #define UNION_MEMBER(x) x
46 #define DEFAULT_SPLIT_POS 300
48 #define DEFAULT_SPLIT_POS 200
60 typedef struct _Entry
{
71 #ifndef _NO_EXTENSIONS
72 BY_HANDLE_FILE_INFORMATION bhfi
;
74 enum ENTRY_TYPE etype
;
86 TCHAR volname
[_MAX_FNAME
];
96 COL_ATTRIBUTES
= 0x08,
99 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
103 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
|COL_INDEX
|COL_LINKS
116 #ifndef _NO_EXTENSIONS
120 #ifndef _NO_EXTENSIONS
126 int positions
[COLUMNS
+1];
138 int focus_pane
; /* 0: left 1: right */
141 BOOL header_wdths_ok
;
143 TCHAR path
[MAX_PATH
];
146 SORT_ORDER sortOrder
;
150 extern void WineLicense(HWND hwnd
);
151 extern void WineWarranty(HWND hwnd
);
156 /* functions in unixcalls.c */
158 extern void call_getcwd(char* buffer
, size_t len
);
159 extern void* call_opendir(const char* path
);
160 extern int call_readdir(void* pdir
, char* name
, unsigned* pinode
);
161 extern void call_closedir(void* pdir
);
163 extern int call_stat(
164 const char* path
, int* pis_dir
,
165 unsigned long* psize_low
, unsigned long* psize_high
,
166 time_t* patime
, time_t* pmtime
,
167 unsigned long* plinks
170 /* call vswprintf() in msvcrt.dll */
171 int swprintf(wchar_t* buffer
, const wchar_t* fmt
, ...)
173 static int (__cdecl
*vswprintf
)(wchar_t*, const wchar_t*, va_list);
179 HMODULE hmod
= LoadLibraryA("msvcrt");
180 vswprintf
= (int(__cdecl
*)(wchar_t*,const wchar_t*,va_list)) GetProcAddress(hmod
, "vswprintf");
184 ret
= vswprintf(buffer
, fmt
, ap
);
191 #define TMP_ALLOC(s) HeapAlloc(GetProcessHeap(), 0, s)
192 #define TMP_FREE(p) HeapFree(GetProcessHeap(), 0, p)
196 #define TMP_ALLOC(s) alloca(s)
202 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
);
203 static void set_curdir(ChildWnd
* child
, Entry
* entry
, HWND hwnd
);
204 static void get_path(Entry
* dir
, PTSTR path
);
206 LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
207 LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
208 LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
212 WINEFILE_GLOBALS Globals
;
215 /* some common string constants */
216 const static TCHAR sEmpty
[] = {'\0'};
217 const static TCHAR sSpace
[] = {' ', '\0'};
218 const static TCHAR sNumFmt
[] = {'%','d','\0'};
219 const static TCHAR sQMarks
[] = {'?','?','?','\0'};
221 /* window class names */
222 const static TCHAR sWINEFILEFRAME
[] = {'W','F','S','_','F','r','a','m','e','\0'};
223 const static TCHAR sWINEFILETREE
[] = {'W','F','S','_','T','r','e','e','\0'};
226 /* #define LONGLONGARG _T("I64") */
227 const static TCHAR sLongHexFmt
[] = {'%','I','6','4','X','\0'};
228 const static TCHAR sLongNumFmt
[] = {'%','I','6','4','d','\0'};
230 /* #define LONGLONGARG _T("L") */
231 const static TCHAR sLongHexFmt
[] = {'%','L','X','\0'};
232 const static TCHAR sLongNumFmt
[] = {'%','L','d','\0'};
236 /* load resource string */
237 static LPTSTR
load_string(LPTSTR buffer
, UINT id
)
239 LoadString(Globals
.hInstance
, id
, buffer
, BUFFER_LEN
);
244 #define RS(b, i) load_string(b, i)
247 /* display error message for the specified WIN32 error code */
248 static void display_error(HWND hwnd
, DWORD error
)
250 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
253 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_FROM_SYSTEM
,
254 0, error
, MAKELANGID(LANG_NEUTRAL
,SUBLANG_DEFAULT
), (PTSTR
)&msg
, 0, NULL
))
255 MessageBox(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
257 MessageBox(hwnd
, RS(b1
,IDS_ERROR
), RS(b2
,IDS_WINEFILE
), MB_OK
);
263 /* display network error message using WNetGetLastError() */
264 static void display_network_error(HWND hwnd
)
266 TCHAR msg
[BUFFER_LEN
], provider
[BUFFER_LEN
], b2
[BUFFER_LEN
];
269 if (WNetGetLastError(&error
, msg
, BUFFER_LEN
, provider
, BUFFER_LEN
) == NO_ERROR
)
270 MessageBox(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
274 /* allocate and initialise a directory entry */
275 static Entry
* alloc_entry()
277 Entry
* entry
= (Entry
*) malloc(sizeof(Entry
));
279 #ifdef _SHELL_FOLDERS
281 entry
->folder
= NULL
;
288 /* free a directory entry */
289 static void free_entry(Entry
* entry
)
291 #ifdef _SHELL_FOLDERS
292 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
293 DestroyIcon(entry
->hicon
);
295 if (entry
->folder
&& entry
->folder
!=Globals
.iDesktop
)
296 (*entry
->folder
->lpVtbl
->Release
)(entry
->folder
);
299 (*Globals
.iMalloc
->lpVtbl
->Free
)(Globals
.iMalloc
, entry
->pidl
);
305 /* recursively free all child entries */
306 static void free_entries(Entry
* dir
)
308 Entry
*entry
, *next
=dir
->down
;
324 static void read_directory_win(Entry
* dir
, LPCTSTR path
)
326 Entry
* first_entry
= NULL
;
330 int level
= dir
->level
+ 1;
331 WIN32_FIND_DATA w32fd
;
333 #ifndef _NO_EXTENSIONS
337 TCHAR buffer
[MAX_PATH
], *p
;
338 for(p
=buffer
; *path
; )
345 hFind
= FindFirstFile(buffer
, &w32fd
);
347 if (hFind
!= INVALID_HANDLE_VALUE
) {
349 entry
= alloc_entry();
357 memcpy(&entry
->data
, &w32fd
, sizeof(WIN32_FIND_DATA
));
360 entry
->expanded
= FALSE
;
361 entry
->scanned
= FALSE
;
362 entry
->level
= level
;
364 #ifdef _NO_EXTENSIONS
365 /* hide directory entry "." */
366 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
367 LPCTSTR name
= entry
->data
.cFileName
;
369 if (name
[0]=='.' && name
[1]=='\0')
373 entry
->etype
= ET_WINDOWS
;
374 entry
->bhfi_valid
= FALSE
;
376 lstrcpy(p
, entry
->data
.cFileName
);
378 hFile
= CreateFile(buffer
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
379 0, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0);
381 if (hFile
!= INVALID_HANDLE_VALUE
) {
382 if (GetFileInformationByHandle(hFile
, &entry
->bhfi
))
383 entry
->bhfi_valid
= TRUE
;
390 } while(FindNextFile(hFind
, &entry
->data
));
397 dir
->down
= first_entry
;
402 static Entry
* find_entry_win(Entry
* dir
, LPCTSTR name
)
406 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
408 LPCTSTR q
= entry
->data
.cFileName
;
411 if (!*p
|| *p
==TEXT('\\') || *p
==TEXT('/'))
413 } while(tolower(*p
++) == tolower(*q
++));
416 q
= entry
->data
.cAlternateFileName
;
419 if (!*p
|| *p
==TEXT('\\') || *p
==TEXT('/'))
421 } while(tolower(*p
++) == tolower(*q
++));
428 static Entry
* read_tree_win(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
430 TCHAR buffer
[MAX_PATH
];
431 Entry
* entry
= &root
->entry
;
435 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
437 #ifndef _NO_EXTENSIONS
438 entry
->etype
= ET_WINDOWS
;
442 while(*s
&& *s
!=TEXT('\\') && *s
!=TEXT('/'))
445 while(*s
==TEXT('\\') || *s
==TEXT('/'))
451 read_directory(entry
, buffer
, sortOrder
, hwnd
);
454 entry
->expanded
= TRUE
;
459 entry
= find_entry_win(entry
, s
);
462 SetCursor(old_cursor
);
468 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
470 static BOOL
time_to_filetime(const time_t* t
, FILETIME
* ftime
)
472 struct tm
* tm
= gmtime(t
);
478 stime
.wYear
= tm
->tm_year
+1900;
479 stime
.wMonth
= tm
->tm_mon
+1;
480 /* stime.wDayOfWeek */
481 stime
.wDay
= tm
->tm_mday
;
482 stime
.wHour
= tm
->tm_hour
;
483 stime
.wMinute
= tm
->tm_min
;
484 stime
.wSecond
= tm
->tm_sec
;
486 return SystemTimeToFileTime(&stime
, ftime
);
489 static void read_directory_unix(Entry
* dir
, LPCTSTR path
)
491 Entry
* first_entry
= NULL
;
497 char cpath
[MAX_PATH
];
499 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, cpath
, MAX_PATH
, NULL
, NULL
);
501 const char* cpath
= path
;
504 pdir
= call_opendir(cpath
);
506 int level
= dir
->level
+ 1;
509 char buffer
[MAX_PATH
];
516 for(p
=buffer
,s
=cpath
; *s
; )
519 if (p
==buffer
|| p
[-1]!='/')
522 while(call_readdir(pdir
, p
, &inode
)) {
523 entry
= alloc_entry();
531 entry
->etype
= ET_UNIX
;
534 MultiByteToWideChar(CP_UNIXCP
, 0, p
, -1, entry
->data
.cFileName
, MAX_PATH
);
536 lstrcpy(entry
->data
.cFileName
, p
);
539 entry
->data
.dwFileAttributes
= p
[0]=='.'? FILE_ATTRIBUTE_HIDDEN
: 0;
541 if (!call_stat(buffer
, &is_dir
,
542 &entry
->data
.nFileSizeLow
, &entry
->data
.nFileSizeHigh
,
543 &atime
, &mtime
, &entry
->bhfi
.nNumberOfLinks
))
546 entry
->data
.dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
548 memset(&entry
->data
.ftCreationTime
, 0, sizeof(FILETIME
));
549 time_to_filetime(&atime
, &entry
->data
.ftLastAccessTime
);
550 time_to_filetime(&mtime
, &entry
->data
.ftLastWriteTime
);
552 entry
->bhfi
.nFileIndexLow
= inode
;
553 entry
->bhfi
.nFileIndexHigh
= 0;
555 entry
->bhfi_valid
= TRUE
;
557 entry
->data
.nFileSizeLow
= 0;
558 entry
->data
.nFileSizeHigh
= 0;
559 entry
->bhfi_valid
= FALSE
;
564 entry
->expanded
= FALSE
;
565 entry
->scanned
= FALSE
;
566 entry
->level
= level
;
576 dir
->down
= first_entry
;
580 static Entry
* find_entry_unix(Entry
* dir
, LPCTSTR name
)
584 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
586 LPCTSTR q
= entry
->data
.cFileName
;
589 if (!*p
|| *p
==TEXT('/'))
591 } while(*p
++ == *q
++);
597 static Entry
* read_tree_unix(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
599 TCHAR buffer
[MAX_PATH
];
600 Entry
* entry
= &root
->entry
;
604 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
606 entry
->etype
= ET_UNIX
;
609 while(*s
&& *s
!=TEXT('/'))
612 while(*s
== TEXT('/'))
618 read_directory(entry
, buffer
, sortOrder
, hwnd
);
621 entry
->expanded
= TRUE
;
626 entry
= find_entry_unix(entry
, s
);
629 SetCursor(old_cursor
);
634 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
637 #ifdef _SHELL_FOLDERS
640 #define tcscpyn strcpyn
641 #define get_strret get_strretW
642 #define path_from_pidl path_from_pidlW
644 #define tcscpyn wcscpyn
645 #define get_strret get_strretA
646 #define path_from_pidl path_from_pidlA
650 static LPSTR
strcpyn(LPSTR dest
, LPCSTR source
, size_t count
)
655 for(s
=source
; count
&&(*d
++=*s
++); )
661 static LPWSTR
wcscpyn(LPWSTR dest
, LPCWSTR source
, size_t count
)
666 for(s
=source
; count
&&(*d
++=*s
++); )
673 static void get_strretA(STRRET
* str
, const SHITEMID
* shiid
, LPSTR buffer
, int len
)
677 WideCharToMultiByte(CP_ACP
, 0, str
->UNION_MEMBER(pOleStr
), -1, buffer
, len
, NULL
, NULL
);
681 strcpyn(buffer
, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), len
);
685 strcpyn(buffer
, str
->UNION_MEMBER(cStr
), len
);
689 static void get_strretW(STRRET
* str
, const SHITEMID
* shiid
, LPWSTR buffer
, int len
)
693 wcscpyn(buffer
, str
->UNION_MEMBER(pOleStr
), len
);
697 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), -1, buffer
, len
);
701 MultiByteToWideChar(CP_ACP
, 0, str
->UNION_MEMBER(cStr
), -1, buffer
, len
);
706 static void free_strret(STRRET
* str
)
708 if (str
->uType
== STRRET_WSTR
)
709 (*Globals
.iMalloc
->lpVtbl
->Free
)(Globals
.iMalloc
, str
->UNION_MEMBER(pOleStr
));
713 HRESULT
name_from_pidl(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPTSTR buffer
, int len
, SHGDNF flags
)
717 HRESULT hr
= (*folder
->lpVtbl
->GetDisplayNameOf
)(folder
, pidl
, flags
, &str
);
720 get_strret(&str
, &pidl
->mkid
, buffer
, len
);
729 HRESULT
path_from_pidlA(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPSTR buffer
, int len
)
733 /* SHGDN_FORPARSING: get full path of id list */
734 HRESULT hr
= (*folder
->lpVtbl
->GetDisplayNameOf
)(folder
, pidl
, SHGDN_FORPARSING
, &str
);
737 get_strretA(&str
, &pidl
->mkid
, buffer
, len
);
745 HRESULT
path_from_pidlW(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPWSTR buffer
, int len
)
749 /* SHGDN_FORPARSING: get full path of id list */
750 HRESULT hr
= (*folder
->lpVtbl
->GetDisplayNameOf
)(folder
, pidl
, SHGDN_FORPARSING
, &str
);
753 get_strretW(&str
, &pidl
->mkid
, buffer
, len
);
762 /* create an item id list from a file system path */
764 static LPITEMIDLIST
get_path_pidl(LPTSTR path
, HWND hwnd
)
771 LPWSTR buffer
= path
;
773 WCHAR buffer
[MAX_PATH
];
774 MultiByteToWideChar(CP_ACP
, 0, path
, -1, buffer
, MAX_PATH
);
777 hr
= (*Globals
.iDesktop
->lpVtbl
->ParseDisplayName
)(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
785 /* convert an item id list from relative to absolute (=relative to the desktop) format */
787 static LPITEMIDLIST
get_to_absolute_pidl(Entry
* entry
, HWND hwnd
)
789 if (entry
->up
&& entry
->up
->etype
==ET_SHELL
) {
790 IShellFolder
* folder
= entry
->up
->folder
;
791 WCHAR buffer
[MAX_PATH
];
793 HRESULT hr
= path_from_pidlW(folder
, entry
->pidl
, buffer
, MAX_PATH
);
799 hr
= (*Globals
.iDesktop
->lpVtbl
->ParseDisplayName
)(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
804 } else if (entry
->etype
== ET_WINDOWS
) {
805 TCHAR path
[MAX_PATH
];
807 get_path(entry
, path
);
809 return get_path_pidl(path
, hwnd
);
810 } else if (entry
->pidl
)
811 return ILClone(entry
->pidl
);
817 HICON
extract_icon(IShellFolder
* folder
, LPCITEMIDLIST pidl
)
819 IExtractIcon
* pExtract
;
821 if (SUCCEEDED((*folder
->lpVtbl
->GetUIObjectOf
)(folder
, 0, 1, (LPCITEMIDLIST
*)&pidl
, &IID_IExtractIcon
, 0, (LPVOID
*)&pExtract
))) {
822 TCHAR path
[_MAX_PATH
];
827 if (SUCCEEDED((*pExtract
->lpVtbl
->GetIconLocation
)(pExtract
, GIL_FORSHELL
, path
, _MAX_PATH
, &idx
, &flags
))) {
828 if (!(flags
& GIL_NOTFILENAME
)) {
830 idx
= 0; /* special case for some control panel applications */
832 if ((int)ExtractIconEx(path
, idx
, 0, &hicon
, 1) > 0)
833 flags
&= ~GIL_DONTCACHE
;
835 HICON hIconLarge
= 0;
837 HRESULT hr
= (*pExtract
->lpVtbl
->Extract
)(pExtract
, path
, idx
, &hIconLarge
, &hicon
, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON
)));
840 DestroyIcon(hIconLarge
);
851 static Entry
* find_entry_shell(Entry
* dir
, LPCITEMIDLIST pidl
)
855 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
856 if (entry
->pidl
->mkid
.cb
== pidl
->mkid
.cb
&&
857 !memcmp(entry
->pidl
, pidl
, entry
->pidl
->mkid
.cb
))
864 static Entry
* read_tree_shell(Root
* root
, LPITEMIDLIST pidl
, SORT_ORDER sortOrder
, HWND hwnd
)
866 Entry
* entry
= &root
->entry
;
868 LPITEMIDLIST next_pidl
= pidl
;
869 IShellFolder
* folder
;
870 IShellFolder
* child
= NULL
;
873 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
875 #ifndef _NO_EXTENSIONS
876 entry
->etype
= ET_SHELL
;
879 folder
= Globals
.iDesktop
;
882 entry
->pidl
= next_pidl
;
883 entry
->folder
= folder
;
888 /* copy first element of item idlist */
889 next_pidl
= (*Globals
.iMalloc
->lpVtbl
->Alloc
)(Globals
.iMalloc
, pidl
->mkid
.cb
+sizeof(USHORT
));
890 memcpy(next_pidl
, pidl
, pidl
->mkid
.cb
);
891 ((LPITEMIDLIST
)((LPBYTE
)next_pidl
+pidl
->mkid
.cb
))->mkid
.cb
= 0;
893 hr
= (*folder
->lpVtbl
->BindToObject
)(folder
, next_pidl
, 0, &IID_IShellFolder
, (void**)&child
);
897 read_directory(entry
, NULL
, sortOrder
, hwnd
);
900 entry
->expanded
= TRUE
;
902 next
= find_entry_shell(entry
, next_pidl
);
909 /* go to next element */
910 pidl
= (LPITEMIDLIST
) ((LPBYTE
)pidl
+pidl
->mkid
.cb
);
913 SetCursor(old_cursor
);
919 static void fill_w32fdata_shell(IShellFolder
* folder
, LPCITEMIDLIST pidl
, SFGAOF attribs
, WIN32_FIND_DATA
* w32fdata
)
921 if (!(attribs
& SFGAO_FILESYSTEM
) ||
922 FAILED(SHGetDataFromIDList(folder
, pidl
, SHGDFIL_FINDDATA
, w32fdata
, sizeof(WIN32_FIND_DATA
)))) {
923 WIN32_FILE_ATTRIBUTE_DATA fad
;
924 IDataObject
* pDataObj
;
926 STGMEDIUM medium
= {0, {0}, 0};
927 FORMATETC fmt
= {Globals
.cfStrFName
, 0, DVASPECT_CONTENT
, -1, TYMED_HGLOBAL
};
929 HRESULT hr
= (*folder
->lpVtbl
->GetUIObjectOf
)(folder
, 0, 1, &pidl
, &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
932 hr
= (*pDataObj
->lpVtbl
->GetData
)(pDataObj
, &fmt
, &medium
);
934 (*pDataObj
->lpVtbl
->Release
)(pDataObj
);
937 LPCTSTR path
= (LPCTSTR
)GlobalLock(medium
.UNION_MEMBER(hGlobal
));
938 UINT sem_org
= SetErrorMode(SEM_FAILCRITICALERRORS
);
940 if (GetFileAttributesEx(path
, GetFileExInfoStandard
, &fad
)) {
941 w32fdata
->dwFileAttributes
= fad
.dwFileAttributes
;
942 w32fdata
->ftCreationTime
= fad
.ftCreationTime
;
943 w32fdata
->ftLastAccessTime
= fad
.ftLastAccessTime
;
944 w32fdata
->ftLastWriteTime
= fad
.ftLastWriteTime
;
946 if (!(fad
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)) {
947 w32fdata
->nFileSizeLow
= fad
.nFileSizeLow
;
948 w32fdata
->nFileSizeHigh
= fad
.nFileSizeHigh
;
952 SetErrorMode(sem_org
);
954 GlobalUnlock(medium
.UNION_MEMBER(hGlobal
));
955 GlobalFree(medium
.UNION_MEMBER(hGlobal
));
960 if (attribs
& (SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
))
961 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
963 if (attribs
& SFGAO_READONLY
)
964 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_READONLY
;
966 if (attribs
& SFGAO_COMPRESSED
)
967 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_COMPRESSED
;
971 static void read_directory_shell(Entry
* dir
, HWND hwnd
)
973 IShellFolder
* folder
= dir
->folder
;
974 int level
= dir
->level
+ 1;
980 Entry
* first_entry
= NULL
;
987 hr
= (*folder
->lpVtbl
->EnumObjects
)(folder
, hwnd
, SHCONTF_FOLDERS
|SHCONTF_NONFOLDERS
|SHCONTF_INCLUDEHIDDEN
|SHCONTF_SHAREABLE
|SHCONTF_STORAGE
, &idlist
);
991 #define FETCH_ITEM_COUNT 32
992 LPITEMIDLIST pidls
[FETCH_ITEM_COUNT
];
997 memset(pidls
, 0, sizeof(pidls
));
999 hr
= (*idlist
->lpVtbl
->Next
)(idlist
, FETCH_ITEM_COUNT
, pidls
, &cnt
);
1006 for(n
=0; n
<cnt
; ++n
) {
1007 entry
= alloc_entry();
1010 first_entry
= entry
;
1015 memset(&entry
->data
, 0, sizeof(WIN32_FIND_DATA
));
1016 entry
->bhfi_valid
= FALSE
;
1018 attribs
= ~SFGAO_FILESYSTEM
; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
1020 hr
= (*folder
->lpVtbl
->GetAttributesOf
)(folder
, 1, (LPCITEMIDLIST
*)&pidls
[n
], &attribs
);
1022 if (SUCCEEDED(hr
)) {
1023 if (attribs
!= (SFGAOF
)~SFGAO_FILESYSTEM
) {
1024 fill_w32fdata_shell(folder
, pidls
[n
], attribs
, &entry
->data
);
1026 entry
->bhfi_valid
= TRUE
;
1032 entry
->pidl
= pidls
[n
];
1034 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1035 hr
= (*folder
->lpVtbl
->BindToObject
)(folder
, pidls
[n
], 0, &IID_IShellFolder
, (void**)&child
);
1038 entry
->folder
= child
;
1040 entry
->folder
= NULL
;
1043 entry
->folder
= NULL
;
1045 if (!entry
->data
.cFileName
[0])
1046 /*hr = */name_from_pidl(folder
, pidls
[n
], entry
->data
.cFileName
, MAX_PATH
, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1048 /* get display icons for files and virtual objects */
1049 if (!(entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ||
1050 !(attribs
& SFGAO_FILESYSTEM
)) {
1051 entry
->hicon
= extract_icon(folder
, pidls
[n
]);
1054 entry
->hicon
= (HICON
)-1; /* don't try again later */
1059 entry
->expanded
= FALSE
;
1060 entry
->scanned
= FALSE
;
1061 entry
->level
= level
;
1063 #ifndef _NO_EXTENSIONS
1064 entry
->etype
= ET_SHELL
;
1065 entry
->bhfi_valid
= FALSE
;
1072 (*idlist
->lpVtbl
->Release
)(idlist
);
1078 dir
->down
= first_entry
;
1079 dir
->scanned
= TRUE
;
1082 #endif /* _SHELL_FOLDERS */
1085 /* sort order for different directory/file types */
1094 /* distinguish between ".", ".." and any other directory names */
1095 static int TypeOrderFromDirname(LPCTSTR name
)
1097 if (name
[0] == '.') {
1098 if (name
[1] == '\0')
1099 return TO_DOT
; /* "." */
1101 if (name
[1]=='.' && name
[2]=='\0')
1102 return TO_DOTDOT
; /* ".." */
1105 return TO_OTHER_DIR
; /* anything else */
1108 /* directories first... */
1109 static int compareType(const WIN32_FIND_DATA
* fd1
, const WIN32_FIND_DATA
* fd2
)
1111 int order1
= fd1
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1112 int order2
= fd2
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1114 /* Handle "." and ".." as special case and move them at the very first beginning. */
1115 if (order1
==TO_DIR
&& order2
==TO_DIR
) {
1116 order1
= TypeOrderFromDirname(fd1
->cFileName
);
1117 order2
= TypeOrderFromDirname(fd2
->cFileName
);
1120 return order2
==order1
? 0: order1
<order2
? -1: 1;
1124 static int compareName(const void* arg1
, const void* arg2
)
1126 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1127 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1129 int cmp
= compareType(fd1
, fd2
);
1133 return lstrcmpi(fd1
->cFileName
, fd2
->cFileName
);
1136 static int compareExt(const void* arg1
, const void* arg2
)
1138 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1139 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1140 const TCHAR
*name1
, *name2
, *ext1
, *ext2
;
1142 int cmp
= compareType(fd1
, fd2
);
1146 name1
= fd1
->cFileName
;
1147 name2
= fd2
->cFileName
;
1149 ext1
= _tcsrchr(name1
, TEXT('.'));
1150 ext2
= _tcsrchr(name2
, TEXT('.'));
1162 cmp
= lstrcmpi(ext1
, ext2
);
1166 return lstrcmpi(name1
, name2
);
1169 static int compareSize(const void* arg1
, const void* arg2
)
1171 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1172 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1174 int cmp
= compareType(fd1
, fd2
);
1178 cmp
= fd2
->nFileSizeHigh
- fd1
->nFileSizeHigh
;
1185 cmp
= fd2
->nFileSizeLow
- fd1
->nFileSizeLow
;
1187 return cmp
<0? -1: cmp
>0? 1: 0;
1190 static int compareDate(const void* arg1
, const void* arg2
)
1192 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1193 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1195 int cmp
= compareType(fd1
, fd2
);
1199 return CompareFileTime(&fd2
->ftLastWriteTime
, &fd1
->ftLastWriteTime
);
1203 static int (*sortFunctions
[])(const void* arg1
, const void* arg2
) = {
1204 compareName
, /* SORT_NAME */
1205 compareExt
, /* SORT_EXT */
1206 compareSize
, /* SORT_SIZE */
1207 compareDate
/* SORT_DATE */
1211 static void SortDirectory(Entry
* dir
, SORT_ORDER sortOrder
)
1213 Entry
* entry
= dir
->down
;
1218 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1222 array
= (Entry
**) TMP_ALLOC(len
*sizeof(Entry
*));
1225 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1228 /* call qsort with the appropriate compare function */
1229 qsort(array
, len
, sizeof(array
[0]), sortFunctions
[sortOrder
]);
1231 dir
->down
= array
[0];
1233 for(p
=array
; --len
; p
++)
1243 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
1245 TCHAR buffer
[MAX_PATH
];
1250 #ifdef _SHELL_FOLDERS
1251 if (dir
->etype
== ET_SHELL
)
1253 read_directory_shell(dir
, hwnd
);
1255 if (Globals
.prescan_node
) {
1264 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1265 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1266 read_directory_shell(entry
, hwnd
);
1267 SortDirectory(entry
, sortOrder
);
1273 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1274 if (dir
->etype
== ET_UNIX
)
1276 read_directory_unix(dir
, path
);
1278 if (Globals
.prescan_node
) {
1287 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1288 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1289 lstrcpy(d
, entry
->data
.cFileName
);
1290 read_directory_unix(entry
, buffer
);
1291 SortDirectory(entry
, sortOrder
);
1298 read_directory_win(dir
, path
);
1300 if (Globals
.prescan_node
) {
1309 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1310 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1311 lstrcpy(d
, entry
->data
.cFileName
);
1312 read_directory_win(entry
, buffer
);
1313 SortDirectory(entry
, sortOrder
);
1318 SortDirectory(dir
, sortOrder
);
1322 static ChildWnd
* alloc_child_window(LPCTSTR path
, LPITEMIDLIST pidl
, HWND hwnd
)
1324 const static TCHAR sBackslash
[] = {'\\', '\0'};
1325 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1326 const static TCHAR sSlash
[] = {'/', '\0'};
1329 TCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
1330 TCHAR b1
[BUFFER_LEN
];
1332 ChildWnd
* child
= (ChildWnd
*) malloc(sizeof(ChildWnd
));
1333 Root
* root
= &child
->root
;
1336 memset(child
, 0, sizeof(ChildWnd
));
1338 child
->left
.treePane
= TRUE
;
1339 child
->left
.visible_cols
= 0;
1341 child
->right
.treePane
= FALSE
;
1342 #ifndef _NO_EXTENSIONS
1343 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_INDEX
|COL_LINKS
;
1345 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
;
1348 child
->pos
.length
= sizeof(WINDOWPLACEMENT
);
1349 child
->pos
.flags
= 0;
1350 child
->pos
.showCmd
= SW_SHOWNORMAL
;
1351 child
->pos
.rcNormalPosition
.left
= CW_USEDEFAULT
;
1352 child
->pos
.rcNormalPosition
.top
= CW_USEDEFAULT
;
1353 child
->pos
.rcNormalPosition
.right
= CW_USEDEFAULT
;
1354 child
->pos
.rcNormalPosition
.bottom
= CW_USEDEFAULT
;
1356 child
->focus_pane
= 0;
1357 child
->split_pos
= DEFAULT_SPLIT_POS
;
1358 child
->sortOrder
= SORT_NAME
;
1359 child
->header_wdths_ok
= FALSE
;
1363 lstrcpy(child
->path
, path
);
1365 _tsplitpath(path
, drv
, dir
, name
, ext
);
1368 root
->entry
.level
= 0;
1370 #ifdef _SHELL_FOLDERS
1373 root
->drive_type
= DRIVE_UNKNOWN
;
1376 load_string(root
->volname
, IDS_DESKTOP
);
1378 load_string(root
->fs
, IDS_SHELL
);
1380 entry
= read_tree_shell(root
, pidl
, child
->sortOrder
, hwnd
);
1384 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1387 root
->drive_type
= GetDriveType(path
);
1389 lstrcat(drv
, sSlash
);
1390 load_string(root
->volname
, IDS_ROOT_FS
);
1392 load_string(root
->fs
, IDS_UNIXFS
);
1394 lstrcpy(root
->path
, sSlash
);
1395 entry
= read_tree_unix(root
, path
, child
->sortOrder
, hwnd
);
1400 root
->drive_type
= GetDriveType(path
);
1402 lstrcat(drv
, sBackslash
);
1403 GetVolumeInformation(drv
, root
->volname
, _MAX_FNAME
, 0, 0, &root
->fs_flags
, root
->fs
, _MAX_DIR
);
1405 lstrcpy(root
->path
, drv
);
1406 entry
= read_tree_win(root
, path
, child
->sortOrder
, hwnd
);
1409 #ifdef _SHELL_FOLDERS
1410 if (root
->entry
.etype
== ET_SHELL
)
1411 load_string(root
->entry
.data
.cFileName
, IDS_DESKTOP
);
1414 wsprintf(root
->entry
.data
.cFileName
, RS(b1
,IDS_TITLEFMT
), drv
, root
->fs
);
1416 root
->entry
.data
.dwFileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1418 child
->left
.root
= &root
->entry
;
1419 child
->right
.root
= NULL
;
1421 set_curdir(child
, entry
, hwnd
);
1427 /* free all memory associated with a child window */
1428 static void free_child_window(ChildWnd
* child
)
1430 free_entries(&child
->root
.entry
);
1435 /* get full path of specified directory entry */
1436 static void get_path(Entry
* dir
, PTSTR path
)
1442 #ifdef _SHELL_FOLDERS
1443 if (dir
->etype
== ET_SHELL
)
1448 path
[0] = TEXT('\0');
1453 hr
= (*dir
->folder
->lpVtbl
->GetAttributesOf
)(dir
->folder
, 1, (LPCITEMIDLIST
*)&dir
->pidl
, &attribs
);
1455 if (SUCCEEDED(hr
) && (attribs
&SFGAO_FILESYSTEM
)) {
1456 IShellFolder
* parent
= dir
->up
? dir
->up
->folder
: Globals
.iDesktop
;
1458 hr
= path_from_pidl(parent
, dir
->pidl
, path
, MAX_PATH
);
1464 for(entry
=dir
; entry
; level
++) {
1470 name
= entry
->data
.cFileName
;
1473 for(l
=0; *s
&& *s
!=TEXT('/') && *s
!=TEXT('\\'); s
++)
1479 memmove(path
+l
+1, path
, len
*sizeof(TCHAR
));
1480 memcpy(path
+1, name
, l
*sizeof(TCHAR
));
1483 #ifndef _NO_EXTENSIONS
1484 if (entry
->etype
== ET_UNIX
)
1485 path
[0] = TEXT('/');
1488 path
[0] = TEXT('\\');
1493 memmove(path
+l
, path
, len
*sizeof(TCHAR
));
1494 memcpy(path
, name
, l
*sizeof(TCHAR
));
1501 #ifndef _NO_EXTENSIONS
1502 if (entry
->etype
== ET_UNIX
)
1503 path
[len
++] = TEXT('/');
1506 path
[len
++] = TEXT('\\');
1509 path
[len
] = TEXT('\0');
1514 static void resize_frame_rect(HWND hwnd
, PRECT prect
)
1519 if (IsWindowVisible(Globals
.htoolbar
)) {
1520 SendMessage(Globals
.htoolbar
, WM_SIZE
, 0, 0);
1521 GetClientRect(Globals
.htoolbar
, &rt
);
1522 prect
->top
= rt
.bottom
+3;
1523 prect
->bottom
-= rt
.bottom
+3;
1526 if (IsWindowVisible(Globals
.hdrivebar
)) {
1527 SendMessage(Globals
.hdrivebar
, WM_SIZE
, 0, 0);
1528 GetClientRect(Globals
.hdrivebar
, &rt
);
1529 new_top
= --prect
->top
+ rt
.bottom
+3;
1530 MoveWindow(Globals
.hdrivebar
, 0, prect
->top
, rt
.right
, new_top
, TRUE
);
1531 prect
->top
= new_top
;
1532 prect
->bottom
-= rt
.bottom
+2;
1535 if (IsWindowVisible(Globals
.hstatusbar
)) {
1536 int parts
[] = {300, 500};
1538 SendMessage(Globals
.hstatusbar
, WM_SIZE
, 0, 0);
1539 SendMessage(Globals
.hstatusbar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
1540 GetClientRect(Globals
.hstatusbar
, &rt
);
1541 prect
->bottom
-= rt
.bottom
;
1544 MoveWindow(Globals
.hmdiclient
, prect
->left
-1,prect
->top
-1,prect
->right
+2,prect
->bottom
+1, TRUE
);
1547 static void resize_frame(HWND hwnd
, int cx
, int cy
)
1556 resize_frame_rect(hwnd
, &rect
);
1559 static void resize_frame_client(HWND hwnd
)
1563 GetClientRect(hwnd
, &rect
);
1565 resize_frame_rect(hwnd
, &rect
);
1569 static HHOOK hcbthook
;
1570 static ChildWnd
* newchild
= NULL
;
1572 LRESULT CALLBACK
CBTProc(int code
, WPARAM wparam
, LPARAM lparam
)
1574 if (code
==HCBT_CREATEWND
&& newchild
) {
1575 ChildWnd
* child
= newchild
;
1578 child
->hwnd
= (HWND
) wparam
;
1579 SetWindowLong(child
->hwnd
, GWL_USERDATA
, (LPARAM
)child
);
1582 return CallNextHookEx(hcbthook
, code
, wparam
, lparam
);
1585 static HWND
create_child_window(ChildWnd
* child
)
1587 MDICREATESTRUCT mcs
;
1590 mcs
.szClass
= sWINEFILETREE
;
1591 mcs
.szTitle
= (LPTSTR
)child
->path
;
1592 mcs
.hOwner
= Globals
.hInstance
;
1593 mcs
.x
= child
->pos
.rcNormalPosition
.left
;
1594 mcs
.y
= child
->pos
.rcNormalPosition
.top
;
1595 mcs
.cx
= child
->pos
.rcNormalPosition
.right
-child
->pos
.rcNormalPosition
.left
;
1596 mcs
.cy
= child
->pos
.rcNormalPosition
.bottom
-child
->pos
.rcNormalPosition
.top
;
1600 hcbthook
= SetWindowsHookEx(WH_CBT
, CBTProc
, 0, GetCurrentThreadId());
1603 child
->hwnd
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDICREATE
, 0, (LPARAM
)&mcs
);
1605 UnhookWindowsHookEx(hcbthook
);
1609 UnhookWindowsHookEx(hcbthook
);
1611 ListBox_SetItemHeight(child
->left
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1612 ListBox_SetItemHeight(child
->right
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1613 idx
= ListBox_FindItemData(child
->left
.hwnd
, ListBox_GetCurSel(child
->left
.hwnd
), child
->left
.cur
);
1614 ListBox_SetCurSel(child
->left
.hwnd
, idx
);
1620 struct ExecuteDialog
{
1621 TCHAR cmd
[MAX_PATH
];
1626 static INT_PTR CALLBACK
ExecuteDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1628 static struct ExecuteDialog
* dlg
;
1632 dlg
= (struct ExecuteDialog
*) lparam
;
1636 int id
= (int)wparam
;
1639 GetWindowText(GetDlgItem(hwnd
, 201), dlg
->cmd
, MAX_PATH
);
1640 dlg
->cmdshow
= Button_GetState(GetDlgItem(hwnd
,214))&BST_CHECKED
?
1641 SW_SHOWMINIMIZED
: SW_SHOWNORMAL
;
1642 EndDialog(hwnd
, id
);
1643 } else if (id
== IDCANCEL
)
1644 EndDialog(hwnd
, id
);
1652 static INT_PTR CALLBACK
DestinationDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1654 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1658 SetWindowLong(hwnd
, GWL_USERDATA
, lparam
);
1659 SetWindowText(GetDlgItem(hwnd
, 201), (LPCTSTR
)lparam
);
1663 int id
= (int)wparam
;
1667 LPTSTR dest
= (LPTSTR
) GetWindowLong(hwnd
, GWL_USERDATA
);
1668 GetWindowText(GetDlgItem(hwnd
, 201), dest
, MAX_PATH
);
1669 EndDialog(hwnd
, id
);
1673 EndDialog(hwnd
, id
);
1677 MessageBox(hwnd
, RS(b1
,IDS_NO_IMPL
), RS(b2
,IDS_WINEFILE
), MB_OK
);
1689 #ifndef _NO_EXTENSIONS
1691 static struct FullScreenParameters
{
1701 void frame_get_clientspace(HWND hwnd
, PRECT prect
)
1705 if (!IsIconic(hwnd
))
1706 GetClientRect(hwnd
, prect
);
1710 GetWindowPlacement(hwnd
, &wp
);
1712 prect
->left
= prect
->top
= 0;
1713 prect
->right
= wp
.rcNormalPosition
.right
-wp
.rcNormalPosition
.left
-
1714 2*(GetSystemMetrics(SM_CXSIZEFRAME
)+GetSystemMetrics(SM_CXEDGE
));
1715 prect
->bottom
= wp
.rcNormalPosition
.bottom
-wp
.rcNormalPosition
.top
-
1716 2*(GetSystemMetrics(SM_CYSIZEFRAME
)+GetSystemMetrics(SM_CYEDGE
))-
1717 GetSystemMetrics(SM_CYCAPTION
)-GetSystemMetrics(SM_CYMENUSIZE
);
1720 if (IsWindowVisible(Globals
.htoolbar
)) {
1721 GetClientRect(Globals
.htoolbar
, &rt
);
1722 prect
->top
+= rt
.bottom
+2;
1725 if (IsWindowVisible(Globals
.hdrivebar
)) {
1726 GetClientRect(Globals
.hdrivebar
, &rt
);
1727 prect
->top
+= rt
.bottom
+2;
1730 if (IsWindowVisible(Globals
.hstatusbar
)) {
1731 GetClientRect(Globals
.hstatusbar
, &rt
);
1732 prect
->bottom
-= rt
.bottom
;
1736 static BOOL
toggle_fullscreen(HWND hwnd
)
1740 if ((g_fullscreen
.mode
=!g_fullscreen
.mode
)) {
1741 GetWindowRect(hwnd
, &g_fullscreen
.orgPos
);
1742 g_fullscreen
.wasZoomed
= IsZoomed(hwnd
);
1744 Frame_CalcFrameClient(hwnd
, &rt
);
1745 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
1746 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
1748 rt
.left
= g_fullscreen
.orgPos
.left
-rt
.left
;
1749 rt
.top
= g_fullscreen
.orgPos
.top
-rt
.top
;
1750 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+g_fullscreen
.orgPos
.right
-rt
.right
;
1751 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+g_fullscreen
.orgPos
.bottom
-rt
.bottom
;
1753 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
1755 MoveWindow(hwnd
, g_fullscreen
.orgPos
.left
, g_fullscreen
.orgPos
.top
,
1756 g_fullscreen
.orgPos
.right
-g_fullscreen
.orgPos
.left
,
1757 g_fullscreen
.orgPos
.bottom
-g_fullscreen
.orgPos
.top
, TRUE
);
1759 if (g_fullscreen
.wasZoomed
)
1760 ShowWindow(hwnd
, WS_MAXIMIZE
);
1763 return g_fullscreen
.mode
;
1766 static void fullscreen_move(HWND hwnd
)
1769 GetWindowRect(hwnd
, &pos
);
1771 Frame_CalcFrameClient(hwnd
, &rt
);
1772 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
1773 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
1775 rt
.left
= pos
.left
-rt
.left
;
1776 rt
.top
= pos
.top
-rt
.top
;
1777 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+pos
.right
-rt
.right
;
1778 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+pos
.bottom
-rt
.bottom
;
1780 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
1786 static void toggle_child(HWND hwnd
, UINT cmd
, HWND hchild
)
1788 BOOL vis
= IsWindowVisible(hchild
);
1790 CheckMenuItem(Globals
.hMenuOptions
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
1792 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
1794 #ifndef _NO_EXTENSIONS
1795 if (g_fullscreen
.mode
)
1796 fullscreen_move(hwnd
);
1799 resize_frame_client(hwnd
);
1802 BOOL
activate_drive_window(LPCTSTR path
)
1804 TCHAR drv1
[_MAX_DRIVE
], drv2
[_MAX_DRIVE
];
1807 _tsplitpath(path
, drv1
, 0, 0, 0);
1809 /* search for a already open window for the same drive */
1810 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
1811 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(child_wnd
, GWL_USERDATA
);
1814 _tsplitpath(child
->root
.path
, drv2
, 0, 0, 0);
1816 if (!lstrcmpi(drv2
, drv1
)) {
1817 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
1819 if (IsMinimized(child_wnd
))
1820 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
1830 BOOL
activate_fs_window(LPCTSTR filesys
)
1834 /* search for a already open window of the given file system name */
1835 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
1836 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(child_wnd
, GWL_USERDATA
);
1839 if (!lstrcmpi(child
->root
.fs
, filesys
)) {
1840 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
1842 if (IsMinimized(child_wnd
))
1843 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
1853 LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1855 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1859 DestroyWindow(hwnd
);
1861 /* clear handle variables */
1862 Globals
.hMenuFrame
= 0;
1863 Globals
.hMenuView
= 0;
1864 Globals
.hMenuOptions
= 0;
1865 Globals
.hMainWnd
= 0;
1866 Globals
.hmdiclient
= 0;
1867 Globals
.hdrivebar
= 0;
1871 /* don't exit desktop when closing file manager window */
1872 if (!Globals
.hwndParent
)
1877 UINT cmd
= LOWORD(wparam
);
1878 HWND hwndClient
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
1880 if (SendMessage(hwndClient
, WM_DISPATCH_COMMAND
, wparam
, lparam
))
1883 if (cmd
>=ID_DRIVE_FIRST
&& cmd
<=ID_DRIVE_FIRST
+0xFF) {
1884 TCHAR drv
[_MAX_DRIVE
], path
[MAX_PATH
];
1886 LPCTSTR root
= Globals
.drives
;
1889 for(i
=cmd
-ID_DRIVE_FIRST
; i
--; root
++)
1893 if (activate_drive_window(root
))
1896 _tsplitpath(root
, drv
, 0, 0, 0);
1898 if (!SetCurrentDirectory(drv
)) {
1899 display_error(hwnd
, GetLastError());
1903 GetCurrentDirectory(MAX_PATH
, path
); /*TODO: store last directory per drive */
1904 child
= alloc_child_window(path
, NULL
, hwnd
);
1906 if (!create_child_window(child
))
1908 } else switch(cmd
) {
1910 SendMessage(hwnd
, WM_CLOSE
, 0, 0);
1913 case ID_WINDOW_NEW
: {
1914 TCHAR path
[MAX_PATH
];
1917 GetCurrentDirectory(MAX_PATH
, path
);
1918 child
= alloc_child_window(path
, NULL
, hwnd
);
1920 if (!create_child_window(child
))
1924 case ID_WINDOW_CASCADE
:
1925 SendMessage(Globals
.hmdiclient
, WM_MDICASCADE
, 0, 0);
1928 case ID_WINDOW_TILE_HORZ
:
1929 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
1932 case ID_WINDOW_TILE_VERT
:
1933 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
1936 case ID_WINDOW_ARRANGE
:
1937 SendMessage(Globals
.hmdiclient
, WM_MDIICONARRANGE
, 0, 0);
1940 case ID_SELECT_FONT
: {
1941 TCHAR dlg_name
[BUFFER_LEN
], dlg_info
[BUFFER_LEN
];
1945 HDC hdc
= GetDC(hwnd
);
1946 chFont
.lStructSize
= sizeof(CHOOSEFONT
);
1947 chFont
.hwndOwner
= hwnd
;
1949 chFont
.lpLogFont
= &lFont
;
1950 chFont
.Flags
= CF_SCREENFONTS
| CF_FORCEFONTEXIST
| CF_LIMITSIZE
| CF_NOSCRIPTSEL
;
1951 chFont
.rgbColors
= RGB(0,0,0);
1952 chFont
.lCustData
= 0;
1953 chFont
.lpfnHook
= NULL
;
1954 chFont
.lpTemplateName
= NULL
;
1955 chFont
.hInstance
= Globals
.hInstance
;
1956 chFont
.lpszStyle
= NULL
;
1957 chFont
.nFontType
= SIMULATED_FONTTYPE
;
1958 chFont
.nSizeMin
= 0;
1959 chFont
.nSizeMax
= 24;
1961 if (ChooseFont(&chFont
)) {
1964 Globals
.hfont
= CreateFontIndirect(&lFont
);
1965 SelectFont(hdc
, Globals
.hfont
);
1966 GetTextExtentPoint32(hdc
, sSpace
, 1, &Globals
.spaceSize
);
1968 /* change font in all open child windows */
1969 for(childWnd
=GetWindow(Globals
.hmdiclient
,GW_CHILD
); childWnd
; childWnd
=GetNextWindow(childWnd
,GW_HWNDNEXT
)) {
1970 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(childWnd
, GWL_USERDATA
);
1971 SetWindowFont(child
->left
.hwnd
, Globals
.hfont
, TRUE
);
1972 SetWindowFont(child
->right
.hwnd
, Globals
.hfont
, TRUE
);
1973 ListBox_SetItemHeight(child
->left
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1974 ListBox_SetItemHeight(child
->right
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1975 InvalidateRect(child
->left
.hwnd
, NULL
, TRUE
);
1976 InvalidateRect(child
->right
.hwnd
, NULL
, TRUE
);
1979 else if (CommDlgExtendedError()) {
1980 LoadString(Globals
.hInstance
, IDS_FONT_SEL_DLG_NAME
, dlg_name
, BUFFER_LEN
);
1981 LoadString(Globals
.hInstance
, IDS_FONT_SEL_ERROR
, dlg_info
, BUFFER_LEN
);
1982 MessageBox(hwnd
, dlg_info
, dlg_name
, MB_OK
);
1985 ReleaseDC(hwnd
, hdc
);
1989 case ID_VIEW_TOOL_BAR
:
1990 toggle_child(hwnd
, cmd
, Globals
.htoolbar
);
1993 case ID_VIEW_DRIVE_BAR
:
1994 toggle_child(hwnd
, cmd
, Globals
.hdrivebar
);
1997 case ID_VIEW_STATUSBAR
:
1998 toggle_child(hwnd
, cmd
, Globals
.hstatusbar
);
2002 struct ExecuteDialog dlg
;
2004 memset(&dlg
, 0, sizeof(struct ExecuteDialog
));
2006 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_EXECUTE
), hwnd
, ExecuteDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
2007 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, dlg
.cmd
/*file*/, NULL
/*parameters*/, NULL
/*dir*/, dlg
.cmdshow
);
2009 if ((int)hinst
<= 32)
2010 display_error(hwnd
, GetLastError());
2014 case ID_CONNECT_NETWORK_DRIVE
: {
2015 DWORD ret
= WNetConnectionDialog(hwnd
, RESOURCETYPE_DISK
);
2016 if (ret
!=NO_ERROR
&& ret
!=(DWORD
)-1) {
2017 if (ret
== ERROR_EXTENDED_ERROR
)
2018 display_network_error(hwnd
);
2020 display_error(hwnd
, ret
);
2024 case ID_DISCONNECT_NETWORK_DRIVE
: {
2025 DWORD ret
= WNetDisconnectDialog(hwnd
, RESOURCETYPE_DISK
);
2026 if (ret
!=NO_ERROR
&& ret
!=(DWORD
)-1) {
2027 if (ret
== ERROR_EXTENDED_ERROR
)
2028 display_network_error(hwnd
);
2030 display_error(hwnd
, ret
);
2034 #ifndef __MINGW32__ /* SHFormatDrive missing in MinGW (as of 13.5.2005) */
2035 case ID_FORMAT_DISK
: {
2036 UINT sem_org
= SetErrorMode(0); /* Get the current Error Mode settings. */
2037 SetErrorMode(sem_org
& ~SEM_FAILCRITICALERRORS
); /* Force O/S to handle */
2038 SHFormatDrive(hwnd
, 0 /* A: */, SHFMT_ID_DEFAULT
, 0);
2039 SetErrorMode(sem_org
); /* Put it back the way it was. */
2044 WinHelp(hwnd
, RS(b1
,IDS_WINEFILE
), HELP_INDEX
, 0);
2047 #ifndef _NO_EXTENSIONS
2048 case ID_VIEW_FULLSCREEN
:
2049 CheckMenuItem(Globals
.hMenuOptions
, cmd
, toggle_fullscreen(hwnd
)?MF_CHECKED
:0);
2053 case ID_DRIVE_UNIX_FS
: {
2054 TCHAR path
[MAX_PATH
];
2056 char cpath
[MAX_PATH
];
2060 if (activate_fs_window(RS(b1
,IDS_UNIXFS
)))
2065 call_getcwd(cpath
, MAX_PATH
);
2066 MultiByteToWideChar(CP_UNIXCP
, 0, cpath
, -1, path
, MAX_PATH
);
2068 call_getcwd(path
, MAX_PATH
);
2070 child
= alloc_child_window(path
, NULL
, hwnd
);
2072 if (!create_child_window(child
))
2077 #ifdef _SHELL_FOLDERS
2078 case ID_DRIVE_SHELL_NS
: {
2079 TCHAR path
[MAX_PATH
];
2082 if (activate_fs_window(RS(b1
,IDS_SHELL
)))
2085 GetCurrentDirectory(MAX_PATH
, path
);
2086 child
= alloc_child_window(path
, get_path_pidl(path
,hwnd
), hwnd
);
2088 if (!create_child_window(child
))
2094 /*TODO: There are even more menu items! */
2096 #ifndef _NO_EXTENSIONS
2099 WineLicense(Globals
.hMainWnd
);
2102 case ID_NO_WARRANTY
:
2103 WineWarranty(Globals
.hMainWnd
);
2108 ShellAbout(hwnd
, RS(b2
,IDS_WINE
), RS(b1
,IDS_WINEFILE
), 0);
2112 ShellAbout(hwnd
, RS(b1
,IDS_WINEFILE
), NULL
, 0);
2114 #endif /* _NO_EXTENSIONS */
2117 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2118 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2119 else */if ((cmd
<IDW_FIRST_CHILD
|| cmd
>=IDW_FIRST_CHILD
+0x100) &&
2120 (cmd
<SC_SIZE
|| cmd
>SC_RESTORE
))
2121 MessageBox(hwnd
, RS(b2
,IDS_NO_IMPL
), RS(b1
,IDS_WINEFILE
), MB_OK
);
2123 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2128 resize_frame(hwnd
, LOWORD(lparam
), HIWORD(lparam
));
2129 break; /* do not pass message to DefFrameProc */
2131 #ifndef _NO_EXTENSIONS
2132 case WM_GETMINMAXINFO
: {
2133 LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
2135 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2136 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2139 case FRM_CALC_CLIENT
:
2140 frame_get_clientspace(hwnd
, (PRECT
)lparam
);
2142 #endif /* _NO_EXTENSIONS */
2145 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2152 static TCHAR g_pos_names
[COLUMNS
][20] = {
2156 static const int g_pos_align
[] = {
2158 HDF_LEFT
, /* Name */
2159 HDF_RIGHT
, /* Size */
2160 HDF_LEFT
, /* CDate */
2161 #ifndef _NO_EXTENSIONS
2162 HDF_LEFT
, /* ADate */
2163 HDF_LEFT
, /* MDate */
2164 HDF_LEFT
, /* Index */
2165 HDF_CENTER
, /* Links */
2167 HDF_CENTER
, /* Attributes */
2168 #ifndef _NO_EXTENSIONS
2169 HDF_LEFT
/* Security */
2173 static void resize_tree(ChildWnd
* child
, int cx
, int cy
)
2175 HDWP hdwp
= BeginDeferWindowPos(4);
2183 cx
= child
->split_pos
+ SPLIT_WIDTH
/2;
2185 #ifndef _NO_EXTENSIONS
2193 Header_Layout(child
->left
.hwndHeader
, &hdl
);
2195 DeferWindowPos(hdwp
, child
->left
.hwndHeader
, wp
.hwndInsertAfter
,
2196 wp
.x
-1, wp
.y
, child
->split_pos
-SPLIT_WIDTH
/2+1, wp
.cy
, wp
.flags
);
2197 DeferWindowPos(hdwp
, child
->right
.hwndHeader
, wp
.hwndInsertAfter
,
2198 rt
.left
+cx
+1, wp
.y
, wp
.cx
-cx
+2, wp
.cy
, wp
.flags
);
2200 #endif /* _NO_EXTENSIONS */
2202 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
);
2203 DeferWindowPos(hdwp
, child
->right
.hwnd
, 0, rt
.left
+cx
+1, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
2205 EndDeferWindowPos(hdwp
);
2209 #ifndef _NO_EXTENSIONS
2211 static HWND
create_header(HWND parent
, Pane
* pane
, int id
)
2216 HWND hwnd
= CreateWindow(WC_HEADER
, 0, WS_CHILD
|WS_VISIBLE
|HDS_HORZ
/*TODO: |HDS_BUTTONS + sort orders*/,
2217 0, 0, 0, 0, parent
, (HMENU
)id
, Globals
.hInstance
, 0);
2221 SetWindowFont(hwnd
, GetStockObject(DEFAULT_GUI_FONT
), FALSE
);
2223 hdi
.mask
= HDI_TEXT
|HDI_WIDTH
|HDI_FORMAT
;
2225 for(idx
=0; idx
<COLUMNS
; idx
++) {
2226 hdi
.pszText
= g_pos_names
[idx
];
2227 hdi
.fmt
= HDF_STRING
| g_pos_align
[idx
];
2228 hdi
.cxy
= pane
->widths
[idx
];
2229 Header_InsertItem(hwnd
, idx
, &hdi
);
2235 #endif /* _NO_EXTENSIONS */
2238 static void init_output(HWND hwnd
)
2240 const static TCHAR s1000
[] = {'1','0','0','0','\0'};
2244 HDC hdc
= GetDC(hwnd
);
2246 if (GetNumberFormat(LOCALE_USER_DEFAULT
, 0, s1000
, 0, b
, 16) > 4)
2247 Globals
.num_sep
= b
[1];
2249 Globals
.num_sep
= TEXT('.');
2251 old_font
= SelectFont(hdc
, Globals
.hfont
);
2252 GetTextExtentPoint32(hdc
, sSpace
, 1, &Globals
.spaceSize
);
2253 SelectFont(hdc
, old_font
);
2254 ReleaseDC(hwnd
, hdc
);
2257 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
);
2260 /* calculate preferred width for all visible columns */
2262 static BOOL
calc_widths(Pane
* pane
, BOOL anyway
)
2264 int col
, x
, cx
, spc
=3*Globals
.spaceSize
.cx
;
2265 int entries
= ListBox_GetCount(pane
->hwnd
);
2266 int orgWidths
[COLUMNS
];
2267 int orgPositions
[COLUMNS
+1];
2273 memcpy(orgWidths
, pane
->widths
, sizeof(orgWidths
));
2274 memcpy(orgPositions
, pane
->positions
, sizeof(orgPositions
));
2277 for(col
=0; col
<COLUMNS
; col
++)
2278 pane
->widths
[col
] = 0;
2280 hdc
= GetDC(pane
->hwnd
);
2281 hfontOld
= SelectFont(hdc
, Globals
.hfont
);
2283 for(cnt
=0; cnt
<entries
; cnt
++) {
2284 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, cnt
);
2293 dis
.hwndItem
= pane
->hwnd
;
2295 dis
.rcItem
.left
= 0;
2297 dis
.rcItem
.right
= 0;
2298 dis
.rcItem
.bottom
= 0;
2299 /*dis.itemData = 0; */
2301 draw_item(pane
, &dis
, entry
, COLUMNS
);
2304 SelectObject(hdc
, hfontOld
);
2305 ReleaseDC(pane
->hwnd
, hdc
);
2308 for(col
=0; col
<COLUMNS
; col
++) {
2309 pane
->positions
[col
] = x
;
2310 cx
= pane
->widths
[col
];
2315 if (cx
< IMAGE_WIDTH
)
2318 pane
->widths
[col
] = cx
;
2324 pane
->positions
[COLUMNS
] = x
;
2326 ListBox_SetHorizontalExtent(pane
->hwnd
, x
);
2329 if (!memcmp(orgWidths
, pane
->widths
, sizeof(orgWidths
)))
2332 /* don't move, if only collapsing an entry */
2333 if (!anyway
&& pane
->widths
[0]<orgWidths
[0] &&
2334 !memcmp(orgWidths
+1, pane
->widths
+1, sizeof(orgWidths
)-sizeof(int))) {
2335 pane
->widths
[0] = orgWidths
[0];
2336 memcpy(pane
->positions
, orgPositions
, sizeof(orgPositions
));
2341 InvalidateRect(pane
->hwnd
, 0, TRUE
);
2347 /* calculate one preferred column width */
2349 static void calc_single_width(Pane
* pane
, int col
)
2353 int entries
= ListBox_GetCount(pane
->hwnd
);
2357 pane
->widths
[col
] = 0;
2359 hdc
= GetDC(pane
->hwnd
);
2360 hfontOld
= SelectFont(hdc
, Globals
.hfont
);
2362 for(cnt
=0; cnt
<entries
; cnt
++) {
2363 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, cnt
);
2371 dis
.hwndItem
= pane
->hwnd
;
2373 dis
.rcItem
.left
= 0;
2375 dis
.rcItem
.right
= 0;
2376 dis
.rcItem
.bottom
= 0;
2377 /*dis.itemData = 0; */
2379 draw_item(pane
, &dis
, entry
, col
);
2382 SelectObject(hdc
, hfontOld
);
2383 ReleaseDC(pane
->hwnd
, hdc
);
2385 cx
= pane
->widths
[col
];
2388 cx
+= 3*Globals
.spaceSize
.cx
;
2390 if (cx
< IMAGE_WIDTH
)
2394 pane
->widths
[col
] = cx
;
2396 x
= pane
->positions
[col
] + cx
;
2398 for(; col
<COLUMNS
; ) {
2399 pane
->positions
[++col
] = x
;
2400 x
+= pane
->widths
[col
];
2403 ListBox_SetHorizontalExtent(pane
->hwnd
, x
);
2407 /* insert listbox entries after index idx */
2409 static int insert_entries(Pane
* pane
, Entry
* dir
, int idx
)
2416 ShowWindow(pane
->hwnd
, SW_HIDE
);
2418 for(; entry
; entry
=entry
->next
) {
2420 if (pane
->treePane
&& !(entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
2424 /* don't display entries "." and ".." in the left pane */
2425 if (pane
->treePane
&& (entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
)
2426 && entry
->data
.cFileName
[0]==TEXT('.'))
2428 #ifndef _NO_EXTENSIONS
2429 entry
->data
.cFileName
[1]==TEXT('\0') ||
2431 (entry
->data
.cFileName
[1]==TEXT('.') && entry
->data
.cFileName
[2]==TEXT('\0')))
2437 ListBox_InsertItemData(pane
->hwnd
, idx
, entry
);
2439 if (pane
->treePane
&& entry
->expanded
)
2440 idx
= insert_entries(pane
, entry
->down
, idx
);
2443 ShowWindow(pane
->hwnd
, SW_SHOW
);
2449 static void format_bytes(LPTSTR buffer
, LONGLONG bytes
)
2451 const static TCHAR sFmtGB
[] = {'%', '.', '1', 'f', ' ', 'G', 'B', '\0'};
2452 const static TCHAR sFmtMB
[] = {'%', '.', '1', 'f', ' ', 'M', 'B', '\0'};
2453 const static TCHAR sFmtkB
[] = {'%', '.', '1', 'f', ' ', 'k', 'B', '\0'};
2455 float fBytes
= (float)bytes
;
2457 if (bytes
>= 1073741824) /* 1 GB */
2458 _stprintf(buffer
, sFmtGB
, fBytes
/1073741824.f
+.5f
);
2459 else if (bytes
>= 1048576) /* 1 MB */
2460 _stprintf(buffer
, sFmtMB
, fBytes
/1048576.f
+.5f
);
2461 else if (bytes
>= 1024) /* 1 kB */
2462 _stprintf(buffer
, sFmtkB
, fBytes
/1024.f
+.5f
);
2464 _stprintf(buffer
, sLongNumFmt
, bytes
);
2467 static void set_space_status()
2469 ULARGE_INTEGER ulFreeBytesToCaller
, ulTotalBytes
, ulFreeBytes
;
2470 TCHAR fmt
[64], b1
[64], b2
[64], buffer
[BUFFER_LEN
];
2472 if (GetDiskFreeSpaceEx(NULL
, &ulFreeBytesToCaller
, &ulTotalBytes
, &ulFreeBytes
)) {
2473 format_bytes(b1
, ulFreeBytesToCaller
.QuadPart
);
2474 format_bytes(b2
, ulTotalBytes
.QuadPart
);
2475 _stprintf(buffer
, RS(fmt
,IDS_FREE_SPACE_FMT
), b1
, b2
);
2477 _tcscpy(buffer
, sQMarks
);
2479 SendMessage(Globals
.hstatusbar
, SB_SETTEXT
, 0, (LPARAM
)buffer
);
2483 static WNDPROC g_orgTreeWndProc
;
2485 static void create_tree_window(HWND parent
, Pane
* pane
, int id
, int id_header
)
2487 const static TCHAR sListBox
[] = {'L','i','s','t','B','o','x','\0'};
2489 static int s_init
= 0;
2490 Entry
* entry
= pane
->root
;
2492 pane
->hwnd
= CreateWindow(sListBox
, sEmpty
, WS_CHILD
|WS_VISIBLE
|WS_HSCROLL
|WS_VSCROLL
|
2493 LBS_DISABLENOSCROLL
|LBS_NOINTEGRALHEIGHT
|LBS_OWNERDRAWFIXED
|LBS_NOTIFY
,
2494 0, 0, 0, 0, parent
, (HMENU
)id
, Globals
.hInstance
, 0);
2496 SetWindowLong(pane
->hwnd
, GWL_USERDATA
, (LPARAM
)pane
);
2497 g_orgTreeWndProc
= SubclassWindow(pane
->hwnd
, TreeWndProc
);
2499 SetWindowFont(pane
->hwnd
, Globals
.hfont
, FALSE
);
2501 /* insert entries into listbox */
2503 insert_entries(pane
, entry
, -1);
2505 /* calculate column widths */
2508 init_output(pane
->hwnd
);
2511 calc_widths(pane
, TRUE
);
2513 #ifndef _NO_EXTENSIONS
2514 pane
->hwndHeader
= create_header(parent
, pane
, id_header
);
2519 static void InitChildWindow(ChildWnd
* child
)
2521 create_tree_window(child
->hwnd
, &child
->left
, IDW_TREE_LEFT
, IDW_HEADER_LEFT
);
2522 create_tree_window(child
->hwnd
, &child
->right
, IDW_TREE_RIGHT
, IDW_HEADER_RIGHT
);
2526 static void format_date(const FILETIME
* ft
, TCHAR
* buffer
, int visible_cols
)
2532 *buffer
= TEXT('\0');
2534 if (!ft
->dwLowDateTime
&& !ft
->dwHighDateTime
)
2537 if (!FileTimeToLocalFileTime(ft
, &lft
))
2538 {err
: _tcscpy(buffer
,sQMarks
); return;}
2540 if (!FileTimeToSystemTime(&lft
, &systime
))
2543 if (visible_cols
& COL_DATE
) {
2544 len
= GetDateFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
, BUFFER_LEN
);
2549 if (visible_cols
& COL_TIME
) {
2551 buffer
[len
-1] = ' ';
2553 buffer
[len
++] = ' ';
2555 if (!GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
+len
, BUFFER_LEN
-len
))
2556 buffer
[len
] = TEXT('\0');
2561 static void calc_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2563 RECT rt
= {0, 0, 0, 0};
2565 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
2567 if (rt
.right
> pane
->widths
[col
])
2568 pane
->widths
[col
] = rt
.right
;
2571 static void calc_tabbed_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2573 RECT rt
= {0, 0, 0, 0};
2575 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2576 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2578 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2579 /*FIXME rt (0,0) ??? */
2581 if (rt
.right
> pane
->widths
[col
])
2582 pane
->widths
[col
] = rt
.right
;
2586 static void output_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
, DWORD flags
)
2588 int x
= dis
->rcItem
.left
;
2591 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2592 rt
.top
= dis
->rcItem
.top
;
2593 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2594 rt
.bottom
= dis
->rcItem
.bottom
;
2596 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_SINGLELINE
|DT_NOPREFIX
|flags
);
2599 static void output_tabbed_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2601 int x
= dis
->rcItem
.left
;
2604 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2605 rt
.top
= dis
->rcItem
.top
;
2606 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2607 rt
.bottom
= dis
->rcItem
.bottom
;
2609 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2610 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2612 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2615 static void output_number(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2617 int x
= dis
->rcItem
.left
;
2624 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2625 rt
.top
= dis
->rcItem
.top
;
2626 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2627 rt
.bottom
= dis
->rcItem
.bottom
;
2632 /* insert number separator characters */
2633 pos
= lstrlen(s
) % 3;
2639 *d
++ = Globals
.num_sep
;
2643 DrawText(dis
->hDC
, b
, d
-b
, &rt
, DT_RIGHT
|DT_SINGLELINE
|DT_NOPREFIX
|DT_END_ELLIPSIS
);
2647 static int is_exe_file(LPCTSTR ext
)
2649 static const TCHAR executable_extensions
[][4] = {
2654 #ifndef _NO_EXTENSIONS
2658 #endif /* _NO_EXTENSIONS */
2662 TCHAR ext_buffer
[_MAX_EXT
];
2663 const TCHAR (*p
)[4];
2667 for(s
=ext
+1,d
=ext_buffer
; (*d
=tolower(*s
)); s
++)
2670 for(p
=executable_extensions
; (*p
)[0]; p
++)
2671 if (!_tcscmp(ext_buffer
, *p
))
2677 static int is_registered_type(LPCTSTR ext
)
2685 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
)
2687 TCHAR buffer
[BUFFER_LEN
];
2689 int visible_cols
= pane
->visible_cols
;
2690 COLORREF bkcolor
, textcolor
;
2691 RECT focusRect
= dis
->rcItem
;
2698 attrs
= entry
->data
.dwFileAttributes
;
2700 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) {
2701 if (entry
->data
.cFileName
[0]==TEXT('.') && entry
->data
.cFileName
[1]==TEXT('.')
2702 && entry
->data
.cFileName
[2]==TEXT('\0'))
2703 img
= IMG_FOLDER_UP
;
2704 #ifndef _NO_EXTENSIONS
2705 else if (entry
->data
.cFileName
[0]==TEXT('.') && entry
->data
.cFileName
[1]==TEXT('\0'))
2706 img
= IMG_FOLDER_CUR
;
2709 #ifdef _NO_EXTENSIONS
2712 (pane
->treePane
&& (dis
->itemState
&ODS_FOCUS
)))
2713 img
= IMG_OPEN_FOLDER
;
2717 LPCTSTR ext
= _tcsrchr(entry
->data
.cFileName
, '.');
2721 if (is_exe_file(ext
))
2722 img
= IMG_EXECUTABLE
;
2723 else if (is_registered_type(ext
))
2733 if (pane
->treePane
) {
2735 img_pos
= dis
->rcItem
.left
+ entry
->level
*(IMAGE_WIDTH
+TREE_LINE_DX
);
2737 if (calcWidthCol
== -1) {
2739 int y
= dis
->rcItem
.top
+ IMAGE_HEIGHT
/2;
2742 HRGN hrgn_org
= CreateRectRgn(0, 0, 0, 0);
2745 rt_clip
.left
= dis
->rcItem
.left
;
2746 rt_clip
.top
= dis
->rcItem
.top
;
2747 rt_clip
.right
= dis
->rcItem
.left
+pane
->widths
[col
];
2748 rt_clip
.bottom
= dis
->rcItem
.bottom
;
2750 hrgn
= CreateRectRgnIndirect(&rt_clip
);
2752 if (!GetClipRgn(dis
->hDC
, hrgn_org
)) {
2753 DeleteObject(hrgn_org
);
2757 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
2758 ExtSelectClipRgn(dis
->hDC
, hrgn
, RGN_AND
);
2761 if ((up
=entry
->up
) != NULL
) {
2762 MoveToEx(dis
->hDC
, img_pos
-IMAGE_WIDTH
/2, y
, 0);
2763 LineTo(dis
->hDC
, img_pos
-2, y
);
2765 x
= img_pos
- IMAGE_WIDTH
/2;
2768 x
-= IMAGE_WIDTH
+TREE_LINE_DX
;
2772 && (up
->next
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
2775 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
2776 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
2778 } while((up
=up
->up
) != NULL
);
2781 x
= img_pos
- IMAGE_WIDTH
/2;
2783 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
2784 LineTo(dis
->hDC
, x
, y
);
2788 && (entry
->next
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
)
2791 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
2793 if (entry->down && entry->expanded) {
2794 x += IMAGE_WIDTH+TREE_LINE_DX;
2795 MoveToEx(dis->hDC, x, dis->rcItem.top+IMAGE_HEIGHT, 0);
2796 LineTo(dis->hDC, x, dis->rcItem.bottom);
2799 SelectClipRgn(dis
->hDC
, hrgn_org
);
2800 if (hrgn_org
) DeleteObject(hrgn_org
);
2801 /* SelectObject(dis->hDC, holdPen); */
2802 } else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
) {
2803 int right
= img_pos
+ IMAGE_WIDTH
- TREE_LINE_DX
;
2805 if (right
> pane
->widths
[col
])
2806 pane
->widths
[col
] = right
;
2809 img_pos
= dis
->rcItem
.left
;
2812 img_pos
= dis
->rcItem
.left
;
2814 if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2815 pane
->widths
[col
] = IMAGE_WIDTH
;
2818 if (calcWidthCol
== -1) {
2819 focusRect
.left
= img_pos
- 2;
2821 #ifdef _NO_EXTENSIONS
2822 if (pane
->treePane
&& entry
) {
2825 DrawText(dis
->hDC
, entry
->data
.cFileName
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
2827 focusRect
.right
= dis
->rcItem
.left
+pane
->positions
[col
+1]+TREE_LINE_DX
+ rt
.right
+2;
2831 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
)
2832 textcolor
= COLOR_COMPRESSED
;
2834 #endif /* _NO_EXTENSIONS */
2835 textcolor
= RGB(0,0,0);
2837 if (dis
->itemState
& ODS_FOCUS
) {
2838 textcolor
= RGB(255,255,255);
2839 bkcolor
= COLOR_SELECTION
;
2841 bkcolor
= RGB(255,255,255);
2844 hbrush
= CreateSolidBrush(bkcolor
);
2845 FillRect(dis
->hDC
, &focusRect
, hbrush
);
2846 DeleteObject(hbrush
);
2848 SetBkMode(dis
->hDC
, TRANSPARENT
);
2849 SetTextColor(dis
->hDC
, textcolor
);
2851 cx
= pane
->widths
[col
];
2853 if (cx
&& img
!=IMG_NONE
) {
2854 if (cx
> IMAGE_WIDTH
)
2857 #ifdef _SHELL_FOLDERS
2858 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
2859 DrawIconEx(dis
->hDC
, img_pos
, dis
->rcItem
.top
, entry
->hicon
, cx
, GetSystemMetrics(SM_CYSMICON
), 0, 0, DI_NORMAL
);
2862 ImageList_DrawEx(Globals
.himl
, img
, dis
->hDC
,
2863 img_pos
, dis
->rcItem
.top
, cx
,
2864 IMAGE_HEIGHT
, bkcolor
, CLR_DEFAULT
, ILD_NORMAL
);
2871 #ifdef _NO_EXTENSIONS
2872 if (img
>= IMG_FOLDER_UP
)
2878 /* ouput file name */
2879 if (calcWidthCol
== -1)
2880 output_text(pane
, dis
, col
, entry
->data
.cFileName
, 0);
2881 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2882 calc_width(pane
, dis
, col
, entry
->data
.cFileName
);
2886 #ifdef _NO_EXTENSIONS
2887 if (!pane
->treePane
) {
2890 /* display file size */
2891 if (visible_cols
& COL_SIZE
) {
2892 #ifdef _NO_EXTENSIONS
2893 if (!(attrs
&FILE_ATTRIBUTE_DIRECTORY
))
2898 size
= ((ULONGLONG
)entry
->data
.nFileSizeHigh
<< 32) | entry
->data
.nFileSizeLow
;
2900 _stprintf(buffer
, sLongNumFmt
, size
);
2902 if (calcWidthCol
== -1)
2903 output_number(pane
, dis
, col
, buffer
);
2904 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2905 calc_width(pane
, dis
, col
, buffer
);/*TODO: not in every case time enough */
2911 /* display file date */
2912 if (visible_cols
& (COL_DATE
|COL_TIME
)) {
2913 #ifndef _NO_EXTENSIONS
2914 format_date(&entry
->data
.ftCreationTime
, buffer
, visible_cols
);
2915 if (calcWidthCol
== -1)
2916 output_text(pane
, dis
, col
, buffer
, 0);
2917 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2918 calc_width(pane
, dis
, col
, buffer
);
2921 format_date(&entry
->data
.ftLastAccessTime
, buffer
, visible_cols
);
2922 if (calcWidthCol
== -1)
2923 output_text(pane
, dis
, col
, buffer
, 0);
2924 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2925 calc_width(pane
, dis
, col
, buffer
);
2927 #endif /* _NO_EXTENSIONS */
2929 format_date(&entry
->data
.ftLastWriteTime
, buffer
, visible_cols
);
2930 if (calcWidthCol
== -1)
2931 output_text(pane
, dis
, col
, buffer
, 0);
2932 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2933 calc_width(pane
, dis
, col
, buffer
);
2937 #ifndef _NO_EXTENSIONS
2938 if (entry
->bhfi_valid
) {
2939 ULONGLONG index
= ((ULONGLONG
)entry
->bhfi
.nFileIndexHigh
<< 32) | entry
->bhfi
.nFileIndexLow
;
2941 if (visible_cols
& COL_INDEX
) {
2942 _stprintf(buffer
, sLongHexFmt
, index
);
2944 if (calcWidthCol
== -1)
2945 output_text(pane
, dis
, col
, buffer
, DT_RIGHT
);
2946 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2947 calc_width(pane
, dis
, col
, buffer
);
2952 if (visible_cols
& COL_LINKS
) {
2953 wsprintf(buffer
, sNumFmt
, entry
->bhfi
.nNumberOfLinks
);
2955 if (calcWidthCol
== -1)
2956 output_text(pane
, dis
, col
, buffer
, DT_CENTER
);
2957 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2958 calc_width(pane
, dis
, col
, buffer
);
2964 #endif /* _NO_EXTENSIONS */
2966 /* show file attributes */
2967 if (visible_cols
& COL_ATTRIBUTES
) {
2968 #ifdef _NO_EXTENSIONS
2969 const static TCHAR s4Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
2970 _tcscpy(buffer
, s4Tabs
);
2972 const static TCHAR s11Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
2973 _tcscpy(buffer
, s11Tabs
);
2976 if (attrs
& FILE_ATTRIBUTE_NORMAL
) buffer
[ 0] = 'N';
2978 if (attrs
& FILE_ATTRIBUTE_READONLY
) buffer
[ 2] = 'R';
2979 if (attrs
& FILE_ATTRIBUTE_HIDDEN
) buffer
[ 4] = 'H';
2980 if (attrs
& FILE_ATTRIBUTE_SYSTEM
) buffer
[ 6] = 'S';
2981 if (attrs
& FILE_ATTRIBUTE_ARCHIVE
) buffer
[ 8] = 'A';
2982 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
) buffer
[10] = 'C';
2983 #ifndef _NO_EXTENSIONS
2984 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) buffer
[12] = 'D';
2985 if (attrs
& FILE_ATTRIBUTE_ENCRYPTED
) buffer
[14] = 'E';
2986 if (attrs
& FILE_ATTRIBUTE_TEMPORARY
) buffer
[16] = 'T';
2987 if (attrs
& FILE_ATTRIBUTE_SPARSE_FILE
) buffer
[18] = 'P';
2988 if (attrs
& FILE_ATTRIBUTE_REPARSE_POINT
) buffer
[20] = 'Q';
2989 if (attrs
& FILE_ATTRIBUTE_OFFLINE
) buffer
[22] = 'O';
2990 if (attrs
& FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
) buffer
[24] = 'X';
2991 #endif /* _NO_EXTENSIONS */
2994 if (calcWidthCol
== -1)
2995 output_tabbed_text(pane
, dis
, col
, buffer
);
2996 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2997 calc_tabbed_width(pane
, dis
, col
, buffer
);
3003 if (flags.security) {
3004 const static TCHAR sSecTabs[] = {
3005 ' ','\t',' ','\t',' ','\t',' ',
3007 ' ','\t',' ','\t',' ','\t',' ',
3009 ' ','\t',' ','\t',' ','\t',' ',
3013 DWORD rights = get_access_mask();
3015 tcscpy(buffer, sSecTabs);
3017 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
3018 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
3019 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
3020 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
3021 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
3022 if (rights & FILE_EXECUTE) buffer[12] = 'X';
3023 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
3024 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
3025 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
3026 if (rights & WRITE_DAC) buffer[22] = 'C';
3027 if (rights & WRITE_OWNER) buffer[24] = 'O';
3028 if (rights & SYNCHRONIZE) buffer[26] = 'S';
3030 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
3033 if (flags.description) {
3034 get_description(buffer);
3035 output_text(dis, col++, buffer, 0, psize);
3039 #ifdef _NO_EXTENSIONS
3042 /* draw focus frame */
3043 if ((dis
->itemState
&ODS_FOCUS
) && calcWidthCol
==-1) {
3044 /* Currently [04/2000] Wine neither behaves exactly the same */
3045 /* way as WIN 95 nor like Windows NT... */
3050 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
3051 LOGBRUSH lb
= {PS_SOLID
, RGB(255,255,255)};
3052 hpen
= ExtCreatePen(PS_COSMETIC
|PS_ALTERNATE
, 1, &lb
, 0, 0);
3054 hpen
= CreatePen(PS_DOT
, 0, RGB(255,255,255));
3056 lastPen
= SelectPen(dis
->hDC
, hpen
);
3057 lastBrush
= SelectObject(dis
->hDC
, GetStockObject(HOLLOW_BRUSH
));
3058 SetROP2(dis
->hDC
, R2_XORPEN
);
3059 Rectangle(dis
->hDC
, focusRect
.left
, focusRect
.top
, focusRect
.right
, focusRect
.bottom
);
3060 SelectObject(dis
->hDC
, lastBrush
);
3061 SelectObject(dis
->hDC
, lastPen
);
3064 #endif /* _NO_EXTENSIONS */
3068 #ifdef _NO_EXTENSIONS
3070 static void draw_splitbar(HWND hwnd
, int x
)
3073 HDC hdc
= GetDC(hwnd
);
3075 GetClientRect(hwnd
, &rt
);
3077 rt
.left
= x
- SPLIT_WIDTH
/2;
3078 rt
.right
= x
+ SPLIT_WIDTH
/2+1;
3080 InvertRect(hdc
, &rt
);
3082 ReleaseDC(hwnd
, hdc
);
3085 #endif /* _NO_EXTENSIONS */
3088 #ifndef _NO_EXTENSIONS
3090 static void set_header(Pane
* pane
)
3093 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3096 item
.mask
= HDI_WIDTH
;
3099 for(; x
+pane
->widths
[i
]<scroll_pos
&& i
<COLUMNS
; i
++) {
3100 x
+= pane
->widths
[i
];
3101 Header_SetItem(pane
->hwndHeader
, i
, &item
);
3105 x
+= pane
->widths
[i
];
3106 item
.cxy
= x
- scroll_pos
;
3107 Header_SetItem(pane
->hwndHeader
, i
++, &item
);
3109 for(; i
<COLUMNS
; i
++) {
3110 item
.cxy
= pane
->widths
[i
];
3111 x
+= pane
->widths
[i
];
3112 Header_SetItem(pane
->hwndHeader
, i
, &item
);
3117 static LRESULT
pane_notify(Pane
* pane
, NMHDR
* pnmh
)
3119 switch(pnmh
->code
) {
3121 case HDN_ENDTRACK
: {
3122 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3123 int idx
= phdn
->iItem
;
3124 int dx
= phdn
->pitem
->cxy
- pane
->widths
[idx
];
3128 GetClientRect(pane
->hwnd
, &clnt
);
3130 /* move immediate to simulate HDS_FULLDRAG (for now [04/2000] not really needed with WINELIB) */
3131 Header_SetItem(pane
->hwndHeader
, idx
, phdn
->pitem
);
3133 pane
->widths
[idx
] += dx
;
3135 for(i
=idx
; ++i
<=COLUMNS
; )
3136 pane
->positions
[i
] += dx
;
3139 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3143 rt_scr
.left
= pane
->positions
[idx
+1]-scroll_pos
;
3145 rt_scr
.right
= clnt
.right
;
3146 rt_scr
.bottom
= clnt
.bottom
;
3148 rt_clip
.left
= pane
->positions
[idx
]-scroll_pos
;
3150 rt_clip
.right
= clnt
.right
;
3151 rt_clip
.bottom
= clnt
.bottom
;
3153 if (rt_scr
.left
< 0) rt_scr
.left
= 0;
3154 if (rt_clip
.left
< 0) rt_clip
.left
= 0;
3156 ScrollWindowEx(pane
->hwnd
, dx
, 0, &rt_scr
, &rt_clip
, 0, 0, SW_INVALIDATE
);
3158 rt_clip
.right
= pane
->positions
[idx
+1];
3159 RedrawWindow(pane
->hwnd
, &rt_clip
, 0, RDW_INVALIDATE
|RDW_UPDATENOW
);
3161 if (pnmh
->code
== HDN_ENDTRACK
) {
3162 ListBox_SetHorizontalExtent(pane
->hwnd
, pane
->positions
[COLUMNS
]);
3164 if (GetScrollPos(pane
->hwnd
, SB_HORZ
) != scroll_pos
)
3172 case HDN_DIVIDERDBLCLICK
: {
3173 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3176 calc_single_width(pane
, phdn
->iItem
);
3177 item
.mask
= HDI_WIDTH
;
3178 item
.cxy
= pane
->widths
[phdn
->iItem
];
3180 Header_SetItem(pane
->hwndHeader
, phdn
->iItem
, &item
);
3181 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3188 #endif /* _NO_EXTENSIONS */
3191 static void scan_entry(ChildWnd
* child
, Entry
* entry
, HWND hwnd
)
3193 TCHAR path
[MAX_PATH
];
3194 int idx
= ListBox_GetCurSel(child
->left
.hwnd
);
3195 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
3197 /* delete sub entries in left pane */
3199 LRESULT res
= ListBox_GetItemData(child
->left
.hwnd
, idx
+1);
3200 Entry
* sub
= (Entry
*) res
;
3202 if (res
==LB_ERR
|| !sub
|| sub
->level
<=entry
->level
)
3205 ListBox_DeleteString(child
->left
.hwnd
, idx
+1);
3208 /* empty right pane */
3209 ListBox_ResetContent(child
->right
.hwnd
);
3211 /* release memory */
3212 free_entries(entry
);
3214 /* read contents from disk */
3215 #ifdef _SHELL_FOLDERS
3216 if (entry
->etype
== ET_SHELL
)
3218 read_directory(entry
, NULL
, child
->sortOrder
, hwnd
);
3223 get_path(entry
, path
);
3224 read_directory(entry
, path
, child
->sortOrder
, hwnd
);
3227 /* insert found entries in right pane */
3228 insert_entries(&child
->right
, entry
->down
, -1);
3229 calc_widths(&child
->right
, FALSE
);
3230 #ifndef _NO_EXTENSIONS
3231 set_header(&child
->right
);
3234 child
->header_wdths_ok
= FALSE
;
3236 SetCursor(old_cursor
);
3240 /* expand a directory entry */
3242 static BOOL
expand_entry(ChildWnd
* child
, Entry
* dir
)
3247 if (!dir
|| dir
->expanded
|| !dir
->down
)
3252 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='\0' && p
->next
) {
3255 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='.' &&
3256 p
->data
.cFileName
[2]=='\0' && p
->next
)
3260 /* no subdirectories ? */
3261 if (!(p
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
3264 idx
= ListBox_FindItemData(child
->left
.hwnd
, 0, dir
);
3266 dir
->expanded
= TRUE
;
3268 /* insert entries in left pane */
3269 insert_entries(&child
->left
, p
, idx
);
3271 if (!child
->header_wdths_ok
) {
3272 if (calc_widths(&child
->left
, FALSE
)) {
3273 #ifndef _NO_EXTENSIONS
3274 set_header(&child
->left
);
3277 child
->header_wdths_ok
= TRUE
;
3285 static void collapse_entry(Pane
* pane
, Entry
* dir
)
3287 int idx
= ListBox_FindItemData(pane
->hwnd
, 0, dir
);
3289 ShowWindow(pane
->hwnd
, SW_HIDE
);
3291 /* hide sub entries */
3293 LRESULT res
= ListBox_GetItemData(pane
->hwnd
, idx
+1);
3294 Entry
* sub
= (Entry
*) res
;
3296 if (res
==LB_ERR
|| !sub
|| sub
->level
<=dir
->level
)
3299 ListBox_DeleteString(pane
->hwnd
, idx
+1);
3302 dir
->expanded
= FALSE
;
3304 ShowWindow(pane
->hwnd
, SW_SHOW
);
3308 static void set_curdir(ChildWnd
* child
, Entry
* entry
, HWND hwnd
)
3310 TCHAR path
[MAX_PATH
];
3314 child
->left
.cur
= entry
;
3315 child
->right
.root
= entry
->down
? entry
->down
: entry
;
3316 child
->right
.cur
= entry
;
3318 if (!entry
->scanned
)
3319 scan_entry(child
, entry
, hwnd
);
3321 ListBox_ResetContent(child
->right
.hwnd
);
3322 insert_entries(&child
->right
, entry
->down
, -1);
3323 calc_widths(&child
->right
, FALSE
);
3324 #ifndef _NO_EXTENSIONS
3325 set_header(&child
->right
);
3329 get_path(entry
, path
);
3330 lstrcpy(child
->path
, path
);
3332 if (child
->hwnd
) /* only change window title, if the window already exists */
3333 SetWindowText(child
->hwnd
, path
);
3336 if (SetCurrentDirectory(path
))
3341 BOOL
launch_file(HWND hwnd
, LPCTSTR cmd
, UINT nCmdShow
)
3343 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3345 if ((int)hinst
<= 32) {
3346 display_error(hwnd
, GetLastError());
3354 BOOL
launch_fileA(HWND hwnd
, LPSTR cmd
, UINT nCmdShow
)
3356 HINSTANCE hinst
= ShellExecuteA(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3358 if ((int)hinst
<= 32) {
3359 display_error(hwnd
, GetLastError());
3368 BOOL
launch_entry(Entry
* entry
, HWND hwnd
, UINT nCmdShow
)
3370 TCHAR cmd
[MAX_PATH
];
3372 #ifdef _SHELL_FOLDERS
3373 if (entry
->etype
== ET_SHELL
) {
3376 SHELLEXECUTEINFO shexinfo
;
3378 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFO
);
3379 shexinfo
.fMask
= SEE_MASK_IDLIST
;
3380 shexinfo
.hwnd
= hwnd
;
3381 shexinfo
.lpVerb
= NULL
;
3382 shexinfo
.lpFile
= NULL
;
3383 shexinfo
.lpParameters
= NULL
;
3384 shexinfo
.lpDirectory
= NULL
;
3385 shexinfo
.nShow
= nCmdShow
;
3386 shexinfo
.lpIDList
= get_to_absolute_pidl(entry
, hwnd
);
3388 if (!ShellExecuteEx(&shexinfo
)) {
3389 display_error(hwnd
, GetLastError());
3393 if (shexinfo
.lpIDList
!= entry
->pidl
)
3394 (*Globals
.iMalloc
->lpVtbl
->Free
)(Globals
.iMalloc
, shexinfo
.lpIDList
);
3400 get_path(entry
, cmd
);
3402 /* start program, open document... */
3403 return launch_file(hwnd
, cmd
, nCmdShow
);
3407 static void activate_entry(ChildWnd
* child
, Pane
* pane
, HWND hwnd
)
3409 Entry
* entry
= pane
->cur
;
3414 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
3415 int scanned_old
= entry
->scanned
;
3418 scan_entry(child
, entry
, hwnd
);
3420 #ifndef _NO_EXTENSIONS
3421 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='\0')
3425 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='.' && entry
->data
.cFileName
[2]=='\0') {
3426 entry
= child
->left
.cur
->up
;
3427 collapse_entry(&child
->left
, entry
);
3429 } else if (entry
->expanded
)
3430 collapse_entry(pane
, child
->left
.cur
);
3432 expand_entry(child
, child
->left
.cur
);
3434 if (!pane
->treePane
) focus_entry
: {
3435 int idx
= ListBox_FindItemData(child
->left
.hwnd
, ListBox_GetCurSel(child
->left
.hwnd
), entry
);
3436 ListBox_SetCurSel(child
->left
.hwnd
, idx
);
3437 set_curdir(child
, entry
, hwnd
);
3442 calc_widths(pane
, FALSE
);
3444 #ifndef _NO_EXTENSIONS
3449 launch_entry(entry
, child
->hwnd
, SW_SHOWNORMAL
);
3454 static BOOL
pane_command(Pane
* pane
, UINT cmd
)
3458 if (pane
->visible_cols
) {
3459 pane
->visible_cols
= 0;
3460 calc_widths(pane
, TRUE
);
3461 #ifndef _NO_EXTENSIONS
3464 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3465 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
|MF_CHECKED
);
3466 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
);
3467 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
3471 case ID_VIEW_ALL_ATTRIBUTES
:
3472 if (pane
->visible_cols
!= COL_ALL
) {
3473 pane
->visible_cols
= COL_ALL
;
3474 calc_widths(pane
, TRUE
);
3475 #ifndef _NO_EXTENSIONS
3478 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3479 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
);
3480 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
|MF_CHECKED
);
3481 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
3485 #ifndef _NO_EXTENSIONS
3486 case ID_PREFERRED_SIZES
: {
3487 calc_widths(pane
, TRUE
);
3489 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3493 /* TODO: more command ids... */
3503 static IContextMenu2
* s_pctxmenu2
= NULL
;
3505 #ifndef __MINGW32__ /* IContextMenu3 missing in MinGW (as of 6.2.2005) */
3506 static IContextMenu3
* s_pctxmenu3
= NULL
;
3509 static void CtxMenu_reset()
3513 #ifndef __MINGW32__ /* IContextMenu3 missing in MinGW (as of 6.2.2005) */
3518 IContextMenu
* CtxMenu_query_interfaces(IContextMenu
* pcm1
)
3520 IContextMenu
* pcm
= NULL
;
3524 #ifndef __MINGW32__ /* IContextMenu3 missing in MinGW (as of 6.2.2005) */
3525 if ((*pcm1
->lpVtbl
->QueryInterface
)(pcm1
, &IID_IContextMenu3
, (void**)&pcm
) == NOERROR
)
3526 s_pctxmenu3
= (LPCONTEXTMENU3
)pcm
;
3529 if ((*pcm1
->lpVtbl
->QueryInterface
)(pcm1
, &IID_IContextMenu2
, (void**)&pcm
) == NOERROR
)
3530 s_pctxmenu2
= (LPCONTEXTMENU2
)pcm
;
3533 (*pcm1
->lpVtbl
->Release
)(pcm1
);
3539 static BOOL
CtxMenu_HandleMenuMsg(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3541 #ifndef __MINGW32__ /* IContextMenu3 missing in MinGW (as of 6.2.2005) */
3543 if (SUCCEEDED((*s_pctxmenu3
->lpVtbl
->HandleMenuMsg
)(s_pctxmenu3
, nmsg
, wparam
, lparam
)))
3549 if (SUCCEEDED((*s_pctxmenu2
->lpVtbl
->HandleMenuMsg
)(s_pctxmenu2
, nmsg
, wparam
, lparam
)))
3556 static HRESULT
ShellFolderContextMenu(IShellFolder
* shell_folder
, HWND hwndParent
, int cidl
, LPCITEMIDLIST
* apidl
, int x
, int y
)
3560 HRESULT hr
= (*shell_folder
->lpVtbl
->GetUIObjectOf
)(shell_folder
, hwndParent
, cidl
, apidl
, &IID_IContextMenu
, NULL
, (LPVOID
*)&pcm
);
3561 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
3563 if (SUCCEEDED(hr
)) {
3564 HMENU hmenu
= CreatePopupMenu();
3566 pcm
= CtxMenu_query_interfaces(pcm
);
3569 hr
= (*pcm
->lpVtbl
->QueryContextMenu
)(pcm
, hmenu
, 0, FCIDM_SHVIEWFIRST
, FCIDM_SHVIEWLAST
, CMF_NORMAL
);
3571 if (SUCCEEDED(hr
)) {
3572 UINT idCmd
= TrackPopupMenu(hmenu
, TPM_LEFTALIGN
|TPM_RETURNCMD
|TPM_RIGHTBUTTON
, x
, y
, 0, hwndParent
, NULL
);
3577 CMINVOKECOMMANDINFO cmi
;
3579 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFO
);
3581 cmi
.hwnd
= hwndParent
;
3582 cmi
.lpVerb
= (LPCSTR
)(INT_PTR
)(idCmd
- FCIDM_SHVIEWFIRST
);
3583 cmi
.lpParameters
= NULL
;
3584 cmi
.lpDirectory
= NULL
;
3585 cmi
.nShow
= SW_SHOWNORMAL
;
3589 hr
= (*pcm
->lpVtbl
->InvokeCommand
)(pcm
, &cmi
);
3595 (*pcm
->lpVtbl
->Release
)(pcm
);
3602 LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3604 static int last_split
;
3606 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(hwnd
, GWL_USERDATA
);
3611 LPDRAWITEMSTRUCT dis
= (LPDRAWITEMSTRUCT
)lparam
;
3612 Entry
* entry
= (Entry
*) dis
->itemData
;
3614 if (dis
->CtlID
== IDW_TREE_LEFT
)
3615 draw_item(&child
->left
, dis
, entry
, -1);
3616 else if (dis
->CtlID
== IDW_TREE_RIGHT
)
3617 draw_item(&child
->right
, dis
, entry
, -1);
3619 goto draw_menu_item
;
3624 InitChildWindow(child
);
3628 free_child_window(child
);
3629 SetWindowLong(hwnd
, GWL_USERDATA
, 0);
3636 GetClientRect(hwnd
, &rt
);
3637 BeginPaint(hwnd
, &ps
);
3638 rt
.left
= child
->split_pos
-SPLIT_WIDTH
/2;
3639 rt
.right
= child
->split_pos
+SPLIT_WIDTH
/2+1;
3640 lastBrush
= SelectBrush(ps
.hdc
, (HBRUSH
)GetStockObject(COLOR_SPLITBAR
));
3641 Rectangle(ps
.hdc
, rt
.left
, rt
.top
-1, rt
.right
, rt
.bottom
+1);
3642 SelectObject(ps
.hdc
, lastBrush
);
3643 #ifdef _NO_EXTENSIONS
3644 rt
.top
= rt
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
3645 FillRect(ps
.hdc
, &rt
, GetStockObject(BLACK_BRUSH
));
3647 EndPaint(hwnd
, &ps
);
3651 if (LOWORD(lparam
) == HTCLIENT
) {
3654 ScreenToClient(hwnd
, &pt
);
3656 if (pt
.x
>=child
->split_pos
-SPLIT_WIDTH
/2 && pt
.x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
3657 SetCursor(LoadCursor(0, IDC_SIZEWE
));
3663 case WM_LBUTTONDOWN
: {
3665 int x
= GET_X_LPARAM(lparam
);
3667 GetClientRect(hwnd
, &rt
);
3669 if (x
>=child
->split_pos
-SPLIT_WIDTH
/2 && x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
3670 last_split
= child
->split_pos
;
3671 #ifdef _NO_EXTENSIONS
3672 draw_splitbar(hwnd
, last_split
);
3680 if (GetCapture() == hwnd
) {
3681 #ifdef _NO_EXTENSIONS
3683 int x
= LOWORD(lparam
);
3684 draw_splitbar(hwnd
, last_split
);
3686 GetClientRect(hwnd
, &rt
);
3687 child
->split_pos
= x
;
3688 resize_tree(child
, rt
.right
, rt
.bottom
);
3694 #ifdef _NO_EXTENSIONS
3695 case WM_CAPTURECHANGED
:
3696 if (GetCapture()==hwnd
&& last_split
>=0)
3697 draw_splitbar(hwnd
, last_split
);
3702 if (wparam
== VK_ESCAPE
)
3703 if (GetCapture() == hwnd
) {
3705 #ifdef _NO_EXTENSIONS
3706 draw_splitbar(hwnd
, last_split
);
3708 child
->split_pos
= last_split
;
3710 GetClientRect(hwnd
, &rt
);
3711 resize_tree(child
, rt
.right
, rt
.bottom
);
3714 SetCursor(LoadCursor(0, IDC_ARROW
));
3719 if (GetCapture() == hwnd
) {
3721 int x
= LOWORD(lparam
);
3723 #ifdef _NO_EXTENSIONS
3724 HDC hdc
= GetDC(hwnd
);
3725 GetClientRect(hwnd
, &rt
);
3727 rt
.left
= last_split
-SPLIT_WIDTH
/2;
3728 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
3729 InvertRect(hdc
, &rt
);
3732 rt
.left
= x
-SPLIT_WIDTH
/2;
3733 rt
.right
= x
+SPLIT_WIDTH
/2+1;
3734 InvertRect(hdc
, &rt
);
3736 ReleaseDC(hwnd
, hdc
);
3738 GetClientRect(hwnd
, &rt
);
3740 if (x
>=0 && x
<rt
.right
) {
3741 child
->split_pos
= x
;
3742 resize_tree(child
, rt
.right
, rt
.bottom
);
3743 rt
.left
= x
-SPLIT_WIDTH
/2;
3744 rt
.right
= x
+SPLIT_WIDTH
/2+1;
3745 InvalidateRect(hwnd
, &rt
, FALSE
);
3746 UpdateWindow(child
->left
.hwnd
);
3748 UpdateWindow(child
->right
.hwnd
);
3754 #ifndef _NO_EXTENSIONS
3755 case WM_GETMINMAXINFO
:
3756 DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
3758 {LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
3760 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
3761 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
3763 #endif /* _NO_EXTENSIONS */
3766 if (SetCurrentDirectory(child
->path
))
3768 SetFocus(child
->focus_pane
? child
->right
.hwnd
: child
->left
.hwnd
);
3771 case WM_DISPATCH_COMMAND
: {
3772 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
3774 switch(LOWORD(wparam
)) {
3775 case ID_WINDOW_NEW
: {
3776 ChildWnd
* new_child
= alloc_child_window(child
->path
, NULL
, hwnd
);
3778 if (!create_child_window(new_child
))
3784 scan_entry(child
, pane
->cur
, hwnd
);
3788 activate_entry(child
, pane
, hwnd
);
3791 case ID_FILE_MOVE
: {
3792 TCHAR new_name
[BUFFER_LEN
], old_name
[BUFFER_LEN
];
3795 get_path(pane
->cur
, new_name
);
3797 ret
= DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_SELECT_DESTINATION
), hwnd
, DestinationDlgProc
, (LPARAM
)new_name
);
3801 if (new_name
[0]!='/' && new_name
[1]!=':') {
3802 get_path(pane
->cur
->up
, old_name
);
3803 len
= lstrlen(old_name
);
3805 if (old_name
[len
-1]!='\\' && old_name
[len
-1]!='/')
3806 old_name
[len
++] = '/';
3808 lstrcpy(old_name
+len
, new_name
);
3809 lstrcpy(new_name
, old_name
);
3812 get_path(pane
->cur
, old_name
);
3814 if (MoveFileEx(old_name
, new_name
, MOVEFILE_COPY_ALLOWED
)) {
3815 if (pane
->treePane
) {
3816 pane
->root
->scanned
= FALSE
;
3817 pane
->cur
= pane
->root
;
3818 activate_entry(child
, pane
, hwnd
);
3821 scan_entry(child
, pane
->root
, hwnd
);
3824 display_error(hwnd
, GetLastError());
3828 return pane_command(pane
, LOWORD(wparam
));
3834 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
3836 switch(HIWORD(wparam
)) {
3837 case LBN_SELCHANGE
: {
3838 int idx
= ListBox_GetCurSel(pane
->hwnd
);
3839 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, idx
);
3841 if (pane
== &child
->left
)
3842 set_curdir(child
, entry
, hwnd
);
3848 activate_entry(child
, pane
, hwnd
);
3853 #ifndef _NO_EXTENSIONS
3855 NMHDR
* pnmh
= (NMHDR
*) lparam
;
3856 return pane_notify(pnmh
->idFrom
==IDW_HEADER_LEFT
? &child
->left
: &child
->right
, pnmh
);}
3859 #ifdef _SHELL_FOLDERS
3860 case WM_CONTEXTMENU
: {
3865 /* first select the current item in the listbox */
3866 HWND hpanel
= (HWND
) wparam
;
3867 pt_clnt
.x
= pt
.x
= (short)LOWORD(lparam
);
3868 pt_clnt
.y
= pt
.y
= (short)HIWORD(lparam
);
3869 ScreenToClient(hpanel
, &pt_clnt
);
3870 SendMessage(hpanel
, WM_LBUTTONDOWN
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
3871 SendMessage(hpanel
, WM_LBUTTONUP
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
3873 /* now create the popup menu using shell namespace and IContextMenu */
3874 pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
3875 idx
= ListBox_GetCurSel(pane
->hwnd
);
3879 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, idx
);
3881 LPITEMIDLIST pidl_abs
= get_to_absolute_pidl(entry
, hwnd
);
3884 IShellFolder
* parentFolder
;
3885 LPCITEMIDLIST pidlLast
;
3887 /* get and use the parent folder to display correct context menu in all cases */
3888 if (SUCCEEDED(SHBindToParent(pidl_abs
, &IID_IShellFolder
, (LPVOID
*)&parentFolder
, &pidlLast
))) {
3889 hr
= ShellFolderContextMenu(parentFolder
, hwnd
, 1, &pidlLast
, pt
.x
, pt
.y
);
3891 (*parentFolder
->lpVtbl
->Release
)(parentFolder
);
3894 (*Globals
.iMalloc
->lpVtbl
->Free
)(Globals
.iMalloc
, pidl_abs
);
3900 case WM_MEASUREITEM
:
3902 if (!wparam
) /* Is the message menu-related? */
3903 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
3908 case WM_INITMENUPOPUP
:
3909 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
3914 #ifndef __MINGW32__ /* IContextMenu3 missing in MinGW (as of 6.2.2005) */
3915 case WM_MENUCHAR
: /* only supported by IContextMenu3 */
3917 LRESULT lResult
= 0;
3919 (*s_pctxmenu3
->lpVtbl
->HandleMenuMsg2
)(s_pctxmenu3
, nmsg
, wparam
, lparam
, &lResult
);
3928 if (wparam
!= SIZE_MINIMIZED
)
3929 resize_tree(child
, LOWORD(lparam
), HIWORD(lparam
));
3933 return DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
3940 LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3942 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(GetParent(hwnd
), GWL_USERDATA
);
3943 Pane
* pane
= (Pane
*) GetWindowLong(hwnd
, GWL_USERDATA
);
3947 #ifndef _NO_EXTENSIONS
3954 child
->focus_pane
= pane
==&child
->right
? 1: 0;
3955 ListBox_SetSel(hwnd
, TRUE
, 1);
3956 /*TODO: check menu items */
3960 if (wparam
== VK_TAB
) {
3961 /*TODO: SetFocus(Globals.hdrivebar) */
3962 SetFocus(child
->focus_pane
? child
->left
.hwnd
: child
->right
.hwnd
);
3966 return CallWindowProc(g_orgTreeWndProc
, hwnd
, nmsg
, wparam
, lparam
);
3970 static void InitInstance(HINSTANCE hinstance
)
3972 const static TCHAR sFont
[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
3979 INITCOMMONCONTROLSEX icc
= {
3980 sizeof(INITCOMMONCONTROLSEX
),
3986 setlocale(LC_COLLATE
, ""); /* set collating rules to local settings for compareName */
3988 InitCommonControlsEx(&icc
);
3991 /* register frame window class */
3993 wcFrame
.cbSize
= sizeof(WNDCLASSEX
);
3995 wcFrame
.lpfnWndProc
= FrameWndProc
;
3996 wcFrame
.cbClsExtra
= 0;
3997 wcFrame
.cbWndExtra
= 0;
3998 wcFrame
.hInstance
= hinstance
;
3999 wcFrame
.hIcon
= LoadIcon(hinstance
, MAKEINTRESOURCE(IDI_WINEFILE
));
4000 wcFrame
.hCursor
= LoadCursor(0, IDC_ARROW
);
4001 wcFrame
.hbrBackground
= 0;
4002 wcFrame
.lpszMenuName
= 0;
4003 wcFrame
.lpszClassName
= sWINEFILEFRAME
;
4004 wcFrame
.hIconSm
= (HICON
)LoadImage(hinstance
,
4005 MAKEINTRESOURCE(IDI_WINEFILE
),
4007 GetSystemMetrics(SM_CXSMICON
),
4008 GetSystemMetrics(SM_CYSMICON
),
4011 Globals
.hframeClass
= RegisterClassEx(&wcFrame
);
4014 /* register tree windows class */
4016 wcChild
.style
= CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
;
4017 wcChild
.lpfnWndProc
= ChildWndProc
;
4018 wcChild
.cbClsExtra
= 0;
4019 wcChild
.cbWndExtra
= 0;
4020 wcChild
.hInstance
= hinstance
;
4022 wcChild
.hCursor
= LoadCursor(0, IDC_ARROW
);
4023 wcChild
.hbrBackground
= 0;
4024 wcChild
.lpszMenuName
= 0;
4025 wcChild
.lpszClassName
= sWINEFILETREE
;
4027 hChildClass
= RegisterClass(&wcChild
);
4030 Globals
.haccel
= LoadAccelerators(hinstance
, MAKEINTRESOURCE(IDA_WINEFILE
));
4032 Globals
.hfont
= CreateFont(-MulDiv(8,GetDeviceCaps(hdc
,LOGPIXELSY
),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont
);
4036 Globals
.hInstance
= hinstance
;
4038 #ifdef _SHELL_FOLDERS
4040 CoGetMalloc(MEMCTX_TASK
, &Globals
.iMalloc
);
4041 SHGetDesktopFolder(&Globals
.iDesktop
);
4043 Globals
.cfStrFName
= RegisterClipboardFormatA(CFSTR_FILENAME
);
4045 Globals
.cfStrFName
= RegisterClipboardFormat(CFSTR_FILENAME
);
4049 /* load column strings */
4052 load_string(g_pos_names
[col
++], IDS_COL_NAME
);
4053 load_string(g_pos_names
[col
++], IDS_COL_SIZE
);
4054 load_string(g_pos_names
[col
++], IDS_COL_CDATE
);
4055 #ifndef _NO_EXTENSIONS
4056 load_string(g_pos_names
[col
++], IDS_COL_ADATE
);
4057 load_string(g_pos_names
[col
++], IDS_COL_MDATE
);
4058 load_string(g_pos_names
[col
++], IDS_COL_IDX
);
4059 load_string(g_pos_names
[col
++], IDS_COL_LINKS
);
4061 load_string(g_pos_names
[col
++], IDS_COL_ATTR
);
4062 #ifndef _NO_EXTENSIONS
4063 load_string(g_pos_names
[col
++], IDS_COL_SEC
);
4068 void show_frame(HWND hwndParent
, int cmdshow
)
4070 const static TCHAR sMDICLIENT
[] = {'M','D','I','C','L','I','E','N','T','\0'};
4072 TCHAR path
[MAX_PATH
], b1
[BUFFER_LEN
];
4074 HMENU hMenuFrame
, hMenuWindow
;
4076 CLIENTCREATESTRUCT ccs
;
4078 if (Globals
.hMainWnd
)
4081 Globals
.hwndParent
= hwndParent
;
4083 hMenuFrame
= LoadMenu(Globals
.hInstance
, MAKEINTRESOURCE(IDM_WINEFILE
));
4084 hMenuWindow
= GetSubMenu(hMenuFrame
, GetMenuItemCount(hMenuFrame
)-2);
4086 Globals
.hMenuFrame
= hMenuFrame
;
4087 Globals
.hMenuView
= GetSubMenu(hMenuFrame
, 3);
4088 Globals
.hMenuOptions
= GetSubMenu(hMenuFrame
, 4);
4090 ccs
.hWindowMenu
= hMenuWindow
;
4091 ccs
.idFirstChild
= IDW_FIRST_CHILD
;
4094 /* create main window */
4095 Globals
.hMainWnd
= CreateWindowEx(0, (LPCTSTR
)(int)Globals
.hframeClass
, RS(b1
,IDS_WINE_FILE
), WS_OVERLAPPEDWINDOW
,
4096 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
4097 hwndParent
, Globals
.hMenuFrame
, Globals
.hInstance
, 0/*lpParam*/);
4100 Globals
.hmdiclient
= CreateWindowEx(0, sMDICLIENT
, NULL
,
4101 WS_CHILD
|WS_CLIPCHILDREN
|WS_VSCROLL
|WS_HSCROLL
|WS_VISIBLE
|WS_BORDER
,
4103 Globals
.hMainWnd
, 0, Globals
.hInstance
, &ccs
);
4107 TBBUTTON drivebarBtn
= {0, 0, TBSTATE_ENABLED
, BTNS_SEP
, {0, 0}, 0, 0};
4111 Globals
.hdrivebar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
,
4112 IDW_DRIVEBAR
, 2, Globals
.hInstance
, IDB_DRIVEBAR
, &drivebarBtn
,
4113 1, 16, 13, 16, 13, sizeof(TBBUTTON
));
4114 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_DRIVE_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4116 GetLogicalDriveStrings(BUFFER_LEN
, Globals
.drives
);
4118 drivebarBtn
.fsStyle
= BTNS_BUTTON
;
4120 #ifndef _NO_EXTENSIONS
4122 /* insert unix file system button */
4126 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
4128 drivebarBtn
.idCommand
= ID_DRIVE_UNIX_FS
;
4129 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
4130 drivebarBtn
.iString
++;
4132 #ifdef _SHELL_FOLDERS
4133 /* insert shell namespace button */
4134 load_string(b1
, IDS_SHELL
);
4135 b1
[lstrlen(b1
)+1] = '\0';
4136 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
4138 drivebarBtn
.idCommand
= ID_DRIVE_SHELL_NS
;
4139 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
4140 drivebarBtn
.iString
++;
4143 /* register windows drive root strings */
4144 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)Globals
.drives
);
4147 drivebarBtn
.idCommand
= ID_DRIVE_FIRST
;
4149 for(p
=Globals
.drives
; *p
; ) {
4150 #ifdef _NO_EXTENSIONS
4151 /* insert drive letter */
4152 TCHAR b
[3] = {tolower(*p
)};
4153 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b
);
4155 switch(GetDriveType(p
)) {
4156 case DRIVE_REMOVABLE
: drivebarBtn
.iBitmap
= 1; break;
4157 case DRIVE_CDROM
: drivebarBtn
.iBitmap
= 3; break;
4158 case DRIVE_REMOTE
: drivebarBtn
.iBitmap
= 4; break;
4159 case DRIVE_RAMDISK
: drivebarBtn
.iBitmap
= 5; break;
4160 default:/*DRIVE_FIXED*/ drivebarBtn
.iBitmap
= 2;
4163 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
4164 drivebarBtn
.idCommand
++;
4165 drivebarBtn
.iString
++;
4172 TBBUTTON toolbarBtns
[] = {
4173 {0, 0, 0, BTNS_SEP
, {0, 0}, 0, 0},
4174 {0, ID_WINDOW_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4175 {1, ID_WINDOW_CASCADE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4176 {2, ID_WINDOW_TILE_HORZ
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4177 {3, ID_WINDOW_TILE_VERT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4179 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4180 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4183 Globals
.htoolbar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
,
4184 IDW_TOOLBAR
, 2, Globals
.hInstance
, IDB_TOOLBAR
, toolbarBtns
,
4185 sizeof(toolbarBtns
)/sizeof(TBBUTTON
), 16, 15, 16, 15, sizeof(TBBUTTON
));
4186 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_TOOL_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4189 Globals
.hstatusbar
= CreateStatusWindow(WS_CHILD
|WS_VISIBLE
, 0, Globals
.hMainWnd
, IDW_STATUSBAR
);
4190 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
4192 /* CreateStatusWindow does not accept WS_BORDER
4193 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
4194 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
4195 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
4197 /*TODO: read paths and window placements from registry */
4198 GetCurrentDirectory(MAX_PATH
, path
);
4200 ShowWindow(Globals
.hMainWnd
, cmdshow
);
4202 //#if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4203 // // Shell Namespace as default:
4204 // child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
4206 child
= alloc_child_window(path
, NULL
, Globals
.hMainWnd
);
4209 child
->pos
.showCmd
= SW_SHOWMAXIMIZED
;
4210 child
->pos
.rcNormalPosition
.left
= 0;
4211 child
->pos
.rcNormalPosition
.top
= 0;
4212 child
->pos
.rcNormalPosition
.right
= 320;
4213 child
->pos
.rcNormalPosition
.bottom
= 280;
4215 if (!create_child_window(child
))
4218 SetWindowPlacement(child
->hwnd
, &child
->pos
);
4220 Globals
.himl
= ImageList_LoadBitmap(Globals
.hInstance
, MAKEINTRESOURCE(IDB_IMAGES
), 16, 0, RGB(0,255,0));
4222 Globals
.prescan_node
= FALSE
;
4224 UpdateWindow(Globals
.hMainWnd
);
4229 #ifdef _SHELL_FOLDERS
4230 (*Globals
.iDesktop
->lpVtbl
->Release
)(Globals
.iDesktop
);
4231 (*Globals
.iMalloc
->lpVtbl
->Release
)(Globals
.iMalloc
);
4235 ImageList_Destroy(Globals
.himl
);
4239 /* search for already running win[e]files */
4241 static int g_foundPrevInstance
= 0;
4243 static BOOL CALLBACK
EnumWndProc(HWND hwnd
, LPARAM lparam
)
4247 GetClassName(hwnd
, cls
, 128);
4249 if (!lstrcmp(cls
, (LPCTSTR
)lparam
)) {
4250 g_foundPrevInstance
++;
4257 /* search for window of given class name to allow only one running instance */
4258 int find_window_class(LPCTSTR classname
)
4260 EnumWindows(EnumWndProc
, (LPARAM
)classname
);
4262 if (g_foundPrevInstance
)
4269 int winefile_main(HINSTANCE hinstance
, HWND hwndParent
, int cmdshow
)
4273 InitInstance(hinstance
);
4275 if (cmdshow
== SW_SHOWNORMAL
)
4276 /*TODO: read window placement from registry */
4277 cmdshow
= SW_MAXIMIZE
;
4279 show_frame(hwndParent
, cmdshow
);
4281 while(GetMessage(&msg
, 0, 0, 0)) {
4282 if (Globals
.hmdiclient
&& TranslateMDISysAccel(Globals
.hmdiclient
, &msg
))
4285 if (Globals
.hMainWnd
&& TranslateAccelerator(Globals
.hMainWnd
, Globals
.haccel
, &msg
))
4288 TranslateMessage(&msg
);
4289 DispatchMessage(&msg
);
4298 int APIENTRY
WinMain(HINSTANCE hinstance
,
4299 HINSTANCE previnstance
,
4303 #ifdef _NO_EXTENSIONS
4304 if (find_window_class(sWINEFILEFRAME
))
4308 winefile_main(hinstance
, 0, cmdshow
);