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
];
144 TCHAR filter_pattern
[MAX_PATH
];
148 SORT_ORDER sortOrder
;
152 extern void WineLicense(HWND hwnd
);
153 extern void WineWarranty(HWND hwnd
);
158 /* functions in unixcalls.c */
160 extern void call_getcwd(char* buffer
, size_t len
);
161 extern void* call_opendir(const char* path
);
162 extern int call_readdir(void* pdir
, char* name
, unsigned* pinode
);
163 extern void call_closedir(void* pdir
);
165 extern int call_stat(
166 const char* path
, int* pis_dir
,
167 unsigned long* psize_low
, unsigned long* psize_high
,
168 time_t* patime
, time_t* pmtime
,
169 unsigned long* plinks
172 /* call vswprintf() in msvcrt.dll */
173 int swprintf(wchar_t* buffer
, const wchar_t* fmt
, ...)
175 static int (__cdecl
*vswprintf
)(wchar_t*, const wchar_t*, va_list);
181 HMODULE hmod
= LoadLibraryA("msvcrt");
182 vswprintf
= (int(__cdecl
*)(wchar_t*,const wchar_t*,va_list)) GetProcAddress(hmod
, "vswprintf");
186 ret
= vswprintf(buffer
, fmt
, ap
);
195 // ugly hack to use alloca() while keeping Wine's developers happy
196 #define HeapAlloc(h,f,s) alloca(s)
197 #define HeapFree(h,f,p)
202 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
);
203 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
);
204 static void refresh_child(ChildWnd
* child
);
205 static void refresh_drives();
206 static void get_path(Entry
* dir
, PTSTR path
);
208 LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
209 LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
210 LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
214 WINEFILE_GLOBALS Globals
;
216 static int last_split
;
219 /* some common string constants */
220 const static TCHAR sEmpty
[] = {'\0'};
221 const static TCHAR sSpace
[] = {' ', '\0'};
222 const static TCHAR sNumFmt
[] = {'%','d','\0'};
223 const static TCHAR sQMarks
[] = {'?','?','?','\0'};
225 /* window class names */
226 const static TCHAR sWINEFILEFRAME
[] = {'W','F','S','_','F','r','a','m','e','\0'};
227 const static TCHAR sWINEFILETREE
[] = {'W','F','S','_','T','r','e','e','\0'};
230 /* #define LONGLONGARG _T("I64") */
231 const static TCHAR sLongHexFmt
[] = {'%','I','6','4','X','\0'};
232 const static TCHAR sLongNumFmt
[] = {'%','I','6','4','d','\0'};
234 /* #define LONGLONGARG _T("L") */
235 const static TCHAR sLongHexFmt
[] = {'%','L','X','\0'};
236 const static TCHAR sLongNumFmt
[] = {'%','L','d','\0'};
240 /* load resource string */
241 static LPTSTR
load_string(LPTSTR buffer
, UINT id
)
243 LoadString(Globals
.hInstance
, id
, buffer
, BUFFER_LEN
);
248 #define RS(b, i) load_string(b, i)
251 /* display error message for the specified WIN32 error code */
252 static void display_error(HWND hwnd
, DWORD error
)
254 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
257 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_FROM_SYSTEM
,
258 0, error
, MAKELANGID(LANG_NEUTRAL
,SUBLANG_DEFAULT
), (PTSTR
)&msg
, 0, NULL
))
259 MessageBox(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
261 MessageBox(hwnd
, RS(b1
,IDS_ERROR
), RS(b2
,IDS_WINEFILE
), MB_OK
);
267 /* display network error message using WNetGetLastError() */
268 static void display_network_error(HWND hwnd
)
270 TCHAR msg
[BUFFER_LEN
], provider
[BUFFER_LEN
], b2
[BUFFER_LEN
];
273 if (WNetGetLastError(&error
, msg
, BUFFER_LEN
, provider
, BUFFER_LEN
) == NO_ERROR
)
274 MessageBox(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
278 /* allocate and initialise a directory entry */
279 static Entry
* alloc_entry()
281 Entry
* entry
= (Entry
*) malloc(sizeof(Entry
));
283 #ifdef _SHELL_FOLDERS
285 entry
->folder
= NULL
;
292 /* free a directory entry */
293 static void free_entry(Entry
* entry
)
295 #ifdef _SHELL_FOLDERS
296 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
297 DestroyIcon(entry
->hicon
);
299 if (entry
->folder
&& entry
->folder
!=Globals
.iDesktop
)
300 (*entry
->folder
->lpVtbl
->Release
)(entry
->folder
);
303 (*Globals
.iMalloc
->lpVtbl
->Free
)(Globals
.iMalloc
, entry
->pidl
);
309 /* recursively free all child entries */
310 static void free_entries(Entry
* dir
)
312 Entry
*entry
, *next
=dir
->down
;
328 static void read_directory_win(Entry
* dir
, LPCTSTR path
)
330 Entry
* first_entry
= NULL
;
334 int level
= dir
->level
+ 1;
335 WIN32_FIND_DATA w32fd
;
337 #ifndef _NO_EXTENSIONS
341 TCHAR buffer
[MAX_PATH
], *p
;
342 for(p
=buffer
; *path
; )
349 hFind
= FindFirstFile(buffer
, &w32fd
);
351 if (hFind
!= INVALID_HANDLE_VALUE
) {
353 #ifdef _NO_EXTENSIONS
354 /* hide directory entry "." */
355 if (w32fd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
356 LPCTSTR name
= w32fd
.cFileName
;
358 if (name
[0]=='.' && name
[1]=='\0')
362 entry
= alloc_entry();
370 memcpy(&entry
->data
, &w32fd
, sizeof(WIN32_FIND_DATA
));
373 entry
->expanded
= FALSE
;
374 entry
->scanned
= FALSE
;
375 entry
->level
= level
;
377 #ifndef _NO_EXTENSIONS
378 entry
->etype
= ET_WINDOWS
;
379 entry
->bhfi_valid
= FALSE
;
381 lstrcpy(p
, entry
->data
.cFileName
);
383 hFile
= CreateFile(buffer
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
384 0, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0);
386 if (hFile
!= INVALID_HANDLE_VALUE
) {
387 if (GetFileInformationByHandle(hFile
, &entry
->bhfi
))
388 entry
->bhfi_valid
= TRUE
;
395 } while(FindNextFile(hFind
, &w32fd
));
403 dir
->down
= first_entry
;
408 static Entry
* find_entry_win(Entry
* dir
, LPCTSTR name
)
412 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
414 LPCTSTR q
= entry
->data
.cFileName
;
417 if (!*p
|| *p
==TEXT('\\') || *p
==TEXT('/'))
419 } while(tolower(*p
++) == tolower(*q
++));
422 q
= entry
->data
.cAlternateFileName
;
425 if (!*p
|| *p
==TEXT('\\') || *p
==TEXT('/'))
427 } while(tolower(*p
++) == tolower(*q
++));
434 static Entry
* read_tree_win(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
436 TCHAR buffer
[MAX_PATH
];
437 Entry
* entry
= &root
->entry
;
441 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
443 #ifndef _NO_EXTENSIONS
444 entry
->etype
= ET_WINDOWS
;
448 while(*s
&& *s
!=TEXT('\\') && *s
!=TEXT('/'))
451 while(*s
==TEXT('\\') || *s
==TEXT('/'))
457 read_directory(entry
, buffer
, sortOrder
, hwnd
);
460 entry
->expanded
= TRUE
;
465 entry
= find_entry_win(entry
, s
);
468 SetCursor(old_cursor
);
474 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
476 static BOOL
time_to_filetime(const time_t* t
, FILETIME
* ftime
)
478 struct tm
* tm
= gmtime(t
);
484 stime
.wYear
= tm
->tm_year
+1900;
485 stime
.wMonth
= tm
->tm_mon
+1;
486 /* stime.wDayOfWeek */
487 stime
.wDay
= tm
->tm_mday
;
488 stime
.wHour
= tm
->tm_hour
;
489 stime
.wMinute
= tm
->tm_min
;
490 stime
.wSecond
= tm
->tm_sec
;
492 return SystemTimeToFileTime(&stime
, ftime
);
495 static void read_directory_unix(Entry
* dir
, LPCTSTR path
)
497 Entry
* first_entry
= NULL
;
503 char cpath
[MAX_PATH
];
505 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, cpath
, MAX_PATH
, NULL
, NULL
);
507 const char* cpath
= path
;
510 pdir
= call_opendir(cpath
);
512 int level
= dir
->level
+ 1;
515 char buffer
[MAX_PATH
];
522 for(p
=buffer
,s
=cpath
; *s
; )
525 if (p
==buffer
|| p
[-1]!='/')
528 while(call_readdir(pdir
, p
, &inode
)) {
529 entry
= alloc_entry();
537 entry
->etype
= ET_UNIX
;
540 MultiByteToWideChar(CP_UNIXCP
, 0, p
, -1, entry
->data
.cFileName
, MAX_PATH
);
542 lstrcpy(entry
->data
.cFileName
, p
);
545 entry
->data
.dwFileAttributes
= p
[0]=='.'? FILE_ATTRIBUTE_HIDDEN
: 0;
547 if (!call_stat(buffer
, &is_dir
,
548 &entry
->data
.nFileSizeLow
, &entry
->data
.nFileSizeHigh
,
549 &atime
, &mtime
, &entry
->bhfi
.nNumberOfLinks
))
552 entry
->data
.dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
554 memset(&entry
->data
.ftCreationTime
, 0, sizeof(FILETIME
));
555 time_to_filetime(&atime
, &entry
->data
.ftLastAccessTime
);
556 time_to_filetime(&mtime
, &entry
->data
.ftLastWriteTime
);
558 entry
->bhfi
.nFileIndexLow
= inode
;
559 entry
->bhfi
.nFileIndexHigh
= 0;
561 entry
->bhfi_valid
= TRUE
;
563 entry
->data
.nFileSizeLow
= 0;
564 entry
->data
.nFileSizeHigh
= 0;
565 entry
->bhfi_valid
= FALSE
;
570 entry
->expanded
= FALSE
;
571 entry
->scanned
= FALSE
;
572 entry
->level
= level
;
583 dir
->down
= first_entry
;
587 static Entry
* find_entry_unix(Entry
* dir
, LPCTSTR name
)
591 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
593 LPCTSTR q
= entry
->data
.cFileName
;
596 if (!*p
|| *p
==TEXT('/'))
598 } while(*p
++ == *q
++);
604 static Entry
* read_tree_unix(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
606 TCHAR buffer
[MAX_PATH
];
607 Entry
* entry
= &root
->entry
;
611 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
613 entry
->etype
= ET_UNIX
;
616 while(*s
&& *s
!=TEXT('/'))
619 while(*s
== TEXT('/'))
625 read_directory(entry
, buffer
, sortOrder
, hwnd
);
628 entry
->expanded
= TRUE
;
633 entry
= find_entry_unix(entry
, s
);
636 SetCursor(old_cursor
);
641 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
644 #ifdef _SHELL_FOLDERS
647 #define tcscpyn strcpyn
648 #define get_strret get_strretW
649 #define path_from_pidl path_from_pidlW
651 #define tcscpyn wcscpyn
652 #define get_strret get_strretA
653 #define path_from_pidl path_from_pidlA
657 static LPSTR
strcpyn(LPSTR dest
, LPCSTR source
, size_t count
)
662 for(s
=source
; count
&&(*d
++=*s
++); )
668 static LPWSTR
wcscpyn(LPWSTR dest
, LPCWSTR source
, size_t count
)
673 for(s
=source
; count
&&(*d
++=*s
++); )
680 static void get_strretA(STRRET
* str
, const SHITEMID
* shiid
, LPSTR buffer
, int len
)
684 WideCharToMultiByte(CP_ACP
, 0, str
->UNION_MEMBER(pOleStr
), -1, buffer
, len
, NULL
, NULL
);
688 strcpyn(buffer
, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), len
);
692 strcpyn(buffer
, str
->UNION_MEMBER(cStr
), len
);
696 static void get_strretW(STRRET
* str
, const SHITEMID
* shiid
, LPWSTR buffer
, int len
)
700 wcscpyn(buffer
, str
->UNION_MEMBER(pOleStr
), len
);
704 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), -1, buffer
, len
);
708 MultiByteToWideChar(CP_ACP
, 0, str
->UNION_MEMBER(cStr
), -1, buffer
, len
);
713 static void free_strret(STRRET
* str
)
715 if (str
->uType
== STRRET_WSTR
)
716 (*Globals
.iMalloc
->lpVtbl
->Free
)(Globals
.iMalloc
, str
->UNION_MEMBER(pOleStr
));
720 HRESULT
name_from_pidl(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPTSTR buffer
, int len
, SHGDNF flags
)
724 HRESULT hr
= (*folder
->lpVtbl
->GetDisplayNameOf
)(folder
, pidl
, flags
, &str
);
727 get_strret(&str
, &pidl
->mkid
, buffer
, len
);
736 HRESULT
path_from_pidlA(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPSTR buffer
, int len
)
740 /* SHGDN_FORPARSING: get full path of id list */
741 HRESULT hr
= (*folder
->lpVtbl
->GetDisplayNameOf
)(folder
, pidl
, SHGDN_FORPARSING
, &str
);
744 get_strretA(&str
, &pidl
->mkid
, buffer
, len
);
752 HRESULT
path_from_pidlW(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPWSTR buffer
, int len
)
756 /* SHGDN_FORPARSING: get full path of id list */
757 HRESULT hr
= (*folder
->lpVtbl
->GetDisplayNameOf
)(folder
, pidl
, SHGDN_FORPARSING
, &str
);
760 get_strretW(&str
, &pidl
->mkid
, buffer
, len
);
769 /* create an item id list from a file system path */
771 static LPITEMIDLIST
get_path_pidl(LPTSTR path
, HWND hwnd
)
778 LPWSTR buffer
= path
;
780 WCHAR buffer
[MAX_PATH
];
781 MultiByteToWideChar(CP_ACP
, 0, path
, -1, buffer
, MAX_PATH
);
784 hr
= (*Globals
.iDesktop
->lpVtbl
->ParseDisplayName
)(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
792 /* convert an item id list from relative to absolute (=relative to the desktop) format */
794 static LPITEMIDLIST
get_to_absolute_pidl(Entry
* entry
, HWND hwnd
)
796 if (entry
->up
&& entry
->up
->etype
==ET_SHELL
) {
797 IShellFolder
* folder
= entry
->up
->folder
;
798 WCHAR buffer
[MAX_PATH
];
800 HRESULT hr
= path_from_pidlW(folder
, entry
->pidl
, buffer
, MAX_PATH
);
806 hr
= (*Globals
.iDesktop
->lpVtbl
->ParseDisplayName
)(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
811 } else if (entry
->etype
== ET_WINDOWS
) {
812 TCHAR path
[MAX_PATH
];
814 get_path(entry
, path
);
816 return get_path_pidl(path
, hwnd
);
817 } else if (entry
->pidl
)
818 return ILClone(entry
->pidl
);
824 HICON
extract_icon(IShellFolder
* folder
, LPCITEMIDLIST pidl
)
826 IExtractIcon
* pExtract
;
828 if (SUCCEEDED((*folder
->lpVtbl
->GetUIObjectOf
)(folder
, 0, 1, (LPCITEMIDLIST
*)&pidl
, &IID_IExtractIcon
, 0, (LPVOID
*)&pExtract
))) {
829 TCHAR path
[_MAX_PATH
];
834 if (SUCCEEDED((*pExtract
->lpVtbl
->GetIconLocation
)(pExtract
, GIL_FORSHELL
, path
, _MAX_PATH
, &idx
, &flags
))) {
835 if (!(flags
& GIL_NOTFILENAME
)) {
837 idx
= 0; /* special case for some control panel applications */
839 if ((int)ExtractIconEx(path
, idx
, 0, &hicon
, 1) > 0)
840 flags
&= ~GIL_DONTCACHE
;
842 HICON hIconLarge
= 0;
844 HRESULT hr
= (*pExtract
->lpVtbl
->Extract
)(pExtract
, path
, idx
, &hIconLarge
, &hicon
, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON
)));
847 DestroyIcon(hIconLarge
);
858 static Entry
* find_entry_shell(Entry
* dir
, LPCITEMIDLIST pidl
)
862 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
863 if (entry
->pidl
->mkid
.cb
== pidl
->mkid
.cb
&&
864 !memcmp(entry
->pidl
, pidl
, entry
->pidl
->mkid
.cb
))
871 static Entry
* read_tree_shell(Root
* root
, LPITEMIDLIST pidl
, SORT_ORDER sortOrder
, HWND hwnd
)
873 Entry
* entry
= &root
->entry
;
875 LPITEMIDLIST next_pidl
= pidl
;
876 IShellFolder
* folder
;
877 IShellFolder
* child
= NULL
;
880 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
882 #ifndef _NO_EXTENSIONS
883 entry
->etype
= ET_SHELL
;
886 folder
= Globals
.iDesktop
;
889 entry
->pidl
= next_pidl
;
890 entry
->folder
= folder
;
895 /* copy first element of item idlist */
896 next_pidl
= (*Globals
.iMalloc
->lpVtbl
->Alloc
)(Globals
.iMalloc
, pidl
->mkid
.cb
+sizeof(USHORT
));
897 memcpy(next_pidl
, pidl
, pidl
->mkid
.cb
);
898 ((LPITEMIDLIST
)((LPBYTE
)next_pidl
+pidl
->mkid
.cb
))->mkid
.cb
= 0;
900 hr
= (*folder
->lpVtbl
->BindToObject
)(folder
, next_pidl
, 0, &IID_IShellFolder
, (void**)&child
);
904 read_directory(entry
, NULL
, sortOrder
, hwnd
);
907 entry
->expanded
= TRUE
;
909 next
= find_entry_shell(entry
, next_pidl
);
916 /* go to next element */
917 pidl
= (LPITEMIDLIST
) ((LPBYTE
)pidl
+pidl
->mkid
.cb
);
920 SetCursor(old_cursor
);
926 static void fill_w32fdata_shell(IShellFolder
* folder
, LPCITEMIDLIST pidl
, SFGAOF attribs
, WIN32_FIND_DATA
* w32fdata
)
928 if (!(attribs
& SFGAO_FILESYSTEM
) ||
929 FAILED(SHGetDataFromIDList(folder
, pidl
, SHGDFIL_FINDDATA
, w32fdata
, sizeof(WIN32_FIND_DATA
)))) {
930 WIN32_FILE_ATTRIBUTE_DATA fad
;
931 IDataObject
* pDataObj
;
933 STGMEDIUM medium
= {0, {0}, 0};
934 FORMATETC fmt
= {Globals
.cfStrFName
, 0, DVASPECT_CONTENT
, -1, TYMED_HGLOBAL
};
936 HRESULT hr
= (*folder
->lpVtbl
->GetUIObjectOf
)(folder
, 0, 1, &pidl
, &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
939 hr
= (*pDataObj
->lpVtbl
->GetData
)(pDataObj
, &fmt
, &medium
);
941 (*pDataObj
->lpVtbl
->Release
)(pDataObj
);
944 LPCTSTR path
= (LPCTSTR
)GlobalLock(medium
.UNION_MEMBER(hGlobal
));
945 UINT sem_org
= SetErrorMode(SEM_FAILCRITICALERRORS
);
947 if (GetFileAttributesEx(path
, GetFileExInfoStandard
, &fad
)) {
948 w32fdata
->dwFileAttributes
= fad
.dwFileAttributes
;
949 w32fdata
->ftCreationTime
= fad
.ftCreationTime
;
950 w32fdata
->ftLastAccessTime
= fad
.ftLastAccessTime
;
951 w32fdata
->ftLastWriteTime
= fad
.ftLastWriteTime
;
953 if (!(fad
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)) {
954 w32fdata
->nFileSizeLow
= fad
.nFileSizeLow
;
955 w32fdata
->nFileSizeHigh
= fad
.nFileSizeHigh
;
959 SetErrorMode(sem_org
);
961 GlobalUnlock(medium
.UNION_MEMBER(hGlobal
));
962 GlobalFree(medium
.UNION_MEMBER(hGlobal
));
967 if (attribs
& (SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
))
968 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
970 if (attribs
& SFGAO_READONLY
)
971 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_READONLY
;
973 if (attribs
& SFGAO_COMPRESSED
)
974 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_COMPRESSED
;
978 static void read_directory_shell(Entry
* dir
, HWND hwnd
)
980 IShellFolder
* folder
= dir
->folder
;
981 int level
= dir
->level
+ 1;
987 Entry
* first_entry
= NULL
;
994 hr
= (*folder
->lpVtbl
->EnumObjects
)(folder
, hwnd
, SHCONTF_FOLDERS
|SHCONTF_NONFOLDERS
|SHCONTF_INCLUDEHIDDEN
|SHCONTF_SHAREABLE
|SHCONTF_STORAGE
, &idlist
);
998 #define FETCH_ITEM_COUNT 32
999 LPITEMIDLIST pidls
[FETCH_ITEM_COUNT
];
1004 memset(pidls
, 0, sizeof(pidls
));
1006 hr
= (*idlist
->lpVtbl
->Next
)(idlist
, FETCH_ITEM_COUNT
, pidls
, &cnt
);
1013 for(n
=0; n
<cnt
; ++n
) {
1014 entry
= alloc_entry();
1017 first_entry
= entry
;
1022 memset(&entry
->data
, 0, sizeof(WIN32_FIND_DATA
));
1023 entry
->bhfi_valid
= FALSE
;
1025 attribs
= ~SFGAO_FILESYSTEM
; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
1027 hr
= (*folder
->lpVtbl
->GetAttributesOf
)(folder
, 1, (LPCITEMIDLIST
*)&pidls
[n
], &attribs
);
1029 if (SUCCEEDED(hr
)) {
1030 if (attribs
!= (SFGAOF
)~SFGAO_FILESYSTEM
) {
1031 fill_w32fdata_shell(folder
, pidls
[n
], attribs
, &entry
->data
);
1033 entry
->bhfi_valid
= TRUE
;
1039 entry
->pidl
= pidls
[n
];
1041 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1042 hr
= (*folder
->lpVtbl
->BindToObject
)(folder
, pidls
[n
], 0, &IID_IShellFolder
, (void**)&child
);
1045 entry
->folder
= child
;
1047 entry
->folder
= NULL
;
1050 entry
->folder
= NULL
;
1052 if (!entry
->data
.cFileName
[0])
1053 /*hr = */name_from_pidl(folder
, pidls
[n
], entry
->data
.cFileName
, MAX_PATH
, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1055 /* get display icons for files and virtual objects */
1056 if (!(entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ||
1057 !(attribs
& SFGAO_FILESYSTEM
)) {
1058 entry
->hicon
= extract_icon(folder
, pidls
[n
]);
1061 entry
->hicon
= (HICON
)-1; /* don't try again later */
1066 entry
->expanded
= FALSE
;
1067 entry
->scanned
= FALSE
;
1068 entry
->level
= level
;
1070 #ifndef _NO_EXTENSIONS
1071 entry
->etype
= ET_SHELL
;
1072 entry
->bhfi_valid
= FALSE
;
1079 (*idlist
->lpVtbl
->Release
)(idlist
);
1085 dir
->down
= first_entry
;
1086 dir
->scanned
= TRUE
;
1089 #endif /* _SHELL_FOLDERS */
1092 /* sort order for different directory/file types */
1101 /* distinguish between ".", ".." and any other directory names */
1102 static int TypeOrderFromDirname(LPCTSTR name
)
1104 if (name
[0] == '.') {
1105 if (name
[1] == '\0')
1106 return TO_DOT
; /* "." */
1108 if (name
[1]=='.' && name
[2]=='\0')
1109 return TO_DOTDOT
; /* ".." */
1112 return TO_OTHER_DIR
; /* anything else */
1115 /* directories first... */
1116 static int compareType(const WIN32_FIND_DATA
* fd1
, const WIN32_FIND_DATA
* fd2
)
1118 int order1
= fd1
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1119 int order2
= fd2
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1121 /* Handle "." and ".." as special case and move them at the very first beginning. */
1122 if (order1
==TO_DIR
&& order2
==TO_DIR
) {
1123 order1
= TypeOrderFromDirname(fd1
->cFileName
);
1124 order2
= TypeOrderFromDirname(fd2
->cFileName
);
1127 return order2
==order1
? 0: order1
<order2
? -1: 1;
1131 static int compareName(const void* arg1
, const void* arg2
)
1133 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1134 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1136 int cmp
= compareType(fd1
, fd2
);
1140 return lstrcmpi(fd1
->cFileName
, fd2
->cFileName
);
1143 static int compareExt(const void* arg1
, const void* arg2
)
1145 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1146 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1147 const TCHAR
*name1
, *name2
, *ext1
, *ext2
;
1149 int cmp
= compareType(fd1
, fd2
);
1153 name1
= fd1
->cFileName
;
1154 name2
= fd2
->cFileName
;
1156 ext1
= _tcsrchr(name1
, TEXT('.'));
1157 ext2
= _tcsrchr(name2
, TEXT('.'));
1169 cmp
= lstrcmpi(ext1
, ext2
);
1173 return lstrcmpi(name1
, name2
);
1176 static int compareSize(const void* arg1
, const void* arg2
)
1178 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1179 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1181 int cmp
= compareType(fd1
, fd2
);
1185 cmp
= fd2
->nFileSizeHigh
- fd1
->nFileSizeHigh
;
1192 cmp
= fd2
->nFileSizeLow
- fd1
->nFileSizeLow
;
1194 return cmp
<0? -1: cmp
>0? 1: 0;
1197 static int compareDate(const void* arg1
, const void* arg2
)
1199 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1200 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1202 int cmp
= compareType(fd1
, fd2
);
1206 return CompareFileTime(&fd2
->ftLastWriteTime
, &fd1
->ftLastWriteTime
);
1210 static int (*sortFunctions
[])(const void* arg1
, const void* arg2
) = {
1211 compareName
, /* SORT_NAME */
1212 compareExt
, /* SORT_EXT */
1213 compareSize
, /* SORT_SIZE */
1214 compareDate
/* SORT_DATE */
1218 static void SortDirectory(Entry
* dir
, SORT_ORDER sortOrder
)
1220 Entry
* entry
= dir
->down
;
1225 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1229 array
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(Entry
*));
1232 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1235 /* call qsort with the appropriate compare function */
1236 qsort(array
, len
, sizeof(array
[0]), sortFunctions
[sortOrder
]);
1238 dir
->down
= array
[0];
1240 for(p
=array
; --len
; p
++)
1245 HeapFree(GetProcessHeap(), 0, array
);
1250 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
1252 TCHAR buffer
[MAX_PATH
];
1257 #ifdef _SHELL_FOLDERS
1258 if (dir
->etype
== ET_SHELL
)
1260 read_directory_shell(dir
, hwnd
);
1262 if (Globals
.prescan_node
) {
1271 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1272 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1273 read_directory_shell(entry
, hwnd
);
1274 SortDirectory(entry
, sortOrder
);
1280 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1281 if (dir
->etype
== ET_UNIX
)
1283 read_directory_unix(dir
, path
);
1285 if (Globals
.prescan_node
) {
1294 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1295 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1296 lstrcpy(d
, entry
->data
.cFileName
);
1297 read_directory_unix(entry
, buffer
);
1298 SortDirectory(entry
, sortOrder
);
1305 read_directory_win(dir
, path
);
1307 if (Globals
.prescan_node
) {
1316 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1317 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1318 lstrcpy(d
, entry
->data
.cFileName
);
1319 read_directory_win(entry
, buffer
);
1320 SortDirectory(entry
, sortOrder
);
1325 SortDirectory(dir
, sortOrder
);
1329 static Entry
* read_tree(Root
* root
, LPCTSTR path
, LPITEMIDLIST pidl
, LPTSTR drv
, SORT_ORDER sortOrder
, HWND hwnd
)
1331 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1332 const static TCHAR sSlash
[] = {'/', '\0'};
1334 const static TCHAR sBackslash
[] = {'\\', '\0'};
1336 #ifdef _SHELL_FOLDERS
1339 /* read shell namespace tree */
1340 root
->drive_type
= DRIVE_UNKNOWN
;
1343 load_string(root
->volname
, IDS_DESKTOP
);
1345 load_string(root
->fs
, IDS_SHELL
);
1347 return read_tree_shell(root
, pidl
, sortOrder
, hwnd
);
1351 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1354 /* read unix file system tree */
1355 root
->drive_type
= GetDriveType(path
);
1357 lstrcat(drv
, sSlash
);
1358 load_string(root
->volname
, IDS_ROOT_FS
);
1360 load_string(root
->fs
, IDS_UNIXFS
);
1362 lstrcpy(root
->path
, sSlash
);
1364 return read_tree_unix(root
, path
, sortOrder
, hwnd
);
1368 /* read WIN32 file system tree */
1369 root
->drive_type
= GetDriveType(path
);
1371 lstrcat(drv
, sBackslash
);
1372 GetVolumeInformation(drv
, root
->volname
, _MAX_FNAME
, 0, 0, &root
->fs_flags
, root
->fs
, _MAX_DIR
);
1374 lstrcpy(root
->path
, drv
);
1376 return read_tree_win(root
, path
, sortOrder
, hwnd
);
1380 /* flags to filter different file types */
1382 TF_DIRECTORIES
= 0x01,
1384 TF_DOCUMENTS
= 0x04,
1391 static ChildWnd
* alloc_child_window(LPCTSTR path
, LPITEMIDLIST pidl
, HWND hwnd
)
1393 TCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
1394 TCHAR b1
[BUFFER_LEN
];
1395 const static TCHAR sAsterics
[] = {'*', '\0'};
1397 ChildWnd
* child
= (ChildWnd
*) malloc(sizeof(ChildWnd
));
1398 Root
* root
= &child
->root
;
1401 memset(child
, 0, sizeof(ChildWnd
));
1403 child
->left
.treePane
= TRUE
;
1404 child
->left
.visible_cols
= 0;
1406 child
->right
.treePane
= FALSE
;
1407 #ifndef _NO_EXTENSIONS
1408 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_INDEX
|COL_LINKS
;
1410 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
;
1413 child
->pos
.length
= sizeof(WINDOWPLACEMENT
);
1414 child
->pos
.flags
= 0;
1415 child
->pos
.showCmd
= SW_SHOWNORMAL
;
1416 child
->pos
.rcNormalPosition
.left
= CW_USEDEFAULT
;
1417 child
->pos
.rcNormalPosition
.top
= CW_USEDEFAULT
;
1418 child
->pos
.rcNormalPosition
.right
= CW_USEDEFAULT
;
1419 child
->pos
.rcNormalPosition
.bottom
= CW_USEDEFAULT
;
1421 child
->focus_pane
= 0;
1422 child
->split_pos
= DEFAULT_SPLIT_POS
;
1423 child
->sortOrder
= SORT_NAME
;
1424 child
->header_wdths_ok
= FALSE
;
1428 lstrcpy(child
->path
, path
);
1430 _tsplitpath(path
, drv
, dir
, name
, ext
);
1433 _tcscpy(child
->filter_pattern
, sAsterics
);
1434 child
->filter_flags
= TF_ALL
;
1436 root
->entry
.level
= 0;
1438 entry
= read_tree(root
, path
, pidl
, drv
, child
->sortOrder
, hwnd
);
1440 #ifdef _SHELL_FOLDERS
1441 if (root
->entry
.etype
== ET_SHELL
)
1442 load_string(root
->entry
.data
.cFileName
, IDS_DESKTOP
);
1445 wsprintf(root
->entry
.data
.cFileName
, RS(b1
,IDS_TITLEFMT
), drv
, root
->fs
);
1447 root
->entry
.data
.dwFileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1449 child
->left
.root
= &root
->entry
;
1450 child
->right
.root
= NULL
;
1452 set_curdir(child
, entry
, 0, hwnd
);
1458 /* free all memory associated with a child window */
1459 static void free_child_window(ChildWnd
* child
)
1461 free_entries(&child
->root
.entry
);
1466 /* get full path of specified directory entry */
1467 static void get_path(Entry
* dir
, PTSTR path
)
1473 #ifdef _SHELL_FOLDERS
1474 if (dir
->etype
== ET_SHELL
)
1479 path
[0] = TEXT('\0');
1484 hr
= (*dir
->folder
->lpVtbl
->GetAttributesOf
)(dir
->folder
, 1, (LPCITEMIDLIST
*)&dir
->pidl
, &attribs
);
1486 if (SUCCEEDED(hr
) && (attribs
&SFGAO_FILESYSTEM
)) {
1487 IShellFolder
* parent
= dir
->up
? dir
->up
->folder
: Globals
.iDesktop
;
1489 hr
= path_from_pidl(parent
, dir
->pidl
, path
, MAX_PATH
);
1495 for(entry
=dir
; entry
; level
++) {
1501 name
= entry
->data
.cFileName
;
1504 for(l
=0; *s
&& *s
!=TEXT('/') && *s
!=TEXT('\\'); s
++)
1510 memmove(path
+l
+1, path
, len
*sizeof(TCHAR
));
1511 memcpy(path
+1, name
, l
*sizeof(TCHAR
));
1514 #ifndef _NO_EXTENSIONS
1515 if (entry
->etype
== ET_UNIX
)
1516 path
[0] = TEXT('/');
1519 path
[0] = TEXT('\\');
1524 memmove(path
+l
, path
, len
*sizeof(TCHAR
));
1525 memcpy(path
, name
, l
*sizeof(TCHAR
));
1532 #ifndef _NO_EXTENSIONS
1533 if (entry
->etype
== ET_UNIX
)
1534 path
[len
++] = TEXT('/');
1537 path
[len
++] = TEXT('\\');
1540 path
[len
] = TEXT('\0');
1545 static void resize_frame_rect(HWND hwnd
, PRECT prect
)
1550 if (IsWindowVisible(Globals
.htoolbar
)) {
1551 SendMessage(Globals
.htoolbar
, WM_SIZE
, 0, 0);
1552 GetClientRect(Globals
.htoolbar
, &rt
);
1553 prect
->top
= rt
.bottom
+3;
1554 prect
->bottom
-= rt
.bottom
+3;
1557 if (IsWindowVisible(Globals
.hdrivebar
)) {
1558 SendMessage(Globals
.hdrivebar
, WM_SIZE
, 0, 0);
1559 GetClientRect(Globals
.hdrivebar
, &rt
);
1560 new_top
= --prect
->top
+ rt
.bottom
+3;
1561 MoveWindow(Globals
.hdrivebar
, 0, prect
->top
, rt
.right
, new_top
, TRUE
);
1562 prect
->top
= new_top
;
1563 prect
->bottom
-= rt
.bottom
+2;
1566 if (IsWindowVisible(Globals
.hstatusbar
)) {
1567 int parts
[] = {300, 500};
1569 SendMessage(Globals
.hstatusbar
, WM_SIZE
, 0, 0);
1570 SendMessage(Globals
.hstatusbar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
1571 GetClientRect(Globals
.hstatusbar
, &rt
);
1572 prect
->bottom
-= rt
.bottom
;
1575 MoveWindow(Globals
.hmdiclient
, prect
->left
-1,prect
->top
-1,prect
->right
+2,prect
->bottom
+1, TRUE
);
1578 static void resize_frame(HWND hwnd
, int cx
, int cy
)
1587 resize_frame_rect(hwnd
, &rect
);
1590 static void resize_frame_client(HWND hwnd
)
1594 GetClientRect(hwnd
, &rect
);
1596 resize_frame_rect(hwnd
, &rect
);
1600 static HHOOK hcbthook
;
1601 static ChildWnd
* newchild
= NULL
;
1603 LRESULT CALLBACK
CBTProc(int code
, WPARAM wparam
, LPARAM lparam
)
1605 if (code
==HCBT_CREATEWND
&& newchild
) {
1606 ChildWnd
* child
= newchild
;
1609 child
->hwnd
= (HWND
) wparam
;
1610 SetWindowLong(child
->hwnd
, GWL_USERDATA
, (LPARAM
)child
);
1613 return CallNextHookEx(hcbthook
, code
, wparam
, lparam
);
1616 static HWND
create_child_window(ChildWnd
* child
)
1618 MDICREATESTRUCT mcs
;
1621 mcs
.szClass
= sWINEFILETREE
;
1622 mcs
.szTitle
= (LPTSTR
)child
->path
;
1623 mcs
.hOwner
= Globals
.hInstance
;
1624 mcs
.x
= child
->pos
.rcNormalPosition
.left
;
1625 mcs
.y
= child
->pos
.rcNormalPosition
.top
;
1626 mcs
.cx
= child
->pos
.rcNormalPosition
.right
-child
->pos
.rcNormalPosition
.left
;
1627 mcs
.cy
= child
->pos
.rcNormalPosition
.bottom
-child
->pos
.rcNormalPosition
.top
;
1631 hcbthook
= SetWindowsHookEx(WH_CBT
, CBTProc
, 0, GetCurrentThreadId());
1634 child
->hwnd
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDICREATE
, 0, (LPARAM
)&mcs
);
1636 UnhookWindowsHookEx(hcbthook
);
1640 UnhookWindowsHookEx(hcbthook
);
1642 ListBox_SetItemHeight(child
->left
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1643 ListBox_SetItemHeight(child
->right
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1645 idx
= ListBox_FindItemData(child
->left
.hwnd
, 0, child
->left
.cur
);
1646 ListBox_SetCurSel(child
->left
.hwnd
, idx
);
1652 struct ExecuteDialog
{
1653 TCHAR cmd
[MAX_PATH
];
1657 static INT_PTR CALLBACK
ExecuteDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1659 static struct ExecuteDialog
* dlg
;
1663 dlg
= (struct ExecuteDialog
*) lparam
;
1667 int id
= (int)wparam
;
1670 GetWindowText(GetDlgItem(hwnd
, 201), dlg
->cmd
, MAX_PATH
);
1671 dlg
->cmdshow
= Button_GetState(GetDlgItem(hwnd
,214))&BST_CHECKED
?
1672 SW_SHOWMINIMIZED
: SW_SHOWNORMAL
;
1673 EndDialog(hwnd
, id
);
1674 } else if (id
== IDCANCEL
)
1675 EndDialog(hwnd
, id
);
1684 static INT_PTR CALLBACK
DestinationDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1686 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1690 SetWindowLong(hwnd
, GWL_USERDATA
, lparam
);
1691 SetWindowText(GetDlgItem(hwnd
, 201), (LPCTSTR
)lparam
);
1695 int id
= (int)wparam
;
1699 LPTSTR dest
= (LPTSTR
) GetWindowLong(hwnd
, GWL_USERDATA
);
1700 GetWindowText(GetDlgItem(hwnd
, 201), dest
, MAX_PATH
);
1701 EndDialog(hwnd
, id
);
1705 EndDialog(hwnd
, id
);
1709 MessageBox(hwnd
, RS(b1
,IDS_NO_IMPL
), RS(b2
,IDS_WINEFILE
), MB_OK
);
1721 struct FilterDialog
{
1722 TCHAR pattern
[MAX_PATH
];
1726 static INT_PTR CALLBACK
FilterDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1728 static struct FilterDialog
* dlg
;
1732 dlg
= (struct FilterDialog
*) lparam
;
1733 SetWindowText(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
);
1734 Button_SetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_DIRECTORIES
), (dlg
->flags
&TF_DIRECTORIES
? BST_CHECKED
: BST_UNCHECKED
));
1735 Button_SetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_PROGRAMS
), dlg
->flags
&TF_PROGRAMS
? BST_CHECKED
: BST_UNCHECKED
);
1736 Button_SetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_DOCUMENTS
), dlg
->flags
&TF_DOCUMENTS
? BST_CHECKED
: BST_UNCHECKED
);
1737 Button_SetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_OTHERS
), dlg
->flags
&TF_OTHERS
? BST_CHECKED
: BST_UNCHECKED
);
1738 Button_SetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_HIDDEN
), dlg
->flags
&TF_HIDDEN
? BST_CHECKED
: BST_UNCHECKED
);
1742 int id
= (int)wparam
;
1747 GetWindowText(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
, MAX_PATH
);
1749 flags
|= Button_GetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_DIRECTORIES
))&BST_CHECKED
? TF_DIRECTORIES
: 0;
1750 flags
|= Button_GetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_PROGRAMS
))&BST_CHECKED
? TF_PROGRAMS
: 0;
1751 flags
|= Button_GetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_DOCUMENTS
))&BST_CHECKED
? TF_DOCUMENTS
: 0;
1752 flags
|= Button_GetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_OTHERS
))&BST_CHECKED
? TF_OTHERS
: 0;
1753 flags
|= Button_GetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_HIDDEN
))&BST_CHECKED
? TF_HIDDEN
: 0;
1757 EndDialog(hwnd
, id
);
1758 } else if (id
== IDCANCEL
)
1759 EndDialog(hwnd
, id
);
1768 #ifndef _NO_EXTENSIONS
1770 static struct FullScreenParameters
{
1780 void frame_get_clientspace(HWND hwnd
, PRECT prect
)
1784 if (!IsIconic(hwnd
))
1785 GetClientRect(hwnd
, prect
);
1789 GetWindowPlacement(hwnd
, &wp
);
1791 prect
->left
= prect
->top
= 0;
1792 prect
->right
= wp
.rcNormalPosition
.right
-wp
.rcNormalPosition
.left
-
1793 2*(GetSystemMetrics(SM_CXSIZEFRAME
)+GetSystemMetrics(SM_CXEDGE
));
1794 prect
->bottom
= wp
.rcNormalPosition
.bottom
-wp
.rcNormalPosition
.top
-
1795 2*(GetSystemMetrics(SM_CYSIZEFRAME
)+GetSystemMetrics(SM_CYEDGE
))-
1796 GetSystemMetrics(SM_CYCAPTION
)-GetSystemMetrics(SM_CYMENUSIZE
);
1799 if (IsWindowVisible(Globals
.htoolbar
)) {
1800 GetClientRect(Globals
.htoolbar
, &rt
);
1801 prect
->top
+= rt
.bottom
+2;
1804 if (IsWindowVisible(Globals
.hdrivebar
)) {
1805 GetClientRect(Globals
.hdrivebar
, &rt
);
1806 prect
->top
+= rt
.bottom
+2;
1809 if (IsWindowVisible(Globals
.hstatusbar
)) {
1810 GetClientRect(Globals
.hstatusbar
, &rt
);
1811 prect
->bottom
-= rt
.bottom
;
1815 static BOOL
toggle_fullscreen(HWND hwnd
)
1819 if ((g_fullscreen
.mode
=!g_fullscreen
.mode
)) {
1820 GetWindowRect(hwnd
, &g_fullscreen
.orgPos
);
1821 g_fullscreen
.wasZoomed
= IsZoomed(hwnd
);
1823 Frame_CalcFrameClient(hwnd
, &rt
);
1824 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
1825 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
1827 rt
.left
= g_fullscreen
.orgPos
.left
-rt
.left
;
1828 rt
.top
= g_fullscreen
.orgPos
.top
-rt
.top
;
1829 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+g_fullscreen
.orgPos
.right
-rt
.right
;
1830 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+g_fullscreen
.orgPos
.bottom
-rt
.bottom
;
1832 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
1834 MoveWindow(hwnd
, g_fullscreen
.orgPos
.left
, g_fullscreen
.orgPos
.top
,
1835 g_fullscreen
.orgPos
.right
-g_fullscreen
.orgPos
.left
,
1836 g_fullscreen
.orgPos
.bottom
-g_fullscreen
.orgPos
.top
, TRUE
);
1838 if (g_fullscreen
.wasZoomed
)
1839 ShowWindow(hwnd
, WS_MAXIMIZE
);
1842 return g_fullscreen
.mode
;
1845 static void fullscreen_move(HWND hwnd
)
1848 GetWindowRect(hwnd
, &pos
);
1850 Frame_CalcFrameClient(hwnd
, &rt
);
1851 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
1852 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
1854 rt
.left
= pos
.left
-rt
.left
;
1855 rt
.top
= pos
.top
-rt
.top
;
1856 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+pos
.right
-rt
.right
;
1857 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+pos
.bottom
-rt
.bottom
;
1859 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
1865 static void toggle_child(HWND hwnd
, UINT cmd
, HWND hchild
)
1867 BOOL vis
= IsWindowVisible(hchild
);
1869 CheckMenuItem(Globals
.hMenuOptions
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
1871 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
1873 #ifndef _NO_EXTENSIONS
1874 if (g_fullscreen
.mode
)
1875 fullscreen_move(hwnd
);
1878 resize_frame_client(hwnd
);
1881 BOOL
activate_drive_window(LPCTSTR path
)
1883 TCHAR drv1
[_MAX_DRIVE
], drv2
[_MAX_DRIVE
];
1886 _tsplitpath(path
, drv1
, 0, 0, 0);
1888 /* search for a already open window for the same drive */
1889 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
1890 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(child_wnd
, GWL_USERDATA
);
1893 _tsplitpath(child
->root
.path
, drv2
, 0, 0, 0);
1895 if (!lstrcmpi(drv2
, drv1
)) {
1896 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
1898 if (IsMinimized(child_wnd
))
1899 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
1909 BOOL
activate_fs_window(LPCTSTR filesys
)
1913 /* search for a already open window of the given file system name */
1914 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
1915 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(child_wnd
, GWL_USERDATA
);
1918 if (!lstrcmpi(child
->root
.fs
, filesys
)) {
1919 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
1921 if (IsMinimized(child_wnd
))
1922 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
1932 LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1934 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1938 DestroyWindow(hwnd
);
1940 /* clear handle variables */
1941 Globals
.hMenuFrame
= 0;
1942 Globals
.hMenuView
= 0;
1943 Globals
.hMenuOptions
= 0;
1944 Globals
.hMainWnd
= 0;
1945 Globals
.hmdiclient
= 0;
1946 Globals
.hdrivebar
= 0;
1950 /* don't exit desktop when closing file manager window */
1951 if (!Globals
.hwndParent
)
1955 case WM_INITMENUPOPUP
: {
1956 HWND hwndClient
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
1958 if (!SendMessage(hwndClient
, WM_INITMENUPOPUP
, wparam
, lparam
))
1963 UINT cmd
= LOWORD(wparam
);
1964 HWND hwndClient
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
1966 if (SendMessage(hwndClient
, WM_DISPATCH_COMMAND
, wparam
, lparam
))
1969 if (cmd
>=ID_DRIVE_FIRST
&& cmd
<=ID_DRIVE_FIRST
+0xFF) {
1970 TCHAR drv
[_MAX_DRIVE
], path
[MAX_PATH
];
1972 LPCTSTR root
= Globals
.drives
;
1975 for(i
=cmd
-ID_DRIVE_FIRST
; i
--; root
++)
1979 if (activate_drive_window(root
))
1982 _tsplitpath(root
, drv
, 0, 0, 0);
1984 if (!SetCurrentDirectory(drv
)) {
1985 display_error(hwnd
, GetLastError());
1989 GetCurrentDirectory(MAX_PATH
, path
); /*TODO: store last directory per drive */
1990 child
= alloc_child_window(path
, NULL
, hwnd
);
1992 if (!create_child_window(child
))
1994 } else switch(cmd
) {
1996 SendMessage(hwnd
, WM_CLOSE
, 0, 0);
1999 case ID_WINDOW_NEW
: {
2000 TCHAR path
[MAX_PATH
];
2003 GetCurrentDirectory(MAX_PATH
, path
);
2004 child
= alloc_child_window(path
, NULL
, hwnd
);
2006 if (!create_child_window(child
))
2014 case ID_WINDOW_CASCADE
:
2015 SendMessage(Globals
.hmdiclient
, WM_MDICASCADE
, 0, 0);
2018 case ID_WINDOW_TILE_HORZ
:
2019 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
2022 case ID_WINDOW_TILE_VERT
:
2023 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
2026 case ID_WINDOW_ARRANGE
:
2027 SendMessage(Globals
.hmdiclient
, WM_MDIICONARRANGE
, 0, 0);
2030 case ID_SELECT_FONT
: {
2031 TCHAR dlg_name
[BUFFER_LEN
], dlg_info
[BUFFER_LEN
];
2035 HDC hdc
= GetDC(hwnd
);
2036 chFont
.lStructSize
= sizeof(CHOOSEFONT
);
2037 chFont
.hwndOwner
= hwnd
;
2039 chFont
.lpLogFont
= &lFont
;
2040 chFont
.Flags
= CF_SCREENFONTS
| CF_FORCEFONTEXIST
| CF_LIMITSIZE
| CF_NOSCRIPTSEL
;
2041 chFont
.rgbColors
= RGB(0,0,0);
2042 chFont
.lCustData
= 0;
2043 chFont
.lpfnHook
= NULL
;
2044 chFont
.lpTemplateName
= NULL
;
2045 chFont
.hInstance
= Globals
.hInstance
;
2046 chFont
.lpszStyle
= NULL
;
2047 chFont
.nFontType
= SIMULATED_FONTTYPE
;
2048 chFont
.nSizeMin
= 0;
2049 chFont
.nSizeMax
= 24;
2051 if (ChooseFont(&chFont
)) {
2054 Globals
.hfont
= CreateFontIndirect(&lFont
);
2055 SelectFont(hdc
, Globals
.hfont
);
2056 GetTextExtentPoint32(hdc
, sSpace
, 1, &Globals
.spaceSize
);
2058 /* change font in all open child windows */
2059 for(childWnd
=GetWindow(Globals
.hmdiclient
,GW_CHILD
); childWnd
; childWnd
=GetNextWindow(childWnd
,GW_HWNDNEXT
)) {
2060 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(childWnd
, GWL_USERDATA
);
2061 SetWindowFont(child
->left
.hwnd
, Globals
.hfont
, TRUE
);
2062 SetWindowFont(child
->right
.hwnd
, Globals
.hfont
, TRUE
);
2063 ListBox_SetItemHeight(child
->left
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
2064 ListBox_SetItemHeight(child
->right
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
2065 InvalidateRect(child
->left
.hwnd
, NULL
, TRUE
);
2066 InvalidateRect(child
->right
.hwnd
, NULL
, TRUE
);
2069 else if (CommDlgExtendedError()) {
2070 LoadString(Globals
.hInstance
, IDS_FONT_SEL_DLG_NAME
, dlg_name
, BUFFER_LEN
);
2071 LoadString(Globals
.hInstance
, IDS_FONT_SEL_ERROR
, dlg_info
, BUFFER_LEN
);
2072 MessageBox(hwnd
, dlg_info
, dlg_name
, MB_OK
);
2075 ReleaseDC(hwnd
, hdc
);
2079 case ID_VIEW_TOOL_BAR
:
2080 toggle_child(hwnd
, cmd
, Globals
.htoolbar
);
2083 case ID_VIEW_DRIVE_BAR
:
2084 toggle_child(hwnd
, cmd
, Globals
.hdrivebar
);
2087 case ID_VIEW_STATUSBAR
:
2088 toggle_child(hwnd
, cmd
, Globals
.hstatusbar
);
2092 struct ExecuteDialog dlg
;
2094 memset(&dlg
, 0, sizeof(struct ExecuteDialog
));
2096 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_EXECUTE
), hwnd
, ExecuteDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
2097 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, dlg
.cmd
/*file*/, NULL
/*parameters*/, NULL
/*dir*/, dlg
.cmdshow
);
2099 if ((int)hinst
<= 32)
2100 display_error(hwnd
, GetLastError());
2104 case ID_CONNECT_NETWORK_DRIVE
: {
2105 DWORD ret
= WNetConnectionDialog(hwnd
, RESOURCETYPE_DISK
);
2106 if (ret
== NO_ERROR
)
2108 else if (ret
!= (DWORD
)-1) {
2109 if (ret
== ERROR_EXTENDED_ERROR
)
2110 display_network_error(hwnd
);
2112 display_error(hwnd
, ret
);
2116 case ID_DISCONNECT_NETWORK_DRIVE
: {
2117 DWORD ret
= WNetDisconnectDialog(hwnd
, RESOURCETYPE_DISK
);
2118 if (ret
== NO_ERROR
)
2120 else if (ret
!= (DWORD
)-1) {
2121 if (ret
== ERROR_EXTENDED_ERROR
)
2122 display_network_error(hwnd
);
2124 display_error(hwnd
, ret
);
2128 #ifndef __MINGW32__ /* SHFormatDrive missing in MinGW (as of 13.5.2005) */
2129 case ID_FORMAT_DISK
: {
2130 UINT sem_org
= SetErrorMode(0); /* Get the current Error Mode settings. */
2131 SetErrorMode(sem_org
& ~SEM_FAILCRITICALERRORS
); /* Force O/S to handle */
2132 SHFormatDrive(hwnd
, 0 /* A: */, SHFMT_ID_DEFAULT
, 0);
2133 SetErrorMode(sem_org
); /* Put it back the way it was. */
2138 WinHelp(hwnd
, RS(b1
,IDS_WINEFILE
), HELP_INDEX
, 0);
2141 #ifndef _NO_EXTENSIONS
2142 case ID_VIEW_FULLSCREEN
:
2143 CheckMenuItem(Globals
.hMenuOptions
, cmd
, toggle_fullscreen(hwnd
)?MF_CHECKED
:0);
2147 case ID_DRIVE_UNIX_FS
: {
2148 TCHAR path
[MAX_PATH
];
2150 char cpath
[MAX_PATH
];
2154 if (activate_fs_window(RS(b1
,IDS_UNIXFS
)))
2159 call_getcwd(cpath
, MAX_PATH
);
2160 MultiByteToWideChar(CP_UNIXCP
, 0, cpath
, -1, path
, MAX_PATH
);
2162 call_getcwd(path
, MAX_PATH
);
2164 child
= alloc_child_window(path
, NULL
, hwnd
);
2166 if (!create_child_window(child
))
2171 #ifdef _SHELL_FOLDERS
2172 case ID_DRIVE_SHELL_NS
: {
2173 TCHAR path
[MAX_PATH
];
2176 if (activate_fs_window(RS(b1
,IDS_SHELL
)))
2179 GetCurrentDirectory(MAX_PATH
, path
);
2180 child
= alloc_child_window(path
, get_path_pidl(path
,hwnd
), hwnd
);
2182 if (!create_child_window(child
))
2188 /*TODO: There are even more menu items! */
2190 #ifndef _NO_EXTENSIONS
2193 WineLicense(Globals
.hMainWnd
);
2196 case ID_NO_WARRANTY
:
2197 WineWarranty(Globals
.hMainWnd
);
2202 ShellAbout(hwnd
, RS(b2
,IDS_WINE
), RS(b1
,IDS_WINEFILE
), 0);
2206 ShellAbout(hwnd
, RS(b1
,IDS_WINEFILE
), NULL
, 0);
2208 #endif /* _NO_EXTENSIONS */
2211 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2212 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2213 else */if ((cmd
<IDW_FIRST_CHILD
|| cmd
>=IDW_FIRST_CHILD
+0x100) &&
2214 (cmd
<SC_SIZE
|| cmd
>SC_RESTORE
))
2215 MessageBox(hwnd
, RS(b2
,IDS_NO_IMPL
), RS(b1
,IDS_WINEFILE
), MB_OK
);
2217 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2222 resize_frame(hwnd
, LOWORD(lparam
), HIWORD(lparam
));
2223 break; /* do not pass message to DefFrameProc */
2225 #ifndef _NO_EXTENSIONS
2226 case WM_GETMINMAXINFO
: {
2227 LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
2229 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2230 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2233 case FRM_CALC_CLIENT
:
2234 frame_get_clientspace(hwnd
, (PRECT
)lparam
);
2236 #endif /* _NO_EXTENSIONS */
2239 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2246 static TCHAR g_pos_names
[COLUMNS
][20] = {
2250 static const int g_pos_align
[] = {
2252 HDF_LEFT
, /* Name */
2253 HDF_RIGHT
, /* Size */
2254 HDF_LEFT
, /* CDate */
2255 #ifndef _NO_EXTENSIONS
2256 HDF_LEFT
, /* ADate */
2257 HDF_LEFT
, /* MDate */
2258 HDF_LEFT
, /* Index */
2259 HDF_CENTER
, /* Links */
2261 HDF_CENTER
, /* Attributes */
2262 #ifndef _NO_EXTENSIONS
2263 HDF_LEFT
/* Security */
2267 static void resize_tree(ChildWnd
* child
, int cx
, int cy
)
2269 HDWP hdwp
= BeginDeferWindowPos(4);
2277 cx
= child
->split_pos
+ SPLIT_WIDTH
/2;
2279 #ifndef _NO_EXTENSIONS
2287 Header_Layout(child
->left
.hwndHeader
, &hdl
);
2289 DeferWindowPos(hdwp
, child
->left
.hwndHeader
, wp
.hwndInsertAfter
,
2290 wp
.x
-1, wp
.y
, child
->split_pos
-SPLIT_WIDTH
/2+1, wp
.cy
, wp
.flags
);
2291 DeferWindowPos(hdwp
, child
->right
.hwndHeader
, wp
.hwndInsertAfter
,
2292 rt
.left
+cx
+1, wp
.y
, wp
.cx
-cx
+2, wp
.cy
, wp
.flags
);
2294 #endif /* _NO_EXTENSIONS */
2296 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
);
2297 DeferWindowPos(hdwp
, child
->right
.hwnd
, 0, rt
.left
+cx
+1, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
2299 EndDeferWindowPos(hdwp
);
2303 #ifndef _NO_EXTENSIONS
2305 static HWND
create_header(HWND parent
, Pane
* pane
, int id
)
2310 HWND hwnd
= CreateWindow(WC_HEADER
, 0, WS_CHILD
|WS_VISIBLE
|HDS_HORZ
/*TODO: |HDS_BUTTONS + sort orders*/,
2311 0, 0, 0, 0, parent
, (HMENU
)id
, Globals
.hInstance
, 0);
2315 SetWindowFont(hwnd
, GetStockObject(DEFAULT_GUI_FONT
), FALSE
);
2317 hdi
.mask
= HDI_TEXT
|HDI_WIDTH
|HDI_FORMAT
;
2319 for(idx
=0; idx
<COLUMNS
; idx
++) {
2320 hdi
.pszText
= g_pos_names
[idx
];
2321 hdi
.fmt
= HDF_STRING
| g_pos_align
[idx
];
2322 hdi
.cxy
= pane
->widths
[idx
];
2323 Header_InsertItem(hwnd
, idx
, &hdi
);
2329 #endif /* _NO_EXTENSIONS */
2332 static void init_output(HWND hwnd
)
2334 const static TCHAR s1000
[] = {'1','0','0','0','\0'};
2338 HDC hdc
= GetDC(hwnd
);
2340 if (GetNumberFormat(LOCALE_USER_DEFAULT
, 0, s1000
, 0, b
, 16) > 4)
2341 Globals
.num_sep
= b
[1];
2343 Globals
.num_sep
= TEXT('.');
2345 old_font
= SelectFont(hdc
, Globals
.hfont
);
2346 GetTextExtentPoint32(hdc
, sSpace
, 1, &Globals
.spaceSize
);
2347 SelectFont(hdc
, old_font
);
2348 ReleaseDC(hwnd
, hdc
);
2351 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
);
2354 /* calculate preferred width for all visible columns */
2356 static BOOL
calc_widths(Pane
* pane
, BOOL anyway
)
2358 int col
, x
, cx
, spc
=3*Globals
.spaceSize
.cx
;
2359 int entries
= ListBox_GetCount(pane
->hwnd
);
2360 int orgWidths
[COLUMNS
];
2361 int orgPositions
[COLUMNS
+1];
2367 memcpy(orgWidths
, pane
->widths
, sizeof(orgWidths
));
2368 memcpy(orgPositions
, pane
->positions
, sizeof(orgPositions
));
2371 for(col
=0; col
<COLUMNS
; col
++)
2372 pane
->widths
[col
] = 0;
2374 hdc
= GetDC(pane
->hwnd
);
2375 hfontOld
= SelectFont(hdc
, Globals
.hfont
);
2377 for(cnt
=0; cnt
<entries
; cnt
++) {
2378 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, cnt
);
2387 dis
.hwndItem
= pane
->hwnd
;
2389 dis
.rcItem
.left
= 0;
2391 dis
.rcItem
.right
= 0;
2392 dis
.rcItem
.bottom
= 0;
2393 /*dis.itemData = 0; */
2395 draw_item(pane
, &dis
, entry
, COLUMNS
);
2398 SelectObject(hdc
, hfontOld
);
2399 ReleaseDC(pane
->hwnd
, hdc
);
2402 for(col
=0; col
<COLUMNS
; col
++) {
2403 pane
->positions
[col
] = x
;
2404 cx
= pane
->widths
[col
];
2409 if (cx
< IMAGE_WIDTH
)
2412 pane
->widths
[col
] = cx
;
2418 pane
->positions
[COLUMNS
] = x
;
2420 ListBox_SetHorizontalExtent(pane
->hwnd
, x
);
2423 if (!memcmp(orgWidths
, pane
->widths
, sizeof(orgWidths
)))
2426 /* don't move, if only collapsing an entry */
2427 if (!anyway
&& pane
->widths
[0]<orgWidths
[0] &&
2428 !memcmp(orgWidths
+1, pane
->widths
+1, sizeof(orgWidths
)-sizeof(int))) {
2429 pane
->widths
[0] = orgWidths
[0];
2430 memcpy(pane
->positions
, orgPositions
, sizeof(orgPositions
));
2435 InvalidateRect(pane
->hwnd
, 0, TRUE
);
2441 /* calculate one preferred column width */
2443 static void calc_single_width(Pane
* pane
, int col
)
2447 int entries
= ListBox_GetCount(pane
->hwnd
);
2451 pane
->widths
[col
] = 0;
2453 hdc
= GetDC(pane
->hwnd
);
2454 hfontOld
= SelectFont(hdc
, Globals
.hfont
);
2456 for(cnt
=0; cnt
<entries
; cnt
++) {
2457 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, cnt
);
2465 dis
.hwndItem
= pane
->hwnd
;
2467 dis
.rcItem
.left
= 0;
2469 dis
.rcItem
.right
= 0;
2470 dis
.rcItem
.bottom
= 0;
2471 /*dis.itemData = 0; */
2473 draw_item(pane
, &dis
, entry
, col
);
2476 SelectObject(hdc
, hfontOld
);
2477 ReleaseDC(pane
->hwnd
, hdc
);
2479 cx
= pane
->widths
[col
];
2482 cx
+= 3*Globals
.spaceSize
.cx
;
2484 if (cx
< IMAGE_WIDTH
)
2488 pane
->widths
[col
] = cx
;
2490 x
= pane
->positions
[col
] + cx
;
2492 for(; col
<COLUMNS
; ) {
2493 pane
->positions
[++col
] = x
;
2494 x
+= pane
->widths
[col
];
2497 ListBox_SetHorizontalExtent(pane
->hwnd
, x
);
2501 static BOOL
pattern_match(LPCTSTR str
, LPCTSTR pattern
)
2503 for( ; *str
&&*pattern
; str
++,pattern
++) {
2504 if (*pattern
== '*') {
2506 while(*pattern
== '*');
2512 if (_totupper(*str
)==_totupper(*pattern
) && pattern_match(str
, pattern
))
2517 else if (_totupper(*str
)!=_totupper(*pattern
) && *pattern
!='?')
2521 if (*str
|| *pattern
)
2522 if (*pattern
!='*' || pattern
[1]!='\0')
2535 static enum FILE_TYPE
get_file_type(LPCTSTR filename
);
2538 /* insert listbox entries after index idx */
2540 static int insert_entries(Pane
* pane
, Entry
* dir
, LPCTSTR pattern
, int filter_flags
, int idx
)
2547 ShowWindow(pane
->hwnd
, SW_HIDE
);
2549 for(; entry
; entry
=entry
->next
) {
2551 if (pane
->treePane
&& !(entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
2555 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
2556 /* don't display entries "." and ".." in the left pane */
2557 if (pane
->treePane
&& entry
->data
.cFileName
[0]==TEXT('.'))
2559 #ifndef _NO_EXTENSIONS
2560 entry
->data
.cFileName
[1]==TEXT('\0') ||
2562 (entry
->data
.cFileName
[1]==TEXT('.') && entry
->data
.cFileName
[2]==TEXT('\0')))
2565 /* filter directories in right pane */
2566 if (!pane
->treePane
&& !(filter_flags
&TF_DIRECTORIES
))
2570 /* filter using the file name pattern */
2572 if (!pattern_match(entry
->data
.cFileName
, pattern
))
2575 /* filter system and hidden files */
2576 if (!(filter_flags
&TF_HIDDEN
) && (entry
->data
.dwFileAttributes
&(FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
)))
2579 /* filter looking at the file type */
2580 if ((filter_flags
&(TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
)) != (TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
))
2581 switch(get_file_type(entry
->data
.cFileName
)) {
2583 if (!(filter_flags
& TF_PROGRAMS
))
2588 if (!(filter_flags
& TF_DOCUMENTS
))
2592 default: // TF_OTHERS
2593 if (!(filter_flags
& TF_OTHERS
))
2600 ListBox_InsertItemData(pane
->hwnd
, idx
, entry
);
2602 if (pane
->treePane
&& entry
->expanded
)
2603 idx
= insert_entries(pane
, entry
->down
, pattern
, filter_flags
, idx
);
2606 ShowWindow(pane
->hwnd
, SW_SHOW
);
2612 static void format_bytes(LPTSTR buffer
, LONGLONG bytes
)
2614 const static TCHAR sFmtGB
[] = {'%', '.', '1', 'f', ' ', 'G', 'B', '\0'};
2615 const static TCHAR sFmtMB
[] = {'%', '.', '1', 'f', ' ', 'M', 'B', '\0'};
2616 const static TCHAR sFmtkB
[] = {'%', '.', '1', 'f', ' ', 'k', 'B', '\0'};
2618 float fBytes
= (float)bytes
;
2620 if (bytes
>= 1073741824) /* 1 GB */
2621 _stprintf(buffer
, sFmtGB
, fBytes
/1073741824.f
+.5f
);
2622 else if (bytes
>= 1048576) /* 1 MB */
2623 _stprintf(buffer
, sFmtMB
, fBytes
/1048576.f
+.5f
);
2624 else if (bytes
>= 1024) /* 1 kB */
2625 _stprintf(buffer
, sFmtkB
, fBytes
/1024.f
+.5f
);
2627 _stprintf(buffer
, sLongNumFmt
, bytes
);
2630 static void set_space_status()
2632 ULARGE_INTEGER ulFreeBytesToCaller
, ulTotalBytes
, ulFreeBytes
;
2633 TCHAR fmt
[64], b1
[64], b2
[64], buffer
[BUFFER_LEN
];
2635 if (GetDiskFreeSpaceEx(NULL
, &ulFreeBytesToCaller
, &ulTotalBytes
, &ulFreeBytes
)) {
2636 format_bytes(b1
, ulFreeBytesToCaller
.QuadPart
);
2637 format_bytes(b2
, ulTotalBytes
.QuadPart
);
2638 _stprintf(buffer
, RS(fmt
,IDS_FREE_SPACE_FMT
), b1
, b2
);
2640 _tcscpy(buffer
, sQMarks
);
2642 SendMessage(Globals
.hstatusbar
, SB_SETTEXT
, 0, (LPARAM
)buffer
);
2646 static WNDPROC g_orgTreeWndProc
;
2648 static void create_tree_window(HWND parent
, Pane
* pane
, int id
, int id_header
, LPCTSTR pattern
, int filter_flags
)
2650 const static TCHAR sListBox
[] = {'L','i','s','t','B','o','x','\0'};
2652 static int s_init
= 0;
2653 Entry
* entry
= pane
->root
;
2655 pane
->hwnd
= CreateWindow(sListBox
, sEmpty
, WS_CHILD
|WS_VISIBLE
|WS_HSCROLL
|WS_VSCROLL
|
2656 LBS_DISABLENOSCROLL
|LBS_NOINTEGRALHEIGHT
|LBS_OWNERDRAWFIXED
|LBS_NOTIFY
,
2657 0, 0, 0, 0, parent
, (HMENU
)id
, Globals
.hInstance
, 0);
2659 SetWindowLong(pane
->hwnd
, GWL_USERDATA
, (LPARAM
)pane
);
2660 g_orgTreeWndProc
= SubclassWindow(pane
->hwnd
, TreeWndProc
);
2662 SetWindowFont(pane
->hwnd
, Globals
.hfont
, FALSE
);
2664 /* insert entries into listbox */
2666 insert_entries(pane
, entry
, pattern
, filter_flags
, -1);
2668 /* calculate column widths */
2671 init_output(pane
->hwnd
);
2674 calc_widths(pane
, TRUE
);
2676 #ifndef _NO_EXTENSIONS
2677 pane
->hwndHeader
= create_header(parent
, pane
, id_header
);
2682 static void InitChildWindow(ChildWnd
* child
)
2684 create_tree_window(child
->hwnd
, &child
->left
, IDW_TREE_LEFT
, IDW_HEADER_LEFT
, NULL
, TF_ALL
);
2685 create_tree_window(child
->hwnd
, &child
->right
, IDW_TREE_RIGHT
, IDW_HEADER_RIGHT
, child
->filter_pattern
, child
->filter_flags
);
2689 static void format_date(const FILETIME
* ft
, TCHAR
* buffer
, int visible_cols
)
2695 *buffer
= TEXT('\0');
2697 if (!ft
->dwLowDateTime
&& !ft
->dwHighDateTime
)
2700 if (!FileTimeToLocalFileTime(ft
, &lft
))
2701 {err
: _tcscpy(buffer
,sQMarks
); return;}
2703 if (!FileTimeToSystemTime(&lft
, &systime
))
2706 if (visible_cols
& COL_DATE
) {
2707 len
= GetDateFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
, BUFFER_LEN
);
2712 if (visible_cols
& COL_TIME
) {
2714 buffer
[len
-1] = ' ';
2716 buffer
[len
++] = ' ';
2718 if (!GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
+len
, BUFFER_LEN
-len
))
2719 buffer
[len
] = TEXT('\0');
2724 static void calc_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2726 RECT rt
= {0, 0, 0, 0};
2728 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
2730 if (rt
.right
> pane
->widths
[col
])
2731 pane
->widths
[col
] = rt
.right
;
2734 static void calc_tabbed_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2736 RECT rt
= {0, 0, 0, 0};
2738 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2739 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2741 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2742 /*FIXME rt (0,0) ??? */
2744 if (rt
.right
> pane
->widths
[col
])
2745 pane
->widths
[col
] = rt
.right
;
2749 static void output_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
, DWORD flags
)
2751 int x
= dis
->rcItem
.left
;
2754 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2755 rt
.top
= dis
->rcItem
.top
;
2756 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2757 rt
.bottom
= dis
->rcItem
.bottom
;
2759 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_SINGLELINE
|DT_NOPREFIX
|flags
);
2762 static void output_tabbed_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2764 int x
= dis
->rcItem
.left
;
2767 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2768 rt
.top
= dis
->rcItem
.top
;
2769 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2770 rt
.bottom
= dis
->rcItem
.bottom
;
2772 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2773 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2775 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2778 static void output_number(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2780 int x
= dis
->rcItem
.left
;
2787 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2788 rt
.top
= dis
->rcItem
.top
;
2789 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2790 rt
.bottom
= dis
->rcItem
.bottom
;
2795 /* insert number separator characters */
2796 pos
= lstrlen(s
) % 3;
2802 *d
++ = Globals
.num_sep
;
2806 DrawText(dis
->hDC
, b
, d
-b
, &rt
, DT_RIGHT
|DT_SINGLELINE
|DT_NOPREFIX
|DT_END_ELLIPSIS
);
2810 static BOOL
is_exe_file(LPCTSTR ext
)
2812 static const TCHAR executable_extensions
[][4] = {
2817 #ifndef _NO_EXTENSIONS
2821 #endif /* _NO_EXTENSIONS */
2825 TCHAR ext_buffer
[_MAX_EXT
];
2826 const TCHAR (*p
)[4];
2830 for(s
=ext
+1,d
=ext_buffer
; (*d
=tolower(*s
)); s
++)
2833 for(p
=executable_extensions
; (*p
)[0]; p
++)
2834 if (!_tcsicmp(ext_buffer
, *p
))
2840 static BOOL
is_registered_type(LPCTSTR ext
)
2842 /* check if there exists a classname for this file extension in the registry */
2843 if (!RegQueryValue(HKEY_CLASSES_ROOT
, ext
, NULL
, NULL
))
2849 static enum FILE_TYPE
get_file_type(LPCTSTR filename
)
2851 LPCTSTR ext
= _tcsrchr(filename
, '.');
2855 if (is_exe_file(ext
))
2856 return FT_EXECUTABLE
;
2857 else if (is_registered_type(ext
))
2864 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
)
2866 TCHAR buffer
[BUFFER_LEN
];
2868 int visible_cols
= pane
->visible_cols
;
2869 COLORREF bkcolor
, textcolor
;
2870 RECT focusRect
= dis
->rcItem
;
2877 attrs
= entry
->data
.dwFileAttributes
;
2879 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) {
2880 if (entry
->data
.cFileName
[0]==TEXT('.') && entry
->data
.cFileName
[1]==TEXT('.')
2881 && entry
->data
.cFileName
[2]==TEXT('\0'))
2882 img
= IMG_FOLDER_UP
;
2883 #ifndef _NO_EXTENSIONS
2884 else if (entry
->data
.cFileName
[0]==TEXT('.') && entry
->data
.cFileName
[1]==TEXT('\0'))
2885 img
= IMG_FOLDER_CUR
;
2888 #ifdef _NO_EXTENSIONS
2891 (pane
->treePane
&& (dis
->itemState
&ODS_FOCUS
)))
2892 img
= IMG_OPEN_FOLDER
;
2896 switch(get_file_type(entry
->data
.cFileName
)) {
2897 case FT_EXECUTABLE
: img
= IMG_EXECUTABLE
; break;
2898 case FT_DOCUMENT
: img
= IMG_DOCUMENT
; break;
2899 default: img
= IMG_FILE
;
2907 if (pane
->treePane
) {
2909 img_pos
= dis
->rcItem
.left
+ entry
->level
*(IMAGE_WIDTH
+TREE_LINE_DX
);
2911 if (calcWidthCol
== -1) {
2913 int y
= dis
->rcItem
.top
+ IMAGE_HEIGHT
/2;
2916 HRGN hrgn_org
= CreateRectRgn(0, 0, 0, 0);
2919 rt_clip
.left
= dis
->rcItem
.left
;
2920 rt_clip
.top
= dis
->rcItem
.top
;
2921 rt_clip
.right
= dis
->rcItem
.left
+pane
->widths
[col
];
2922 rt_clip
.bottom
= dis
->rcItem
.bottom
;
2924 hrgn
= CreateRectRgnIndirect(&rt_clip
);
2926 if (!GetClipRgn(dis
->hDC
, hrgn_org
)) {
2927 DeleteObject(hrgn_org
);
2931 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
2932 ExtSelectClipRgn(dis
->hDC
, hrgn
, RGN_AND
);
2935 if ((up
=entry
->up
) != NULL
) {
2936 MoveToEx(dis
->hDC
, img_pos
-IMAGE_WIDTH
/2, y
, 0);
2937 LineTo(dis
->hDC
, img_pos
-2, y
);
2939 x
= img_pos
- IMAGE_WIDTH
/2;
2942 x
-= IMAGE_WIDTH
+TREE_LINE_DX
;
2946 && (up
->next
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
2949 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
2950 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
2952 } while((up
=up
->up
) != NULL
);
2955 x
= img_pos
- IMAGE_WIDTH
/2;
2957 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
2958 LineTo(dis
->hDC
, x
, y
);
2962 && (entry
->next
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
)
2965 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
2967 if (entry->down && entry->expanded) {
2968 x += IMAGE_WIDTH+TREE_LINE_DX;
2969 MoveToEx(dis->hDC, x, dis->rcItem.top+IMAGE_HEIGHT, 0);
2970 LineTo(dis->hDC, x, dis->rcItem.bottom);
2973 SelectClipRgn(dis
->hDC
, hrgn_org
);
2974 if (hrgn_org
) DeleteObject(hrgn_org
);
2975 /* SelectObject(dis->hDC, holdPen); */
2976 } else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
) {
2977 int right
= img_pos
+ IMAGE_WIDTH
- TREE_LINE_DX
;
2979 if (right
> pane
->widths
[col
])
2980 pane
->widths
[col
] = right
;
2983 img_pos
= dis
->rcItem
.left
;
2986 img_pos
= dis
->rcItem
.left
;
2988 if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2989 pane
->widths
[col
] = IMAGE_WIDTH
;
2992 if (calcWidthCol
== -1) {
2993 focusRect
.left
= img_pos
- 2;
2995 #ifdef _NO_EXTENSIONS
2996 if (pane
->treePane
&& entry
) {
2999 DrawText(dis
->hDC
, entry
->data
.cFileName
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
3001 focusRect
.right
= dis
->rcItem
.left
+pane
->positions
[col
+1]+TREE_LINE_DX
+ rt
.right
+2;
3005 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
)
3006 textcolor
= COLOR_COMPRESSED
;
3008 #endif /* _NO_EXTENSIONS */
3009 textcolor
= RGB(0,0,0);
3011 if (dis
->itemState
& ODS_FOCUS
) {
3012 textcolor
= RGB(255,255,255);
3013 bkcolor
= COLOR_SELECTION
;
3015 bkcolor
= RGB(255,255,255);
3018 hbrush
= CreateSolidBrush(bkcolor
);
3019 FillRect(dis
->hDC
, &focusRect
, hbrush
);
3020 DeleteObject(hbrush
);
3022 SetBkMode(dis
->hDC
, TRANSPARENT
);
3023 SetTextColor(dis
->hDC
, textcolor
);
3025 cx
= pane
->widths
[col
];
3027 if (cx
&& img
!=IMG_NONE
) {
3028 if (cx
> IMAGE_WIDTH
)
3031 #ifdef _SHELL_FOLDERS
3032 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
3033 DrawIconEx(dis
->hDC
, img_pos
, dis
->rcItem
.top
, entry
->hicon
, cx
, GetSystemMetrics(SM_CYSMICON
), 0, 0, DI_NORMAL
);
3036 ImageList_DrawEx(Globals
.himl
, img
, dis
->hDC
,
3037 img_pos
, dis
->rcItem
.top
, cx
,
3038 IMAGE_HEIGHT
, bkcolor
, CLR_DEFAULT
, ILD_NORMAL
);
3045 #ifdef _NO_EXTENSIONS
3046 if (img
>= IMG_FOLDER_UP
)
3052 /* ouput file name */
3053 if (calcWidthCol
== -1)
3054 output_text(pane
, dis
, col
, entry
->data
.cFileName
, 0);
3055 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3056 calc_width(pane
, dis
, col
, entry
->data
.cFileName
);
3060 #ifdef _NO_EXTENSIONS
3061 if (!pane
->treePane
) {
3064 /* display file size */
3065 if (visible_cols
& COL_SIZE
) {
3066 #ifdef _NO_EXTENSIONS
3067 if (!(attrs
&FILE_ATTRIBUTE_DIRECTORY
))
3072 size
= ((ULONGLONG
)entry
->data
.nFileSizeHigh
<< 32) | entry
->data
.nFileSizeLow
;
3074 _stprintf(buffer
, sLongNumFmt
, size
);
3076 if (calcWidthCol
== -1)
3077 output_number(pane
, dis
, col
, buffer
);
3078 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3079 calc_width(pane
, dis
, col
, buffer
);/*TODO: not in every case time enough */
3085 /* display file date */
3086 if (visible_cols
& (COL_DATE
|COL_TIME
)) {
3087 #ifndef _NO_EXTENSIONS
3088 format_date(&entry
->data
.ftCreationTime
, buffer
, visible_cols
);
3089 if (calcWidthCol
== -1)
3090 output_text(pane
, dis
, col
, buffer
, 0);
3091 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3092 calc_width(pane
, dis
, col
, buffer
);
3095 format_date(&entry
->data
.ftLastAccessTime
, buffer
, visible_cols
);
3096 if (calcWidthCol
== -1)
3097 output_text(pane
, dis
, col
, buffer
, 0);
3098 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3099 calc_width(pane
, dis
, col
, buffer
);
3101 #endif /* _NO_EXTENSIONS */
3103 format_date(&entry
->data
.ftLastWriteTime
, buffer
, visible_cols
);
3104 if (calcWidthCol
== -1)
3105 output_text(pane
, dis
, col
, buffer
, 0);
3106 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3107 calc_width(pane
, dis
, col
, buffer
);
3111 #ifndef _NO_EXTENSIONS
3112 if (entry
->bhfi_valid
) {
3113 ULONGLONG index
= ((ULONGLONG
)entry
->bhfi
.nFileIndexHigh
<< 32) | entry
->bhfi
.nFileIndexLow
;
3115 if (visible_cols
& COL_INDEX
) {
3116 _stprintf(buffer
, sLongHexFmt
, index
);
3118 if (calcWidthCol
== -1)
3119 output_text(pane
, dis
, col
, buffer
, DT_RIGHT
);
3120 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3121 calc_width(pane
, dis
, col
, buffer
);
3126 if (visible_cols
& COL_LINKS
) {
3127 wsprintf(buffer
, sNumFmt
, entry
->bhfi
.nNumberOfLinks
);
3129 if (calcWidthCol
== -1)
3130 output_text(pane
, dis
, col
, buffer
, DT_CENTER
);
3131 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3132 calc_width(pane
, dis
, col
, buffer
);
3138 #endif /* _NO_EXTENSIONS */
3140 /* show file attributes */
3141 if (visible_cols
& COL_ATTRIBUTES
) {
3142 #ifdef _NO_EXTENSIONS
3143 const static TCHAR s4Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3144 _tcscpy(buffer
, s4Tabs
);
3146 const static TCHAR s11Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3147 _tcscpy(buffer
, s11Tabs
);
3150 if (attrs
& FILE_ATTRIBUTE_NORMAL
) buffer
[ 0] = 'N';
3152 if (attrs
& FILE_ATTRIBUTE_READONLY
) buffer
[ 2] = 'R';
3153 if (attrs
& FILE_ATTRIBUTE_HIDDEN
) buffer
[ 4] = 'H';
3154 if (attrs
& FILE_ATTRIBUTE_SYSTEM
) buffer
[ 6] = 'S';
3155 if (attrs
& FILE_ATTRIBUTE_ARCHIVE
) buffer
[ 8] = 'A';
3156 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
) buffer
[10] = 'C';
3157 #ifndef _NO_EXTENSIONS
3158 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) buffer
[12] = 'D';
3159 if (attrs
& FILE_ATTRIBUTE_ENCRYPTED
) buffer
[14] = 'E';
3160 if (attrs
& FILE_ATTRIBUTE_TEMPORARY
) buffer
[16] = 'T';
3161 if (attrs
& FILE_ATTRIBUTE_SPARSE_FILE
) buffer
[18] = 'P';
3162 if (attrs
& FILE_ATTRIBUTE_REPARSE_POINT
) buffer
[20] = 'Q';
3163 if (attrs
& FILE_ATTRIBUTE_OFFLINE
) buffer
[22] = 'O';
3164 if (attrs
& FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
) buffer
[24] = 'X';
3165 #endif /* _NO_EXTENSIONS */
3168 if (calcWidthCol
== -1)
3169 output_tabbed_text(pane
, dis
, col
, buffer
);
3170 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3171 calc_tabbed_width(pane
, dis
, col
, buffer
);
3177 if (flags.security) {
3178 const static TCHAR sSecTabs[] = {
3179 ' ','\t',' ','\t',' ','\t',' ',
3181 ' ','\t',' ','\t',' ','\t',' ',
3183 ' ','\t',' ','\t',' ','\t',' ',
3187 DWORD rights = get_access_mask();
3189 tcscpy(buffer, sSecTabs);
3191 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
3192 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
3193 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
3194 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
3195 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
3196 if (rights & FILE_EXECUTE) buffer[12] = 'X';
3197 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
3198 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
3199 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
3200 if (rights & WRITE_DAC) buffer[22] = 'C';
3201 if (rights & WRITE_OWNER) buffer[24] = 'O';
3202 if (rights & SYNCHRONIZE) buffer[26] = 'S';
3204 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
3207 if (flags.description) {
3208 get_description(buffer);
3209 output_text(dis, col++, buffer, 0, psize);
3213 #ifdef _NO_EXTENSIONS
3216 /* draw focus frame */
3217 if ((dis
->itemState
&ODS_FOCUS
) && calcWidthCol
==-1) {
3218 /* Currently [04/2000] Wine neither behaves exactly the same */
3219 /* way as WIN 95 nor like Windows NT... */
3224 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
3225 LOGBRUSH lb
= {PS_SOLID
, RGB(255,255,255)};
3226 hpen
= ExtCreatePen(PS_COSMETIC
|PS_ALTERNATE
, 1, &lb
, 0, 0);
3228 hpen
= CreatePen(PS_DOT
, 0, RGB(255,255,255));
3230 lastPen
= SelectPen(dis
->hDC
, hpen
);
3231 lastBrush
= SelectObject(dis
->hDC
, GetStockObject(HOLLOW_BRUSH
));
3232 SetROP2(dis
->hDC
, R2_XORPEN
);
3233 Rectangle(dis
->hDC
, focusRect
.left
, focusRect
.top
, focusRect
.right
, focusRect
.bottom
);
3234 SelectObject(dis
->hDC
, lastBrush
);
3235 SelectObject(dis
->hDC
, lastPen
);
3238 #endif /* _NO_EXTENSIONS */
3242 #ifdef _NO_EXTENSIONS
3244 static void draw_splitbar(HWND hwnd
, int x
)
3247 HDC hdc
= GetDC(hwnd
);
3249 GetClientRect(hwnd
, &rt
);
3251 rt
.left
= x
- SPLIT_WIDTH
/2;
3252 rt
.right
= x
+ SPLIT_WIDTH
/2+1;
3254 InvertRect(hdc
, &rt
);
3256 ReleaseDC(hwnd
, hdc
);
3259 #endif /* _NO_EXTENSIONS */
3262 #ifndef _NO_EXTENSIONS
3264 static void set_header(Pane
* pane
)
3267 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3270 item
.mask
= HDI_WIDTH
;
3273 for(; x
+pane
->widths
[i
]<scroll_pos
&& i
<COLUMNS
; i
++) {
3274 x
+= pane
->widths
[i
];
3275 Header_SetItem(pane
->hwndHeader
, i
, &item
);
3279 x
+= pane
->widths
[i
];
3280 item
.cxy
= x
- scroll_pos
;
3281 Header_SetItem(pane
->hwndHeader
, i
++, &item
);
3283 for(; i
<COLUMNS
; i
++) {
3284 item
.cxy
= pane
->widths
[i
];
3285 x
+= pane
->widths
[i
];
3286 Header_SetItem(pane
->hwndHeader
, i
, &item
);
3291 static LRESULT
pane_notify(Pane
* pane
, NMHDR
* pnmh
)
3293 switch(pnmh
->code
) {
3295 case HDN_ENDTRACK
: {
3296 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3297 int idx
= phdn
->iItem
;
3298 int dx
= phdn
->pitem
->cxy
- pane
->widths
[idx
];
3302 GetClientRect(pane
->hwnd
, &clnt
);
3304 /* move immediate to simulate HDS_FULLDRAG (for now [04/2000] not really needed with WINELIB) */
3305 Header_SetItem(pane
->hwndHeader
, idx
, phdn
->pitem
);
3307 pane
->widths
[idx
] += dx
;
3309 for(i
=idx
; ++i
<=COLUMNS
; )
3310 pane
->positions
[i
] += dx
;
3313 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3317 rt_scr
.left
= pane
->positions
[idx
+1]-scroll_pos
;
3319 rt_scr
.right
= clnt
.right
;
3320 rt_scr
.bottom
= clnt
.bottom
;
3322 rt_clip
.left
= pane
->positions
[idx
]-scroll_pos
;
3324 rt_clip
.right
= clnt
.right
;
3325 rt_clip
.bottom
= clnt
.bottom
;
3327 if (rt_scr
.left
< 0) rt_scr
.left
= 0;
3328 if (rt_clip
.left
< 0) rt_clip
.left
= 0;
3330 ScrollWindowEx(pane
->hwnd
, dx
, 0, &rt_scr
, &rt_clip
, 0, 0, SW_INVALIDATE
);
3332 rt_clip
.right
= pane
->positions
[idx
+1];
3333 RedrawWindow(pane
->hwnd
, &rt_clip
, 0, RDW_INVALIDATE
|RDW_UPDATENOW
);
3335 if (pnmh
->code
== HDN_ENDTRACK
) {
3336 ListBox_SetHorizontalExtent(pane
->hwnd
, pane
->positions
[COLUMNS
]);
3338 if (GetScrollPos(pane
->hwnd
, SB_HORZ
) != scroll_pos
)
3346 case HDN_DIVIDERDBLCLICK
: {
3347 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3350 calc_single_width(pane
, phdn
->iItem
);
3351 item
.mask
= HDI_WIDTH
;
3352 item
.cxy
= pane
->widths
[phdn
->iItem
];
3354 Header_SetItem(pane
->hwndHeader
, phdn
->iItem
, &item
);
3355 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3362 #endif /* _NO_EXTENSIONS */
3365 static void scan_entry(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3367 TCHAR path
[MAX_PATH
];
3368 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
3370 /* delete sub entries in left pane */
3372 LRESULT res
= ListBox_GetItemData(child
->left
.hwnd
, idx
+1);
3373 Entry
* sub
= (Entry
*) res
;
3375 if (res
==LB_ERR
|| !sub
|| sub
->level
<=entry
->level
)
3378 ListBox_DeleteString(child
->left
.hwnd
, idx
+1);
3381 /* empty right pane */
3382 ListBox_ResetContent(child
->right
.hwnd
);
3384 /* release memory */
3385 free_entries(entry
);
3387 /* read contents from disk */
3388 #ifdef _SHELL_FOLDERS
3389 if (entry
->etype
== ET_SHELL
)
3391 read_directory(entry
, NULL
, child
->sortOrder
, hwnd
);
3396 get_path(entry
, path
);
3397 read_directory(entry
, path
, child
->sortOrder
, hwnd
);
3400 /* insert found entries in right pane */
3401 insert_entries(&child
->right
, entry
->down
, child
->filter_pattern
, child
->filter_flags
, -1);
3402 calc_widths(&child
->right
, FALSE
);
3403 #ifndef _NO_EXTENSIONS
3404 set_header(&child
->right
);
3407 child
->header_wdths_ok
= FALSE
;
3409 SetCursor(old_cursor
);
3413 /* expand a directory entry */
3415 static BOOL
expand_entry(ChildWnd
* child
, Entry
* dir
)
3420 if (!dir
|| dir
->expanded
|| !dir
->down
)
3425 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='\0' && p
->next
) {
3428 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='.' &&
3429 p
->data
.cFileName
[2]=='\0' && p
->next
)
3433 /* no subdirectories ? */
3434 if (!(p
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
3437 idx
= ListBox_FindItemData(child
->left
.hwnd
, 0, dir
);
3439 dir
->expanded
= TRUE
;
3441 /* insert entries in left pane */
3442 insert_entries(&child
->left
, p
, NULL
, TF_ALL
, idx
);
3444 if (!child
->header_wdths_ok
) {
3445 if (calc_widths(&child
->left
, FALSE
)) {
3446 #ifndef _NO_EXTENSIONS
3447 set_header(&child
->left
);
3450 child
->header_wdths_ok
= TRUE
;
3458 static void collapse_entry(Pane
* pane
, Entry
* dir
)
3460 int idx
= ListBox_FindItemData(pane
->hwnd
, 0, dir
);
3462 ShowWindow(pane
->hwnd
, SW_HIDE
);
3464 /* hide sub entries */
3466 LRESULT res
= ListBox_GetItemData(pane
->hwnd
, idx
+1);
3467 Entry
* sub
= (Entry
*) res
;
3469 if (res
==LB_ERR
|| !sub
|| sub
->level
<=dir
->level
)
3472 ListBox_DeleteString(pane
->hwnd
, idx
+1);
3475 dir
->expanded
= FALSE
;
3477 ShowWindow(pane
->hwnd
, SW_SHOW
);
3481 static void refresh_right_pane(ChildWnd
* child
)
3483 ListBox_ResetContent(child
->right
.hwnd
);
3484 insert_entries(&child
->right
, child
->right
.root
, child
->filter_pattern
, child
->filter_flags
, -1);
3485 calc_widths(&child
->right
, FALSE
);
3487 #ifndef _NO_EXTENSIONS
3488 set_header(&child
->right
);
3492 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3494 TCHAR path
[MAX_PATH
];
3498 child
->left
.cur
= entry
;
3500 child
->right
.root
= entry
->down
? entry
->down
: entry
;
3501 child
->right
.cur
= entry
;
3503 if (!entry
->scanned
)
3504 scan_entry(child
, entry
, idx
, hwnd
);
3506 refresh_right_pane(child
);
3508 get_path(entry
, path
);
3509 lstrcpy(child
->path
, path
);
3511 if (child
->hwnd
) /* only change window title, if the window already exists */
3512 SetWindowText(child
->hwnd
, path
);
3515 if (SetCurrentDirectory(path
))
3520 static void refresh_child(ChildWnd
* child
)
3522 TCHAR path
[MAX_PATH
], drv
[_MAX_DRIVE
+1];
3526 get_path(child
->left
.cur
, path
);
3527 _tsplitpath(path
, drv
, NULL
, NULL
, NULL
);
3529 child
->right
.root
= NULL
;
3531 scan_entry(child
, &child
->root
.entry
, 0, child
->hwnd
);
3533 #ifdef _SHELL_FOLDERS
3534 if (child
->root
.entry
.etype
== ET_SHELL
)
3535 entry
= read_tree(&child
->root
, NULL
, get_path_pidl(path
,child
->hwnd
), drv
, child
->sortOrder
, child
->hwnd
);
3538 entry
= read_tree(&child
->root
, path
, NULL
, drv
, child
->sortOrder
, child
->hwnd
);
3541 entry
= &child
->root
.entry
;
3543 insert_entries(&child
->left
, child
->root
.entry
.down
, NULL
, TF_ALL
, 0);
3545 set_curdir(child
, entry
, 0, child
->hwnd
);
3547 idx
= ListBox_FindItemData(child
->left
.hwnd
, 0, child
->left
.cur
);
3548 ListBox_SetCurSel(child
->left
.hwnd
, idx
);
3552 static void create_drive_bar()
3554 TBBUTTON drivebarBtn
= {0, 0, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0};
3555 #ifndef _NO_EXTENSIONS
3556 TCHAR b1
[BUFFER_LEN
];
3561 GetLogicalDriveStrings(BUFFER_LEN
, Globals
.drives
);
3563 Globals
.hdrivebar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
,
3564 IDW_DRIVEBAR
, 2, Globals
.hInstance
, IDB_DRIVEBAR
, &drivebarBtn
,
3565 1, 16, 13, 16, 13, sizeof(TBBUTTON
));
3567 #ifndef _NO_EXTENSIONS
3569 /* insert unix file system button */
3573 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
3575 drivebarBtn
.idCommand
= ID_DRIVE_UNIX_FS
;
3576 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3577 drivebarBtn
.iString
++;
3579 #ifdef _SHELL_FOLDERS
3580 /* insert shell namespace button */
3581 load_string(b1
, IDS_SHELL
);
3582 b1
[lstrlen(b1
)+1] = '\0';
3583 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
3585 drivebarBtn
.idCommand
= ID_DRIVE_SHELL_NS
;
3586 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3587 drivebarBtn
.iString
++;
3590 /* register windows drive root strings */
3591 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)Globals
.drives
);
3594 drivebarBtn
.idCommand
= ID_DRIVE_FIRST
;
3596 for(p
=Globals
.drives
; *p
; ) {
3597 #ifdef _NO_EXTENSIONS
3598 /* insert drive letter */
3599 TCHAR b
[3] = {tolower(*p
)};
3600 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b
);
3602 switch(GetDriveType(p
)) {
3603 case DRIVE_REMOVABLE
: drivebarBtn
.iBitmap
= 1; break;
3604 case DRIVE_CDROM
: drivebarBtn
.iBitmap
= 3; break;
3605 case DRIVE_REMOTE
: drivebarBtn
.iBitmap
= 4; break;
3606 case DRIVE_RAMDISK
: drivebarBtn
.iBitmap
= 5; break;
3607 default:/*DRIVE_FIXED*/ drivebarBtn
.iBitmap
= 2;
3610 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3611 drivebarBtn
.idCommand
++;
3612 drivebarBtn
.iString
++;
3618 static void refresh_drives()
3622 /* destroy drive bar */
3623 DestroyWindow(Globals
.hdrivebar
);
3624 Globals
.hdrivebar
= 0;
3626 /* re-create drive bar */
3629 /* update window layout */
3630 GetClientRect(Globals
.hMainWnd
, &rect
);
3631 SendMessage(Globals
.hMainWnd
, WM_SIZE
, 0, MAKELONG(rect
.right
, rect
.bottom
));
3635 BOOL
launch_file(HWND hwnd
, LPCTSTR cmd
, UINT nCmdShow
)
3637 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3639 if ((int)hinst
<= 32) {
3640 display_error(hwnd
, GetLastError());
3648 BOOL
launch_fileA(HWND hwnd
, LPSTR cmd
, UINT nCmdShow
)
3650 HINSTANCE hinst
= ShellExecuteA(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3652 if ((int)hinst
<= 32) {
3653 display_error(hwnd
, GetLastError());
3662 BOOL
launch_entry(Entry
* entry
, HWND hwnd
, UINT nCmdShow
)
3664 TCHAR cmd
[MAX_PATH
];
3666 #ifdef _SHELL_FOLDERS
3667 if (entry
->etype
== ET_SHELL
) {
3670 SHELLEXECUTEINFO shexinfo
;
3672 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFO
);
3673 shexinfo
.fMask
= SEE_MASK_IDLIST
;
3674 shexinfo
.hwnd
= hwnd
;
3675 shexinfo
.lpVerb
= NULL
;
3676 shexinfo
.lpFile
= NULL
;
3677 shexinfo
.lpParameters
= NULL
;
3678 shexinfo
.lpDirectory
= NULL
;
3679 shexinfo
.nShow
= nCmdShow
;
3680 shexinfo
.lpIDList
= get_to_absolute_pidl(entry
, hwnd
);
3682 if (!ShellExecuteEx(&shexinfo
)) {
3683 display_error(hwnd
, GetLastError());
3687 if (shexinfo
.lpIDList
!= entry
->pidl
)
3688 (*Globals
.iMalloc
->lpVtbl
->Free
)(Globals
.iMalloc
, shexinfo
.lpIDList
);
3694 get_path(entry
, cmd
);
3696 /* start program, open document... */
3697 return launch_file(hwnd
, cmd
, nCmdShow
);
3701 static void activate_entry(ChildWnd
* child
, Pane
* pane
, HWND hwnd
)
3703 Entry
* entry
= pane
->cur
;
3708 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
3709 int scanned_old
= entry
->scanned
;
3712 scan_entry(child
, entry
, ListBox_GetCurSel(child
->left
.hwnd
), hwnd
);
3714 #ifndef _NO_EXTENSIONS
3715 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='\0')
3719 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='.' && entry
->data
.cFileName
[2]=='\0') {
3720 entry
= child
->left
.cur
->up
;
3721 collapse_entry(&child
->left
, entry
);
3723 } else if (entry
->expanded
)
3724 collapse_entry(pane
, child
->left
.cur
);
3726 expand_entry(child
, child
->left
.cur
);
3728 if (!pane
->treePane
) focus_entry
: {
3729 int idx
= ListBox_FindItemData(child
->left
.hwnd
, ListBox_GetCurSel(child
->left
.hwnd
), entry
);
3730 ListBox_SetCurSel(child
->left
.hwnd
, idx
);
3731 set_curdir(child
, entry
, idx
, hwnd
);
3736 calc_widths(pane
, FALSE
);
3738 #ifndef _NO_EXTENSIONS
3743 launch_entry(entry
, child
->hwnd
, SW_SHOWNORMAL
);
3748 static BOOL
pane_command(Pane
* pane
, UINT cmd
)
3752 if (pane
->visible_cols
) {
3753 pane
->visible_cols
= 0;
3754 calc_widths(pane
, TRUE
);
3755 #ifndef _NO_EXTENSIONS
3758 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3759 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
|MF_CHECKED
);
3760 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
);
3761 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
3765 case ID_VIEW_ALL_ATTRIBUTES
:
3766 if (pane
->visible_cols
!= COL_ALL
) {
3767 pane
->visible_cols
= COL_ALL
;
3768 calc_widths(pane
, TRUE
);
3769 #ifndef _NO_EXTENSIONS
3772 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3773 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
);
3774 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
|MF_CHECKED
);
3775 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
3779 #ifndef _NO_EXTENSIONS
3780 case ID_PREFERRED_SIZES
: {
3781 calc_widths(pane
, TRUE
);
3783 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3787 /* TODO: more command ids... */
3797 static void set_sort_order(ChildWnd
* child
, SORT_ORDER sortOrder
)
3799 if (child
->sortOrder
!= sortOrder
) {
3800 child
->sortOrder
= sortOrder
;
3801 refresh_child(child
);
3805 static void update_view_menu(ChildWnd
* child
)
3807 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_NAME
, child
->sortOrder
==SORT_NAME
? MF_CHECKED
: MF_UNCHECKED
);
3808 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_TYPE
, child
->sortOrder
==SORT_EXT
? MF_CHECKED
: MF_UNCHECKED
);
3809 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_SIZE
, child
->sortOrder
==SORT_SIZE
? MF_CHECKED
: MF_UNCHECKED
);
3810 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_DATE
, child
->sortOrder
==SORT_DATE
? MF_CHECKED
: MF_UNCHECKED
);
3815 static BOOL
is_directory(LPCTSTR target
)
3817 /*TODO correctly handle UNIX paths */
3818 DWORD target_attr
= GetFileAttributes(target
);
3820 if (target_attr
== INVALID_FILE_ATTRIBUTES
)
3823 return target_attr
&FILE_ATTRIBUTE_DIRECTORY
? TRUE
: FALSE
;
3826 static BOOL
prompt_target(Pane
* pane
, LPTSTR source
, LPTSTR target
)
3828 TCHAR path
[MAX_PATH
];
3831 get_path(pane
->cur
, path
);
3833 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_SELECT_DESTINATION
), pane
->hwnd
, DestinationDlgProc
, (LPARAM
)path
) != IDOK
)
3836 get_path(pane
->cur
, source
);
3838 /* convert relative targets to absolute paths */
3839 if (path
[0]!='/' && path
[1]!=':') {
3840 get_path(pane
->cur
->up
, target
);
3841 len
= lstrlen(target
);
3843 if (target
[len
-1]!='\\' && target
[len
-1]!='/')
3844 target
[len
++] = '/';
3846 lstrcpy(target
+len
, path
);
3849 /* If the target already exists as directory, create a new target below this. */
3850 if (is_directory(path
)) {
3851 TCHAR fname
[_MAX_FNAME
], ext
[_MAX_EXT
];
3852 const static TCHAR sAppend
[] = {'%','s','/','%','s','%','s','\0'};
3854 _tsplitpath(source
, NULL
, NULL
, fname
, ext
);
3856 wsprintf(target
, sAppend
, path
, fname
, ext
);
3858 lstrcpy(target
, path
);
3864 static IContextMenu2
* s_pctxmenu2
= NULL
;
3866 #ifndef __MINGW32__ /* IContextMenu3 missing in MinGW (as of 6.2.2005) */
3867 static IContextMenu3
* s_pctxmenu3
= NULL
;
3870 static void CtxMenu_reset()
3874 #ifndef __MINGW32__ /* IContextMenu3 missing in MinGW (as of 6.2.2005) */
3879 IContextMenu
* CtxMenu_query_interfaces(IContextMenu
* pcm1
)
3881 IContextMenu
* pcm
= NULL
;
3885 #ifndef __MINGW32__ /* IContextMenu3 missing in MinGW (as of 6.2.2005) */
3886 if ((*pcm1
->lpVtbl
->QueryInterface
)(pcm1
, &IID_IContextMenu3
, (void**)&pcm
) == NOERROR
)
3887 s_pctxmenu3
= (LPCONTEXTMENU3
)pcm
;
3890 if ((*pcm1
->lpVtbl
->QueryInterface
)(pcm1
, &IID_IContextMenu2
, (void**)&pcm
) == NOERROR
)
3891 s_pctxmenu2
= (LPCONTEXTMENU2
)pcm
;
3894 (*pcm1
->lpVtbl
->Release
)(pcm1
);
3900 static BOOL
CtxMenu_HandleMenuMsg(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3902 #ifndef __MINGW32__ /* IContextMenu3 missing in MinGW (as of 6.2.2005) */
3904 if (SUCCEEDED((*s_pctxmenu3
->lpVtbl
->HandleMenuMsg
)(s_pctxmenu3
, nmsg
, wparam
, lparam
)))
3910 if (SUCCEEDED((*s_pctxmenu2
->lpVtbl
->HandleMenuMsg
)(s_pctxmenu2
, nmsg
, wparam
, lparam
)))
3917 static HRESULT
ShellFolderContextMenu(IShellFolder
* shell_folder
, HWND hwndParent
, int cidl
, LPCITEMIDLIST
* apidl
, int x
, int y
)
3921 HRESULT hr
= (*shell_folder
->lpVtbl
->GetUIObjectOf
)(shell_folder
, hwndParent
, cidl
, apidl
, &IID_IContextMenu
, NULL
, (LPVOID
*)&pcm
);
3922 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
3924 if (SUCCEEDED(hr
)) {
3925 HMENU hmenu
= CreatePopupMenu();
3927 pcm
= CtxMenu_query_interfaces(pcm
);
3930 hr
= (*pcm
->lpVtbl
->QueryContextMenu
)(pcm
, hmenu
, 0, FCIDM_SHVIEWFIRST
, FCIDM_SHVIEWLAST
, CMF_NORMAL
);
3932 if (SUCCEEDED(hr
)) {
3933 UINT idCmd
= TrackPopupMenu(hmenu
, TPM_LEFTALIGN
|TPM_RETURNCMD
|TPM_RIGHTBUTTON
, x
, y
, 0, hwndParent
, NULL
);
3938 CMINVOKECOMMANDINFO cmi
;
3940 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFO
);
3942 cmi
.hwnd
= hwndParent
;
3943 cmi
.lpVerb
= (LPCSTR
)(INT_PTR
)(idCmd
- FCIDM_SHVIEWFIRST
);
3944 cmi
.lpParameters
= NULL
;
3945 cmi
.lpDirectory
= NULL
;
3946 cmi
.nShow
= SW_SHOWNORMAL
;
3950 hr
= (*pcm
->lpVtbl
->InvokeCommand
)(pcm
, &cmi
);
3956 (*pcm
->lpVtbl
->Release
)(pcm
);
3963 static DWORD CALLBACK
CopyProgressRoutine(
3964 LARGE_INTEGER TotalFileSize
,
3965 LARGE_INTEGER TotalBytesTransferred
,
3966 LARGE_INTEGER StreamSize
,
3967 LARGE_INTEGER StreamBytesTransferred
,
3968 DWORD dwStreamNumber
,
3969 DWORD dwCallbackReason
,
3971 HANDLE hDestinationFile
,
3975 return PROGRESS_CONTINUE
;
3979 LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3981 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(hwnd
, GWL_USERDATA
);
3986 LPDRAWITEMSTRUCT dis
= (LPDRAWITEMSTRUCT
)lparam
;
3987 Entry
* entry
= (Entry
*) dis
->itemData
;
3989 if (dis
->CtlID
== IDW_TREE_LEFT
)
3990 draw_item(&child
->left
, dis
, entry
, -1);
3991 else if (dis
->CtlID
== IDW_TREE_RIGHT
)
3992 draw_item(&child
->right
, dis
, entry
, -1);
3994 goto draw_menu_item
;
3999 InitChildWindow(child
);
4003 free_child_window(child
);
4004 SetWindowLong(hwnd
, GWL_USERDATA
, 0);
4011 GetClientRect(hwnd
, &rt
);
4012 BeginPaint(hwnd
, &ps
);
4013 rt
.left
= child
->split_pos
-SPLIT_WIDTH
/2;
4014 rt
.right
= child
->split_pos
+SPLIT_WIDTH
/2+1;
4015 lastBrush
= SelectBrush(ps
.hdc
, (HBRUSH
)GetStockObject(COLOR_SPLITBAR
));
4016 Rectangle(ps
.hdc
, rt
.left
, rt
.top
-1, rt
.right
, rt
.bottom
+1);
4017 SelectObject(ps
.hdc
, lastBrush
);
4018 #ifdef _NO_EXTENSIONS
4019 rt
.top
= rt
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
4020 FillRect(ps
.hdc
, &rt
, GetStockObject(BLACK_BRUSH
));
4022 EndPaint(hwnd
, &ps
);
4026 if (LOWORD(lparam
) == HTCLIENT
) {
4029 ScreenToClient(hwnd
, &pt
);
4031 if (pt
.x
>=child
->split_pos
-SPLIT_WIDTH
/2 && pt
.x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
4032 SetCursor(LoadCursor(0, IDC_SIZEWE
));
4038 case WM_LBUTTONDOWN
: {
4040 int x
= GET_X_LPARAM(lparam
);
4042 GetClientRect(hwnd
, &rt
);
4044 if (x
>=child
->split_pos
-SPLIT_WIDTH
/2 && x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
4045 last_split
= child
->split_pos
;
4046 #ifdef _NO_EXTENSIONS
4047 draw_splitbar(hwnd
, last_split
);
4055 if (GetCapture() == hwnd
) {
4056 #ifdef _NO_EXTENSIONS
4058 int x
= LOWORD(lparam
);
4059 draw_splitbar(hwnd
, last_split
);
4061 GetClientRect(hwnd
, &rt
);
4062 child
->split_pos
= x
;
4063 resize_tree(child
, rt
.right
, rt
.bottom
);
4069 #ifdef _NO_EXTENSIONS
4070 case WM_CAPTURECHANGED
:
4071 if (GetCapture()==hwnd
&& last_split
>=0)
4072 draw_splitbar(hwnd
, last_split
);
4077 if (wparam
== VK_ESCAPE
)
4078 if (GetCapture() == hwnd
) {
4080 #ifdef _NO_EXTENSIONS
4081 draw_splitbar(hwnd
, last_split
);
4083 child
->split_pos
= last_split
;
4085 GetClientRect(hwnd
, &rt
);
4086 resize_tree(child
, rt
.right
, rt
.bottom
);
4089 SetCursor(LoadCursor(0, IDC_ARROW
));
4094 if (GetCapture() == hwnd
) {
4096 int x
= LOWORD(lparam
);
4098 #ifdef _NO_EXTENSIONS
4099 HDC hdc
= GetDC(hwnd
);
4100 GetClientRect(hwnd
, &rt
);
4102 rt
.left
= last_split
-SPLIT_WIDTH
/2;
4103 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
4104 InvertRect(hdc
, &rt
);
4107 rt
.left
= x
-SPLIT_WIDTH
/2;
4108 rt
.right
= x
+SPLIT_WIDTH
/2+1;
4109 InvertRect(hdc
, &rt
);
4111 ReleaseDC(hwnd
, hdc
);
4113 GetClientRect(hwnd
, &rt
);
4115 if (x
>=0 && x
<rt
.right
) {
4116 child
->split_pos
= x
;
4117 resize_tree(child
, rt
.right
, rt
.bottom
);
4118 rt
.left
= x
-SPLIT_WIDTH
/2;
4119 rt
.right
= x
+SPLIT_WIDTH
/2+1;
4120 InvalidateRect(hwnd
, &rt
, FALSE
);
4121 UpdateWindow(child
->left
.hwnd
);
4123 UpdateWindow(child
->right
.hwnd
);
4129 #ifndef _NO_EXTENSIONS
4130 case WM_GETMINMAXINFO
:
4131 DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
4133 {LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
4135 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
4136 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
4138 #endif /* _NO_EXTENSIONS */
4141 if (SetCurrentDirectory(child
->path
))
4143 SetFocus(child
->focus_pane
? child
->right
.hwnd
: child
->left
.hwnd
);
4146 case WM_DISPATCH_COMMAND
: {
4147 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4149 switch(LOWORD(wparam
)) {
4150 case ID_WINDOW_NEW
: {
4151 ChildWnd
* new_child
= alloc_child_window(child
->path
, NULL
, hwnd
);
4153 if (!create_child_window(new_child
))
4160 refresh_child(child
);
4164 activate_entry(child
, pane
, hwnd
);
4167 case ID_FILE_MOVE
: {
4168 TCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
4170 if (prompt_target(pane
, source
, target
)) {
4171 /*TODO handle moving of directory trees
4172 if (is_directory(source) && drive_from_path(source)!=drive_from_path(target))
4175 if (MoveFileWithProgress(source
, target
, CopyProgressRoutine
, NULL
, MOVEFILE_COPY_ALLOWED
))
4176 refresh_child(child
);
4178 display_error(hwnd
, GetLastError());
4182 case ID_FILE_COPY
: {
4183 TCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
4185 if (prompt_target(pane
, source
, target
)) {
4186 /*TODO handle copying of directory trees
4187 if (is_directory(source))
4190 if (CopyFileEx(source
, target
, CopyProgressRoutine
, NULL
, NULL
, COPY_FILE_RESTARTABLE
|COPY_FILE_ALLOW_DECRYPTED_DESTINATION
))
4191 refresh_child(child
);
4193 display_error(hwnd
, GetLastError());
4197 case ID_VIEW_SORT_NAME
:
4198 set_sort_order(child
, SORT_NAME
);
4201 case ID_VIEW_SORT_TYPE
:
4202 set_sort_order(child
, SORT_EXT
);
4205 case ID_VIEW_SORT_SIZE
:
4206 set_sort_order(child
, SORT_SIZE
);
4209 case ID_VIEW_SORT_DATE
:
4210 set_sort_order(child
, SORT_DATE
);
4213 case ID_VIEW_FILTER
: {
4214 struct FilterDialog dlg
;
4216 memset(&dlg
, 0, sizeof(struct FilterDialog
));
4217 _tcscpy(dlg
.pattern
, child
->filter_pattern
);
4218 dlg
.flags
= child
->filter_flags
;
4220 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE
), hwnd
, FilterDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
4221 _tcscpy(child
->filter_pattern
, dlg
.pattern
);
4222 child
->filter_flags
= dlg
.flags
;
4223 refresh_right_pane(child
);
4227 case ID_VIEW_SPLIT
: {
4228 last_split
= child
->split_pos
;
4229 #ifdef _NO_EXTENSIONS
4230 draw_splitbar(hwnd
, last_split
);
4236 return pane_command(pane
, LOWORD(wparam
));
4242 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4244 switch(HIWORD(wparam
)) {
4245 case LBN_SELCHANGE
: {
4246 int idx
= ListBox_GetCurSel(pane
->hwnd
);
4247 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, idx
);
4249 if (pane
== &child
->left
)
4250 set_curdir(child
, entry
, idx
, hwnd
);
4256 activate_entry(child
, pane
, hwnd
);
4261 #ifndef _NO_EXTENSIONS
4263 NMHDR
* pnmh
= (NMHDR
*) lparam
;
4264 return pane_notify(pnmh
->idFrom
==IDW_HEADER_LEFT
? &child
->left
: &child
->right
, pnmh
);}
4267 #ifdef _SHELL_FOLDERS
4268 case WM_CONTEXTMENU
: {
4273 /* first select the current item in the listbox */
4274 HWND hpanel
= (HWND
) wparam
;
4275 pt_clnt
.x
= pt
.x
= (short)LOWORD(lparam
);
4276 pt_clnt
.y
= pt
.y
= (short)HIWORD(lparam
);
4277 ScreenToClient(hpanel
, &pt_clnt
);
4278 SendMessage(hpanel
, WM_LBUTTONDOWN
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4279 SendMessage(hpanel
, WM_LBUTTONUP
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4281 /* now create the popup menu using shell namespace and IContextMenu */
4282 pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4283 idx
= ListBox_GetCurSel(pane
->hwnd
);
4286 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, idx
);
4288 LPITEMIDLIST pidl_abs
= get_to_absolute_pidl(entry
, hwnd
);
4291 IShellFolder
* parentFolder
;
4292 LPCITEMIDLIST pidlLast
;
4294 /* get and use the parent folder to display correct context menu in all cases */
4295 if (SUCCEEDED(SHBindToParent(pidl_abs
, &IID_IShellFolder
, (LPVOID
*)&parentFolder
, &pidlLast
))) {
4296 if (SUCCEEDED(ShellFolderContextMenu(parentFolder
, hwnd
, 1, &pidlLast
, pt
.x
, pt
.y
)))
4297 refresh_child(child
);
4299 (*parentFolder
->lpVtbl
->Release
)(parentFolder
);
4302 (*Globals
.iMalloc
->lpVtbl
->Free
)(Globals
.iMalloc
, pidl_abs
);
4308 case WM_MEASUREITEM
:
4310 if (!wparam
) /* Is the message menu-related? */
4311 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4316 case WM_INITMENUPOPUP
:
4317 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4320 update_view_menu(child
);
4323 #ifndef __MINGW32__ /* IContextMenu3 missing in MinGW (as of 6.2.2005) */
4324 case WM_MENUCHAR
: /* only supported by IContextMenu3 */
4326 LRESULT lResult
= 0;
4328 (*s_pctxmenu3
->lpVtbl
->HandleMenuMsg2
)(s_pctxmenu3
, nmsg
, wparam
, lparam
, &lResult
);
4337 if (wparam
!= SIZE_MINIMIZED
)
4338 resize_tree(child
, LOWORD(lparam
), HIWORD(lparam
));
4342 return DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
4349 LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4351 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(GetParent(hwnd
), GWL_USERDATA
);
4352 Pane
* pane
= (Pane
*) GetWindowLong(hwnd
, GWL_USERDATA
);
4356 #ifndef _NO_EXTENSIONS
4363 child
->focus_pane
= pane
==&child
->right
? 1: 0;
4364 ListBox_SetSel(hwnd
, TRUE
, 1);
4365 /*TODO: check menu items */
4369 if (wparam
== VK_TAB
) {
4370 /*TODO: SetFocus(Globals.hdrivebar) */
4371 SetFocus(child
->focus_pane
? child
->left
.hwnd
: child
->right
.hwnd
);
4375 return CallWindowProc(g_orgTreeWndProc
, hwnd
, nmsg
, wparam
, lparam
);
4379 static void InitInstance(HINSTANCE hinstance
)
4381 const static TCHAR sFont
[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4388 INITCOMMONCONTROLSEX icc
= {
4389 sizeof(INITCOMMONCONTROLSEX
),
4395 setlocale(LC_COLLATE
, ""); /* set collating rules to local settings for compareName */
4397 InitCommonControlsEx(&icc
);
4400 /* register frame window class */
4402 wcFrame
.cbSize
= sizeof(WNDCLASSEX
);
4404 wcFrame
.lpfnWndProc
= FrameWndProc
;
4405 wcFrame
.cbClsExtra
= 0;
4406 wcFrame
.cbWndExtra
= 0;
4407 wcFrame
.hInstance
= hinstance
;
4408 wcFrame
.hIcon
= LoadIcon(hinstance
, MAKEINTRESOURCE(IDI_WINEFILE
));
4409 wcFrame
.hCursor
= LoadCursor(0, IDC_ARROW
);
4410 wcFrame
.hbrBackground
= 0;
4411 wcFrame
.lpszMenuName
= 0;
4412 wcFrame
.lpszClassName
= sWINEFILEFRAME
;
4413 wcFrame
.hIconSm
= (HICON
)LoadImage(hinstance
,
4414 MAKEINTRESOURCE(IDI_WINEFILE
),
4416 GetSystemMetrics(SM_CXSMICON
),
4417 GetSystemMetrics(SM_CYSMICON
),
4420 Globals
.hframeClass
= RegisterClassEx(&wcFrame
);
4423 /* register tree windows class */
4425 wcChild
.style
= CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
;
4426 wcChild
.lpfnWndProc
= ChildWndProc
;
4427 wcChild
.cbClsExtra
= 0;
4428 wcChild
.cbWndExtra
= 0;
4429 wcChild
.hInstance
= hinstance
;
4431 wcChild
.hCursor
= LoadCursor(0, IDC_ARROW
);
4432 wcChild
.hbrBackground
= 0;
4433 wcChild
.lpszMenuName
= 0;
4434 wcChild
.lpszClassName
= sWINEFILETREE
;
4436 hChildClass
= RegisterClass(&wcChild
);
4439 Globals
.haccel
= LoadAccelerators(hinstance
, MAKEINTRESOURCE(IDA_WINEFILE
));
4441 Globals
.hfont
= CreateFont(-MulDiv(8,GetDeviceCaps(hdc
,LOGPIXELSY
),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont
);
4445 Globals
.hInstance
= hinstance
;
4447 #ifdef _SHELL_FOLDERS
4449 CoGetMalloc(MEMCTX_TASK
, &Globals
.iMalloc
);
4450 SHGetDesktopFolder(&Globals
.iDesktop
);
4452 Globals
.cfStrFName
= RegisterClipboardFormatA(CFSTR_FILENAME
);
4454 Globals
.cfStrFName
= RegisterClipboardFormat(CFSTR_FILENAME
);
4458 /* load column strings */
4461 load_string(g_pos_names
[col
++], IDS_COL_NAME
);
4462 load_string(g_pos_names
[col
++], IDS_COL_SIZE
);
4463 load_string(g_pos_names
[col
++], IDS_COL_CDATE
);
4464 #ifndef _NO_EXTENSIONS
4465 load_string(g_pos_names
[col
++], IDS_COL_ADATE
);
4466 load_string(g_pos_names
[col
++], IDS_COL_MDATE
);
4467 load_string(g_pos_names
[col
++], IDS_COL_IDX
);
4468 load_string(g_pos_names
[col
++], IDS_COL_LINKS
);
4470 load_string(g_pos_names
[col
++], IDS_COL_ATTR
);
4471 #ifndef _NO_EXTENSIONS
4472 load_string(g_pos_names
[col
++], IDS_COL_SEC
);
4477 void show_frame(HWND hwndParent
, int cmdshow
)
4479 const static TCHAR sMDICLIENT
[] = {'M','D','I','C','L','I','E','N','T','\0'};
4481 TCHAR path
[MAX_PATH
], b1
[BUFFER_LEN
];
4483 HMENU hMenuFrame
, hMenuWindow
;
4485 CLIENTCREATESTRUCT ccs
;
4487 if (Globals
.hMainWnd
)
4490 Globals
.hwndParent
= hwndParent
;
4492 hMenuFrame
= LoadMenu(Globals
.hInstance
, MAKEINTRESOURCE(IDM_WINEFILE
));
4493 hMenuWindow
= GetSubMenu(hMenuFrame
, GetMenuItemCount(hMenuFrame
)-2);
4495 Globals
.hMenuFrame
= hMenuFrame
;
4496 Globals
.hMenuView
= GetSubMenu(hMenuFrame
, 3);
4497 Globals
.hMenuOptions
= GetSubMenu(hMenuFrame
, 4);
4499 ccs
.hWindowMenu
= hMenuWindow
;
4500 ccs
.idFirstChild
= IDW_FIRST_CHILD
;
4503 /* create main window */
4504 Globals
.hMainWnd
= CreateWindowEx(0, (LPCTSTR
)(int)Globals
.hframeClass
, RS(b1
,IDS_WINE_FILE
), WS_OVERLAPPEDWINDOW
,
4505 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
4506 hwndParent
, Globals
.hMenuFrame
, Globals
.hInstance
, 0/*lpParam*/);
4509 Globals
.hmdiclient
= CreateWindowEx(0, sMDICLIENT
, NULL
,
4510 WS_CHILD
|WS_CLIPCHILDREN
|WS_VSCROLL
|WS_HSCROLL
|WS_VISIBLE
|WS_BORDER
,
4512 Globals
.hMainWnd
, 0, Globals
.hInstance
, &ccs
);
4515 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_DRIVE_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4520 TBBUTTON toolbarBtns
[] = {
4521 {0, 0, 0, BTNS_SEP
, {0, 0}, 0, 0},
4522 {0, ID_WINDOW_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4523 {1, ID_WINDOW_CASCADE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4524 {2, ID_WINDOW_TILE_HORZ
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4525 {3, ID_WINDOW_TILE_VERT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4527 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4528 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4531 Globals
.htoolbar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
,
4532 IDW_TOOLBAR
, 2, Globals
.hInstance
, IDB_TOOLBAR
, toolbarBtns
,
4533 sizeof(toolbarBtns
)/sizeof(TBBUTTON
), 16, 15, 16, 15, sizeof(TBBUTTON
));
4534 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_TOOL_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4537 Globals
.hstatusbar
= CreateStatusWindow(WS_CHILD
|WS_VISIBLE
, 0, Globals
.hMainWnd
, IDW_STATUSBAR
);
4538 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
4540 /* CreateStatusWindow does not accept WS_BORDER
4541 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
4542 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
4543 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
4545 /*TODO: read paths and window placements from registry */
4546 GetCurrentDirectory(MAX_PATH
, path
);
4548 ShowWindow(Globals
.hMainWnd
, cmdshow
);
4550 //#if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4551 // // Shell Namespace as default:
4552 // child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
4554 child
= alloc_child_window(path
, NULL
, Globals
.hMainWnd
);
4557 child
->pos
.showCmd
= SW_SHOWMAXIMIZED
;
4558 child
->pos
.rcNormalPosition
.left
= 0;
4559 child
->pos
.rcNormalPosition
.top
= 0;
4560 child
->pos
.rcNormalPosition
.right
= 320;
4561 child
->pos
.rcNormalPosition
.bottom
= 280;
4563 if (!create_child_window(child
))
4566 SetWindowPlacement(child
->hwnd
, &child
->pos
);
4568 Globals
.himl
= ImageList_LoadBitmap(Globals
.hInstance
, MAKEINTRESOURCE(IDB_IMAGES
), 16, 0, RGB(0,255,0));
4570 Globals
.prescan_node
= FALSE
;
4572 UpdateWindow(Globals
.hMainWnd
);
4577 #ifdef _SHELL_FOLDERS
4578 (*Globals
.iDesktop
->lpVtbl
->Release
)(Globals
.iDesktop
);
4579 (*Globals
.iMalloc
->lpVtbl
->Release
)(Globals
.iMalloc
);
4583 ImageList_Destroy(Globals
.himl
);
4587 /* search for already running win[e]files */
4589 static int g_foundPrevInstance
= 0;
4591 static BOOL CALLBACK
EnumWndProc(HWND hwnd
, LPARAM lparam
)
4595 GetClassName(hwnd
, cls
, 128);
4597 if (!lstrcmp(cls
, (LPCTSTR
)lparam
)) {
4598 g_foundPrevInstance
++;
4605 /* search for window of given class name to allow only one running instance */
4606 int find_window_class(LPCTSTR classname
)
4608 EnumWindows(EnumWndProc
, (LPARAM
)classname
);
4610 if (g_foundPrevInstance
)
4617 int winefile_main(HINSTANCE hinstance
, HWND hwndParent
, int cmdshow
)
4621 InitInstance(hinstance
);
4623 if (cmdshow
== SW_SHOWNORMAL
)
4624 /*TODO: read window placement from registry */
4625 cmdshow
= SW_MAXIMIZE
;
4627 show_frame(hwndParent
, cmdshow
);
4629 while(GetMessage(&msg
, 0, 0, 0)) {
4630 if (Globals
.hmdiclient
&& TranslateMDISysAccel(Globals
.hmdiclient
, &msg
))
4633 if (Globals
.hMainWnd
&& TranslateAccelerator(Globals
.hMainWnd
, Globals
.haccel
, &msg
))
4636 TranslateMessage(&msg
);
4637 DispatchMessage(&msg
);
4646 int APIENTRY
WinMain(HINSTANCE hinstance
,
4647 HINSTANCE previnstance
,
4651 #ifdef _NO_EXTENSIONS
4652 if (find_window_class(sWINEFILEFRAME
))
4656 winefile_main(hinstance
, 0, cmdshow
);