4 * Copyright 2000, 2003, 2004, 2005 Martin Fuchs
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #define _MAX_FNAME 256
33 #define _MAX_DIR _MAX_FNAME
34 #define _MAX_EXT _MAX_FNAME
38 #ifdef NONAMELESSUNION
39 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
41 #define UNION_MEMBER(x) x
46 #define DEFAULT_SPLIT_POS 300
48 #define DEFAULT_SPLIT_POS 200
60 typedef struct _Entry
{
71 #ifndef _NO_EXTENSIONS
72 BY_HANDLE_FILE_INFORMATION bhfi
;
74 enum ENTRY_TYPE etype
;
86 TCHAR volname
[_MAX_FNAME
];
96 COL_ATTRIBUTES
= 0x08,
99 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
103 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
|COL_INDEX
|COL_LINKS
116 #ifndef _NO_EXTENSIONS
120 #ifndef _NO_EXTENSIONS
126 int positions
[COLUMNS
+1];
138 int focus_pane
; /* 0: left 1: right */
141 BOOL header_wdths_ok
;
143 TCHAR path
[MAX_PATH
];
146 SORT_ORDER sortOrder
;
150 extern void WineLicense(HWND hwnd
);
151 extern void WineWarranty(HWND hwnd
);
156 /* functions in unixcalls.c */
158 extern void call_getcwd(char* buffer
, size_t len
);
159 extern void* call_opendir(const char* path
);
160 extern int call_readdir(void* pdir
, char* name
, unsigned* pinode
);
161 extern void call_closedir(void* pdir
);
163 extern int call_stat(
164 const char* path
, int* pis_dir
,
165 unsigned long* psize_low
, unsigned long* psize_high
,
166 time_t* patime
, time_t* pmtime
,
167 unsigned long* plinks
170 /* call vswprintf() in msvcrt.dll */
171 int swprintf(wchar_t* buffer
, const wchar_t* fmt
, ...)
173 static int (__cdecl
*vswprintf
)(wchar_t*, const wchar_t*, va_list);
179 HMODULE hmod
= LoadLibraryA("msvcrt");
180 vswprintf
= (int(__cdecl
*)(wchar_t*,const wchar_t*,va_list)) GetProcAddress(hmod
, "vswprintf");
184 ret
= vswprintf(buffer
, fmt
, ap
);
193 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
);
194 static void set_curdir(ChildWnd
* child
, Entry
* entry
, HWND hwnd
);
195 static void get_path(Entry
* dir
, PTSTR path
);
197 LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
198 LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
199 LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
203 WINEFILE_GLOBALS Globals
;
206 /* some common string constants */
207 const static TCHAR sEmpty
[] = {'\0'};
208 const static TCHAR sSpace
[] = {' ', '\0'};
209 const static TCHAR sNumFmt
[] = {'%','d','\0'};
210 const static TCHAR sQMarks
[] = {'?','?','?','\0'};
212 /* window class names */
213 const static TCHAR sWINEFILEFRAME
[] = {'W','F','S','_','F','r','a','m','e','\0'};
214 const static TCHAR sWINEFILETREE
[] = {'W','F','S','_','T','r','e','e','\0'};
217 /* #define LONGLONGARG _T("I64") */
218 const static TCHAR sLongHexFmt
[] = {'%','I','6','4','X','\0'};
219 const static TCHAR sLongNumFmt
[] = {'%','I','6','4','d','\0'};
221 /* #define LONGLONGARG _T("L") */
222 const static TCHAR sLongHexFmt
[] = {'%','L','X','\0'};
223 const static TCHAR sLongNumFmt
[] = {'%','L','d','\0'};
227 /* load resource string */
228 static LPTSTR
load_string(LPTSTR buffer
, UINT id
)
230 LoadString(Globals
.hInstance
, id
, buffer
, BUFFER_LEN
);
235 #define RS(b, i) load_string(b, i)
238 /* display error message for the specified WIN32 error code */
239 static void display_error(HWND hwnd
, DWORD error
)
241 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
244 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_FROM_SYSTEM
,
245 0, error
, MAKELANGID(LANG_NEUTRAL
,SUBLANG_DEFAULT
), (PTSTR
)&msg
, 0, NULL
))
246 MessageBox(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
248 MessageBox(hwnd
, RS(b1
,IDS_ERROR
), RS(b2
,IDS_WINEFILE
), MB_OK
);
254 /* allocate and initialise a directory entry */
255 static Entry
* alloc_entry()
257 Entry
* entry
= (Entry
*) malloc(sizeof(Entry
));
259 #ifdef _SHELL_FOLDERS
261 entry
->folder
= NULL
;
268 /* free a directory entry */
269 static void free_entry(Entry
* entry
)
271 #ifdef _SHELL_FOLDERS
272 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
273 DestroyIcon(entry
->hicon
);
275 if (entry
->folder
&& entry
->folder
!=Globals
.iDesktop
)
276 (*entry
->folder
->lpVtbl
->Release
)(entry
->folder
);
279 (*Globals
.iMalloc
->lpVtbl
->Free
)(Globals
.iMalloc
, entry
->pidl
);
285 /* recursively free all child entries */
286 static void free_entries(Entry
* dir
)
288 Entry
*entry
, *next
=dir
->down
;
304 static void read_directory_win(Entry
* dir
, LPCTSTR path
)
306 Entry
* first_entry
= NULL
;
310 int level
= dir
->level
+ 1;
311 WIN32_FIND_DATA w32fd
;
313 #ifndef _NO_EXTENSIONS
317 TCHAR buffer
[MAX_PATH
], *p
;
318 for(p
=buffer
; *path
; )
325 hFind
= FindFirstFile(buffer
, &w32fd
);
327 if (hFind
!= INVALID_HANDLE_VALUE
) {
329 entry
= alloc_entry();
337 memcpy(&entry
->data
, &w32fd
, sizeof(WIN32_FIND_DATA
));
340 entry
->expanded
= FALSE
;
341 entry
->scanned
= FALSE
;
342 entry
->level
= level
;
344 #ifdef _NO_EXTENSIONS
345 /* hide directory entry "." */
346 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
347 LPCTSTR name
= entry
->data
.cFileName
;
349 if (name
[0]=='.' && name
[1]=='\0')
353 entry
->etype
= ET_WINDOWS
;
354 entry
->bhfi_valid
= FALSE
;
356 lstrcpy(p
, entry
->data
.cFileName
);
358 hFile
= CreateFile(buffer
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
359 0, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0);
361 if (hFile
!= INVALID_HANDLE_VALUE
) {
362 if (GetFileInformationByHandle(hFile
, &entry
->bhfi
))
363 entry
->bhfi_valid
= TRUE
;
370 } while(FindNextFile(hFind
, &entry
->data
));
377 dir
->down
= first_entry
;
382 static Entry
* find_entry_win(Entry
* dir
, LPCTSTR name
)
386 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
388 LPCTSTR q
= entry
->data
.cFileName
;
391 if (!*p
|| *p
==TEXT('\\') || *p
==TEXT('/'))
393 } while(tolower(*p
++) == tolower(*q
++));
396 q
= entry
->data
.cAlternateFileName
;
399 if (!*p
|| *p
==TEXT('\\') || *p
==TEXT('/'))
401 } while(tolower(*p
++) == tolower(*q
++));
408 static Entry
* read_tree_win(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
410 TCHAR buffer
[MAX_PATH
];
411 Entry
* entry
= &root
->entry
;
415 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
417 #ifndef _NO_EXTENSIONS
418 entry
->etype
= ET_WINDOWS
;
422 while(*s
&& *s
!=TEXT('\\') && *s
!=TEXT('/'))
425 while(*s
==TEXT('\\') || *s
==TEXT('/'))
431 read_directory(entry
, buffer
, sortOrder
, hwnd
);
434 entry
->expanded
= TRUE
;
439 entry
= find_entry_win(entry
, s
);
442 SetCursor(old_cursor
);
448 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
450 static BOOL
time_to_filetime(const time_t* t
, FILETIME
* ftime
)
452 struct tm
* tm
= gmtime(t
);
458 stime
.wYear
= tm
->tm_year
+1900;
459 stime
.wMonth
= tm
->tm_mon
+1;
460 /* stime.wDayOfWeek */
461 stime
.wDay
= tm
->tm_mday
;
462 stime
.wHour
= tm
->tm_hour
;
463 stime
.wMinute
= tm
->tm_min
;
464 stime
.wSecond
= tm
->tm_sec
;
466 return SystemTimeToFileTime(&stime
, ftime
);
469 static void read_directory_unix(Entry
* dir
, LPCTSTR path
)
471 Entry
* first_entry
= NULL
;
477 char cpath
[MAX_PATH
];
479 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, cpath
, MAX_PATH
, NULL
, NULL
);
481 const char* cpath
= path
;
484 pdir
= call_opendir(cpath
);
486 int level
= dir
->level
+ 1;
489 char buffer
[MAX_PATH
];
496 for(p
=buffer
,s
=cpath
; *s
; )
499 if (p
==buffer
|| p
[-1]!='/')
502 while(call_readdir(pdir
, p
, &inode
)) {
503 entry
= alloc_entry();
511 entry
->etype
= ET_UNIX
;
514 MultiByteToWideChar(CP_UNIXCP
, 0, p
, -1, entry
->data
.cFileName
, MAX_PATH
);
516 lstrcpy(entry
->data
.cFileName
, p
);
519 entry
->data
.dwFileAttributes
= p
[0]=='.'? FILE_ATTRIBUTE_HIDDEN
: 0;
521 if (!call_stat(buffer
, &is_dir
,
522 &entry
->data
.nFileSizeLow
, &entry
->data
.nFileSizeHigh
,
523 &atime
, &mtime
, &entry
->bhfi
.nNumberOfLinks
))
526 entry
->data
.dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
528 memset(&entry
->data
.ftCreationTime
, 0, sizeof(FILETIME
));
529 time_to_filetime(&atime
, &entry
->data
.ftLastAccessTime
);
530 time_to_filetime(&mtime
, &entry
->data
.ftLastWriteTime
);
532 entry
->bhfi
.nFileIndexLow
= inode
;
533 entry
->bhfi
.nFileIndexHigh
= 0;
535 entry
->bhfi_valid
= TRUE
;
537 entry
->data
.nFileSizeLow
= 0;
538 entry
->data
.nFileSizeHigh
= 0;
539 entry
->bhfi_valid
= FALSE
;
544 entry
->expanded
= FALSE
;
545 entry
->scanned
= FALSE
;
546 entry
->level
= level
;
556 dir
->down
= first_entry
;
560 static Entry
* find_entry_unix(Entry
* dir
, LPCTSTR name
)
564 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
566 LPCTSTR q
= entry
->data
.cFileName
;
569 if (!*p
|| *p
==TEXT('/'))
571 } while(*p
++ == *q
++);
577 static Entry
* read_tree_unix(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
579 TCHAR buffer
[MAX_PATH
];
580 Entry
* entry
= &root
->entry
;
584 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
586 entry
->etype
= ET_UNIX
;
589 while(*s
&& *s
!=TEXT('/'))
592 while(*s
== TEXT('/'))
598 read_directory(entry
, buffer
, sortOrder
, hwnd
);
601 entry
->expanded
= TRUE
;
606 entry
= find_entry_unix(entry
, s
);
609 SetCursor(old_cursor
);
614 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
617 #ifdef _SHELL_FOLDERS
620 #define tcscpyn strcpyn
621 #define get_strret get_strretW
622 #define path_from_pidl path_from_pidlW
624 #define tcscpyn wcscpyn
625 #define get_strret get_strretA
626 #define path_from_pidl path_from_pidlA
630 static LPSTR
strcpyn(LPSTR dest
, LPCSTR source
, size_t count
)
635 for(s
=source
; count
&&(*d
++=*s
++); )
641 static LPWSTR
wcscpyn(LPWSTR dest
, LPCWSTR source
, size_t count
)
646 for(s
=source
; count
&&(*d
++=*s
++); )
653 static void get_strretA(STRRET
* str
, const SHITEMID
* shiid
, LPSTR buffer
, int len
)
657 WideCharToMultiByte(CP_ACP
, 0, str
->UNION_MEMBER(pOleStr
), -1, buffer
, len
, NULL
, NULL
);
661 strcpyn(buffer
, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), len
);
665 strcpyn(buffer
, str
->UNION_MEMBER(cStr
), len
);
669 static void get_strretW(STRRET
* str
, const SHITEMID
* shiid
, LPWSTR buffer
, int len
)
673 wcscpyn(buffer
, str
->UNION_MEMBER(pOleStr
), len
);
677 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), -1, buffer
, len
);
681 MultiByteToWideChar(CP_ACP
, 0, str
->UNION_MEMBER(cStr
), -1, buffer
, len
);
686 static void free_strret(STRRET
* str
)
688 if (str
->uType
== STRRET_WSTR
)
689 (*Globals
.iMalloc
->lpVtbl
->Free
)(Globals
.iMalloc
, str
->UNION_MEMBER(pOleStr
));
693 HRESULT
name_from_pidl(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPTSTR buffer
, int len
, SHGDNF flags
)
697 HRESULT hr
= (*folder
->lpVtbl
->GetDisplayNameOf
)(folder
, pidl
, flags
, &str
);
700 get_strret(&str
, &pidl
->mkid
, buffer
, len
);
709 HRESULT
path_from_pidlA(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPSTR buffer
, int len
)
713 /* SHGDN_FORPARSING: get full path of id list */
714 HRESULT hr
= (*folder
->lpVtbl
->GetDisplayNameOf
)(folder
, pidl
, SHGDN_FORPARSING
, &str
);
717 get_strretA(&str
, &pidl
->mkid
, buffer
, len
);
725 HRESULT
path_from_pidlW(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPWSTR buffer
, int len
)
729 /* SHGDN_FORPARSING: get full path of id list */
730 HRESULT hr
= (*folder
->lpVtbl
->GetDisplayNameOf
)(folder
, pidl
, SHGDN_FORPARSING
, &str
);
733 get_strretW(&str
, &pidl
->mkid
, buffer
, len
);
742 /* create an item id list from a file system path */
744 static LPITEMIDLIST
get_path_pidl(LPTSTR path
, HWND hwnd
)
751 LPWSTR buffer
= path
;
753 WCHAR buffer
[MAX_PATH
];
754 MultiByteToWideChar(CP_ACP
, 0, path
, -1, buffer
, MAX_PATH
);
757 hr
= (*Globals
.iDesktop
->lpVtbl
->ParseDisplayName
)(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
765 /* convert an item id list from relative to absolute (=relative to the desktop) format */
767 static LPITEMIDLIST
get_to_absolute_pidl(Entry
* entry
, HWND hwnd
)
769 if (entry
->up
&& entry
->up
->etype
==ET_SHELL
) {
770 IShellFolder
* folder
= entry
->up
->folder
;
771 WCHAR buffer
[MAX_PATH
];
773 HRESULT hr
= path_from_pidlW(folder
, entry
->pidl
, buffer
, MAX_PATH
);
779 hr
= (*Globals
.iDesktop
->lpVtbl
->ParseDisplayName
)(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
784 } else if (entry
->etype
== ET_WINDOWS
) {
785 TCHAR path
[MAX_PATH
];
787 get_path(entry
, path
);
789 return get_path_pidl(path
, hwnd
);
790 } else if (entry
->pidl
)
791 return ILClone(entry
->pidl
);
797 HICON
extract_icon(IShellFolder
* folder
, LPCITEMIDLIST pidl
)
799 IExtractIcon
* pExtract
;
801 if (SUCCEEDED((*folder
->lpVtbl
->GetUIObjectOf
)(folder
, 0, 1, (LPCITEMIDLIST
*)&pidl
, &IID_IExtractIcon
, 0, (LPVOID
*)&pExtract
))) {
802 TCHAR path
[_MAX_PATH
];
807 if (SUCCEEDED((*pExtract
->lpVtbl
->GetIconLocation
)(pExtract
, GIL_FORSHELL
, path
, _MAX_PATH
, &idx
, &flags
))) {
808 if (!(flags
& GIL_NOTFILENAME
)) {
810 idx
= 0; /* special case for some control panel applications */
812 if ((int)ExtractIconEx(path
, idx
, 0, &hicon
, 1) > 0)
813 flags
&= ~GIL_DONTCACHE
;
815 HICON hIconLarge
= 0;
817 HRESULT hr
= (*pExtract
->lpVtbl
->Extract
)(pExtract
, path
, idx
, &hIconLarge
, &hicon
, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON
)));
820 DestroyIcon(hIconLarge
);
831 static Entry
* find_entry_shell(Entry
* dir
, LPITEMIDLIST pidl
)
835 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
836 if (entry
->pidl
->mkid
.cb
== pidl
->mkid
.cb
&&
837 !memcmp(entry
->pidl
, pidl
, entry
->pidl
->mkid
.cb
))
844 static Entry
* read_tree_shell(Root
* root
, LPITEMIDLIST pidl
, SORT_ORDER sortOrder
, HWND hwnd
)
846 Entry
* entry
= &root
->entry
;
848 LPITEMIDLIST next_pidl
= pidl
;
849 IShellFolder
* folder
;
850 IShellFolder
* child
= NULL
;
853 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
855 #ifndef _NO_EXTENSIONS
856 entry
->etype
= ET_SHELL
;
859 folder
= Globals
.iDesktop
;
862 entry
->pidl
= next_pidl
;
863 entry
->folder
= folder
;
868 /* copy first element of item idlist -> could be replaced by SHBindToParent() */
869 next_pidl
= (*Globals
.iMalloc
->lpVtbl
->Alloc
)(Globals
.iMalloc
, pidl
->mkid
.cb
+sizeof(USHORT
));
870 memcpy(next_pidl
, pidl
, pidl
->mkid
.cb
);
871 ((LPITEMIDLIST
)((LPBYTE
)next_pidl
+pidl
->mkid
.cb
))->mkid
.cb
= 0;
873 hr
= (*folder
->lpVtbl
->BindToObject
)(folder
, next_pidl
, 0, &IID_IShellFolder
, (void**)&child
);
877 read_directory(entry
, NULL
, sortOrder
, hwnd
);
880 entry
->expanded
= TRUE
;
882 next
= find_entry_shell(entry
, next_pidl
);
889 /* go to next element */
890 pidl
= (LPITEMIDLIST
) ((LPBYTE
)pidl
+pidl
->mkid
.cb
);
893 SetCursor(old_cursor
);
899 static void fill_w32fdata_shell(IShellFolder
* folder
, LPCITEMIDLIST pidl
, SFGAOF attribs
, WIN32_FIND_DATA
* w32fdata
)
901 if (!(attribs
& SFGAO_FILESYSTEM
) ||
902 FAILED(SHGetDataFromIDList(folder
, pidl
, SHGDFIL_FINDDATA
, w32fdata
, sizeof(WIN32_FIND_DATA
)))) {
903 WIN32_FILE_ATTRIBUTE_DATA fad
;
904 IDataObject
* pDataObj
;
906 STGMEDIUM medium
= {0, {0}, 0};
907 FORMATETC fmt
= {Globals
.cfStrFName
, 0, DVASPECT_CONTENT
, -1, TYMED_HGLOBAL
};
909 HRESULT hr
= (*folder
->lpVtbl
->GetUIObjectOf
)(folder
, 0, 1, &pidl
, &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
912 hr
= (*pDataObj
->lpVtbl
->GetData
)(pDataObj
, &fmt
, &medium
);
914 (*pDataObj
->lpVtbl
->Release
)(pDataObj
);
917 LPCTSTR path
= (LPCTSTR
)GlobalLock(medium
.UNION_MEMBER(hGlobal
));
918 UINT sem_org
= SetErrorMode(SEM_FAILCRITICALERRORS
);
920 if (GetFileAttributesEx(path
, GetFileExInfoStandard
, &fad
)) {
921 w32fdata
->dwFileAttributes
= fad
.dwFileAttributes
;
922 w32fdata
->ftCreationTime
= fad
.ftCreationTime
;
923 w32fdata
->ftLastAccessTime
= fad
.ftLastAccessTime
;
924 w32fdata
->ftLastWriteTime
= fad
.ftLastWriteTime
;
926 if (!(fad
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)) {
927 w32fdata
->nFileSizeLow
= fad
.nFileSizeLow
;
928 w32fdata
->nFileSizeHigh
= fad
.nFileSizeHigh
;
932 SetErrorMode(sem_org
);
934 GlobalUnlock(medium
.UNION_MEMBER(hGlobal
));
935 GlobalFree(medium
.UNION_MEMBER(hGlobal
));
940 if (attribs
& (SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
))
941 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
943 if (attribs
& SFGAO_READONLY
)
944 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_READONLY
;
946 if (attribs
& SFGAO_COMPRESSED
)
947 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_COMPRESSED
;
951 static void read_directory_shell(Entry
* dir
, HWND hwnd
)
953 IShellFolder
* folder
= dir
->folder
;
954 int level
= dir
->level
+ 1;
960 Entry
* first_entry
= NULL
;
967 hr
= (*folder
->lpVtbl
->EnumObjects
)(folder
, hwnd
, SHCONTF_FOLDERS
|SHCONTF_NONFOLDERS
|SHCONTF_INCLUDEHIDDEN
|SHCONTF_SHAREABLE
|SHCONTF_STORAGE
, &idlist
);
971 #define FETCH_ITEM_COUNT 32
972 LPITEMIDLIST pidls
[FETCH_ITEM_COUNT
];
977 memset(pidls
, 0, sizeof(pidls
));
979 hr
= (*idlist
->lpVtbl
->Next
)(idlist
, FETCH_ITEM_COUNT
, pidls
, &cnt
);
986 for(n
=0; n
<cnt
; ++n
) {
987 entry
= alloc_entry();
995 memset(&entry
->data
, 0, sizeof(WIN32_FIND_DATA
));
996 entry
->bhfi_valid
= FALSE
;
998 attribs
= ~SFGAO_FILESYSTEM
; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
1000 hr
= (*folder
->lpVtbl
->GetAttributesOf
)(folder
, 1, (LPCITEMIDLIST
*)&pidls
[n
], &attribs
);
1002 if (SUCCEEDED(hr
)) {
1003 if (attribs
!= (SFGAOF
)~SFGAO_FILESYSTEM
) {
1004 fill_w32fdata_shell(folder
, pidls
[n
], attribs
, &entry
->data
);
1006 entry
->bhfi_valid
= TRUE
;
1012 entry
->pidl
= pidls
[n
];
1014 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1015 hr
= (*folder
->lpVtbl
->BindToObject
)(folder
, pidls
[n
], 0, &IID_IShellFolder
, (void**)&child
);
1018 entry
->folder
= child
;
1020 entry
->folder
= NULL
;
1023 entry
->folder
= NULL
;
1025 if (!entry
->data
.cFileName
[0])
1026 /*hr = */name_from_pidl(folder
, pidls
[n
], entry
->data
.cFileName
, MAX_PATH
, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1028 /* get display icons for files and virtual objects */
1029 if (!(entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ||
1030 !(attribs
& SFGAO_FILESYSTEM
)) {
1031 entry
->hicon
= extract_icon(folder
, pidls
[n
]);
1034 entry
->hicon
= (HICON
)-1; /* don't try again later */
1039 entry
->expanded
= FALSE
;
1040 entry
->scanned
= FALSE
;
1041 entry
->level
= level
;
1043 #ifndef _NO_EXTENSIONS
1044 entry
->etype
= ET_SHELL
;
1045 entry
->bhfi_valid
= FALSE
;
1052 (*idlist
->lpVtbl
->Release
)(idlist
);
1058 dir
->down
= first_entry
;
1059 dir
->scanned
= TRUE
;
1062 #endif /* _SHELL_FOLDERS */
1065 /* sort order for different directory/file types */
1074 /* distinguish between ".", ".." and any other directory names */
1075 static int TypeOrderFromDirname(LPCTSTR name
)
1077 if (name
[0] == '.') {
1078 if (name
[1] == '\0')
1079 return TO_DOT
; /* "." */
1081 if (name
[1]=='.' && name
[2]=='\0')
1082 return TO_DOTDOT
; /* ".." */
1085 return TO_OTHER_DIR
; /* anything else */
1088 /* directories first... */
1089 static int compareType(const WIN32_FIND_DATA
* fd1
, const WIN32_FIND_DATA
* fd2
)
1091 int order1
= fd1
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1092 int order2
= fd2
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1094 /* Handle "." and ".." as special case and move them at the very first beginning. */
1095 if (order1
==TO_DIR
&& order2
==TO_DIR
) {
1096 order1
= TypeOrderFromDirname(fd1
->cFileName
);
1097 order2
= TypeOrderFromDirname(fd2
->cFileName
);
1100 return order2
==order1
? 0: order1
<order2
? -1: 1;
1104 static int compareName(const void* arg1
, const void* arg2
)
1106 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1107 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1109 int cmp
= compareType(fd1
, fd2
);
1113 return lstrcmpi(fd1
->cFileName
, fd2
->cFileName
);
1116 static int compareExt(const void* arg1
, const void* arg2
)
1118 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1119 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1120 const TCHAR
*name1
, *name2
, *ext1
, *ext2
;
1122 int cmp
= compareType(fd1
, fd2
);
1126 name1
= fd1
->cFileName
;
1127 name2
= fd2
->cFileName
;
1129 ext1
= _tcsrchr(name1
, TEXT('.'));
1130 ext2
= _tcsrchr(name2
, TEXT('.'));
1142 cmp
= lstrcmpi(ext1
, ext2
);
1146 return lstrcmpi(name1
, name2
);
1149 static int compareSize(const void* arg1
, const void* arg2
)
1151 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1152 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1154 int cmp
= compareType(fd1
, fd2
);
1158 cmp
= fd2
->nFileSizeHigh
- fd1
->nFileSizeHigh
;
1165 cmp
= fd2
->nFileSizeLow
- fd1
->nFileSizeLow
;
1167 return cmp
<0? -1: cmp
>0? 1: 0;
1170 static int compareDate(const void* arg1
, const void* arg2
)
1172 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1173 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1175 int cmp
= compareType(fd1
, fd2
);
1179 return CompareFileTime(&fd2
->ftLastWriteTime
, &fd1
->ftLastWriteTime
);
1183 static int (*sortFunctions
[])(const void* arg1
, const void* arg2
) = {
1184 compareName
, /* SORT_NAME */
1185 compareExt
, /* SORT_EXT */
1186 compareSize
, /* SORT_SIZE */
1187 compareDate
/* SORT_DATE */
1191 static void SortDirectory(Entry
* dir
, SORT_ORDER sortOrder
)
1193 Entry
* entry
= dir
->down
;
1198 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1202 array
= (Entry
**) alloca(len
*sizeof(Entry
*));
1205 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1208 /* call qsort with the appropriate compare function */
1209 qsort(array
, len
, sizeof(array
[0]), sortFunctions
[sortOrder
]);
1211 dir
->down
= array
[0];
1213 for(p
=array
; --len
; p
++)
1221 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
1223 TCHAR buffer
[MAX_PATH
];
1228 #ifdef _SHELL_FOLDERS
1229 if (dir
->etype
== ET_SHELL
)
1231 read_directory_shell(dir
, hwnd
);
1233 if (Globals
.prescan_node
) {
1242 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1243 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1244 read_directory_shell(entry
, hwnd
);
1245 SortDirectory(entry
, sortOrder
);
1251 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1252 if (dir
->etype
== ET_UNIX
)
1254 read_directory_unix(dir
, path
);
1256 if (Globals
.prescan_node
) {
1265 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1266 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1267 lstrcpy(d
, entry
->data
.cFileName
);
1268 read_directory_unix(entry
, buffer
);
1269 SortDirectory(entry
, sortOrder
);
1276 read_directory_win(dir
, path
);
1278 if (Globals
.prescan_node
) {
1287 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1288 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1289 lstrcpy(d
, entry
->data
.cFileName
);
1290 read_directory_win(entry
, buffer
);
1291 SortDirectory(entry
, sortOrder
);
1296 SortDirectory(dir
, sortOrder
);
1300 static ChildWnd
* alloc_child_window(LPCTSTR path
, LPITEMIDLIST pidl
, HWND hwnd
)
1302 const static TCHAR sBackslash
[] = {'\\', '\0'};
1303 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1304 const static TCHAR sSlash
[] = {'/', '\0'};
1307 TCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
1308 TCHAR b1
[BUFFER_LEN
];
1310 ChildWnd
* child
= (ChildWnd
*) malloc(sizeof(ChildWnd
));
1311 Root
* root
= &child
->root
;
1314 memset(child
, 0, sizeof(ChildWnd
));
1316 child
->left
.treePane
= TRUE
;
1317 child
->left
.visible_cols
= 0;
1319 child
->right
.treePane
= FALSE
;
1320 #ifndef _NO_EXTENSIONS
1321 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_INDEX
|COL_LINKS
;
1323 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
;
1326 child
->pos
.length
= sizeof(WINDOWPLACEMENT
);
1327 child
->pos
.flags
= 0;
1328 child
->pos
.showCmd
= SW_SHOWNORMAL
;
1329 child
->pos
.rcNormalPosition
.left
= CW_USEDEFAULT
;
1330 child
->pos
.rcNormalPosition
.top
= CW_USEDEFAULT
;
1331 child
->pos
.rcNormalPosition
.right
= CW_USEDEFAULT
;
1332 child
->pos
.rcNormalPosition
.bottom
= CW_USEDEFAULT
;
1334 child
->focus_pane
= 0;
1335 child
->split_pos
= DEFAULT_SPLIT_POS
;
1336 child
->sortOrder
= SORT_NAME
;
1337 child
->header_wdths_ok
= FALSE
;
1341 lstrcpy(child
->path
, path
);
1343 _tsplitpath(path
, drv
, dir
, name
, ext
);
1346 root
->entry
.level
= 0;
1348 #ifdef _SHELL_FOLDERS
1351 root
->drive_type
= DRIVE_UNKNOWN
;
1354 load_string(root
->volname
, IDS_DESKTOP
);
1356 load_string(root
->fs
, IDS_SHELL
);
1358 entry
= read_tree_shell(root
, pidl
, child
->sortOrder
, hwnd
);
1362 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1365 root
->drive_type
= GetDriveType(path
);
1367 lstrcat(drv
, sSlash
);
1368 load_string(root
->volname
, IDS_ROOT_FS
);
1370 load_string(root
->fs
, IDS_UNIXFS
);
1372 lstrcpy(root
->path
, sSlash
);
1373 entry
= read_tree_unix(root
, path
, child
->sortOrder
, hwnd
);
1378 root
->drive_type
= GetDriveType(path
);
1380 lstrcat(drv
, sBackslash
);
1381 GetVolumeInformation(drv
, root
->volname
, _MAX_FNAME
, 0, 0, &root
->fs_flags
, root
->fs
, _MAX_DIR
);
1383 lstrcpy(root
->path
, drv
);
1384 entry
= read_tree_win(root
, path
, child
->sortOrder
, hwnd
);
1387 #ifdef _SHELL_FOLDERS
1388 if (root
->entry
.etype
== ET_SHELL
)
1389 load_string(root
->entry
.data
.cFileName
, IDS_DESKTOP
);
1392 wsprintf(root
->entry
.data
.cFileName
, RS(b1
,IDS_TITLEFMT
), drv
, root
->fs
);
1394 root
->entry
.data
.dwFileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1396 child
->left
.root
= &root
->entry
;
1397 child
->right
.root
= NULL
;
1399 set_curdir(child
, entry
, hwnd
);
1405 /* free all memory associated with a child window */
1406 static void free_child_window(ChildWnd
* child
)
1408 free_entries(&child
->root
.entry
);
1413 /* get full path of specified directory entry */
1414 static void get_path(Entry
* dir
, PTSTR path
)
1420 #ifdef _SHELL_FOLDERS
1421 if (dir
->etype
== ET_SHELL
)
1426 path
[0] = TEXT('\0');
1431 hr
= (*dir
->folder
->lpVtbl
->GetAttributesOf
)(dir
->folder
, 1, (LPCITEMIDLIST
*)&dir
->pidl
, &attribs
);
1433 if (SUCCEEDED(hr
) && (attribs
&SFGAO_FILESYSTEM
)) {
1434 IShellFolder
* parent
= dir
->up
? dir
->up
->folder
: Globals
.iDesktop
;
1436 hr
= path_from_pidl(parent
, dir
->pidl
, path
, MAX_PATH
);
1442 for(entry
=dir
; entry
; level
++) {
1448 name
= entry
->data
.cFileName
;
1451 for(l
=0; *s
&& *s
!=TEXT('/') && *s
!=TEXT('\\'); s
++)
1457 memmove(path
+l
+1, path
, len
*sizeof(TCHAR
));
1458 memcpy(path
+1, name
, l
*sizeof(TCHAR
));
1461 #ifndef _NO_EXTENSIONS
1462 if (entry
->etype
== ET_UNIX
)
1463 path
[0] = TEXT('/');
1466 path
[0] = TEXT('\\');
1471 memmove(path
+l
, path
, len
*sizeof(TCHAR
));
1472 memcpy(path
, name
, l
*sizeof(TCHAR
));
1479 #ifndef _NO_EXTENSIONS
1480 if (entry
->etype
== ET_UNIX
)
1481 path
[len
++] = TEXT('/');
1484 path
[len
++] = TEXT('\\');
1487 path
[len
] = TEXT('\0');
1492 static void resize_frame_rect(HWND hwnd
, PRECT prect
)
1497 if (IsWindowVisible(Globals
.htoolbar
)) {
1498 SendMessage(Globals
.htoolbar
, WM_SIZE
, 0, 0);
1499 GetClientRect(Globals
.htoolbar
, &rt
);
1500 prect
->top
= rt
.bottom
+3;
1501 prect
->bottom
-= rt
.bottom
+3;
1504 if (IsWindowVisible(Globals
.hdrivebar
)) {
1505 SendMessage(Globals
.hdrivebar
, WM_SIZE
, 0, 0);
1506 GetClientRect(Globals
.hdrivebar
, &rt
);
1507 new_top
= --prect
->top
+ rt
.bottom
+3;
1508 MoveWindow(Globals
.hdrivebar
, 0, prect
->top
, rt
.right
, new_top
, TRUE
);
1509 prect
->top
= new_top
;
1510 prect
->bottom
-= rt
.bottom
+2;
1513 if (IsWindowVisible(Globals
.hstatusbar
)) {
1514 int parts
[] = {300, 500};
1516 SendMessage(Globals
.hstatusbar
, WM_SIZE
, 0, 0);
1517 SendMessage(Globals
.hstatusbar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
1518 GetClientRect(Globals
.hstatusbar
, &rt
);
1519 prect
->bottom
-= rt
.bottom
;
1522 MoveWindow(Globals
.hmdiclient
, prect
->left
-1,prect
->top
-1,prect
->right
+2,prect
->bottom
+1, TRUE
);
1525 static void resize_frame(HWND hwnd
, int cx
, int cy
)
1534 resize_frame_rect(hwnd
, &rect
);
1537 static void resize_frame_client(HWND hwnd
)
1541 GetClientRect(hwnd
, &rect
);
1543 resize_frame_rect(hwnd
, &rect
);
1547 static HHOOK hcbthook
;
1548 static ChildWnd
* newchild
= NULL
;
1550 LRESULT CALLBACK
CBTProc(int code
, WPARAM wparam
, LPARAM lparam
)
1552 if (code
==HCBT_CREATEWND
&& newchild
) {
1553 ChildWnd
* child
= newchild
;
1556 child
->hwnd
= (HWND
) wparam
;
1557 SetWindowLong(child
->hwnd
, GWL_USERDATA
, (LPARAM
)child
);
1560 return CallNextHookEx(hcbthook
, code
, wparam
, lparam
);
1563 static HWND
create_child_window(ChildWnd
* child
)
1565 MDICREATESTRUCT mcs
;
1568 mcs
.szClass
= sWINEFILETREE
;
1569 mcs
.szTitle
= (LPTSTR
)child
->path
;
1570 mcs
.hOwner
= Globals
.hInstance
;
1571 mcs
.x
= child
->pos
.rcNormalPosition
.left
;
1572 mcs
.y
= child
->pos
.rcNormalPosition
.top
;
1573 mcs
.cx
= child
->pos
.rcNormalPosition
.right
-child
->pos
.rcNormalPosition
.left
;
1574 mcs
.cy
= child
->pos
.rcNormalPosition
.bottom
-child
->pos
.rcNormalPosition
.top
;
1578 hcbthook
= SetWindowsHookEx(WH_CBT
, CBTProc
, 0, GetCurrentThreadId());
1581 child
->hwnd
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDICREATE
, 0, (LPARAM
)&mcs
);
1583 UnhookWindowsHookEx(hcbthook
);
1587 UnhookWindowsHookEx(hcbthook
);
1589 ListBox_SetItemHeight(child
->left
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1590 ListBox_SetItemHeight(child
->right
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1591 idx
= ListBox_FindItemData(child
->left
.hwnd
, ListBox_GetCurSel(child
->left
.hwnd
), child
->left
.cur
);
1592 ListBox_SetCurSel(child
->left
.hwnd
, idx
);
1598 struct ExecuteDialog
{
1599 TCHAR cmd
[MAX_PATH
];
1604 static INT_PTR CALLBACK
ExecuteDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1606 static struct ExecuteDialog
* dlg
;
1610 dlg
= (struct ExecuteDialog
*) lparam
;
1614 int id
= (int)wparam
;
1617 GetWindowText(GetDlgItem(hwnd
, 201), dlg
->cmd
, MAX_PATH
);
1618 dlg
->cmdshow
= Button_GetState(GetDlgItem(hwnd
,214))&BST_CHECKED
?
1619 SW_SHOWMINIMIZED
: SW_SHOWNORMAL
;
1620 EndDialog(hwnd
, id
);
1621 } else if (id
== IDCANCEL
)
1622 EndDialog(hwnd
, id
);
1630 static INT_PTR CALLBACK
DestinationDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1632 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1636 SetWindowLong(hwnd
, GWL_USERDATA
, lparam
);
1640 int id
= (int)wparam
;
1644 LPTSTR dest
= (LPTSTR
) GetWindowLong(hwnd
, GWL_USERDATA
);
1645 GetWindowText(GetDlgItem(hwnd
, 201), dest
, MAX_PATH
);
1646 EndDialog(hwnd
, id
);
1650 EndDialog(hwnd
, id
);
1654 MessageBox(hwnd
, RS(b1
,IDS_NO_IMPL
), RS(b2
,IDS_WINEFILE
), MB_OK
);
1666 #ifndef _NO_EXTENSIONS
1668 static struct FullScreenParameters
{
1678 void frame_get_clientspace(HWND hwnd
, PRECT prect
)
1682 if (!IsIconic(hwnd
))
1683 GetClientRect(hwnd
, prect
);
1687 GetWindowPlacement(hwnd
, &wp
);
1689 prect
->left
= prect
->top
= 0;
1690 prect
->right
= wp
.rcNormalPosition
.right
-wp
.rcNormalPosition
.left
-
1691 2*(GetSystemMetrics(SM_CXSIZEFRAME
)+GetSystemMetrics(SM_CXEDGE
));
1692 prect
->bottom
= wp
.rcNormalPosition
.bottom
-wp
.rcNormalPosition
.top
-
1693 2*(GetSystemMetrics(SM_CYSIZEFRAME
)+GetSystemMetrics(SM_CYEDGE
))-
1694 GetSystemMetrics(SM_CYCAPTION
)-GetSystemMetrics(SM_CYMENUSIZE
);
1697 if (IsWindowVisible(Globals
.htoolbar
)) {
1698 GetClientRect(Globals
.htoolbar
, &rt
);
1699 prect
->top
+= rt
.bottom
+2;
1702 if (IsWindowVisible(Globals
.hdrivebar
)) {
1703 GetClientRect(Globals
.hdrivebar
, &rt
);
1704 prect
->top
+= rt
.bottom
+2;
1707 if (IsWindowVisible(Globals
.hstatusbar
)) {
1708 GetClientRect(Globals
.hstatusbar
, &rt
);
1709 prect
->bottom
-= rt
.bottom
;
1713 static BOOL
toggle_fullscreen(HWND hwnd
)
1717 if ((g_fullscreen
.mode
=!g_fullscreen
.mode
)) {
1718 GetWindowRect(hwnd
, &g_fullscreen
.orgPos
);
1719 g_fullscreen
.wasZoomed
= IsZoomed(hwnd
);
1721 Frame_CalcFrameClient(hwnd
, &rt
);
1722 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
1723 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
1725 rt
.left
= g_fullscreen
.orgPos
.left
-rt
.left
;
1726 rt
.top
= g_fullscreen
.orgPos
.top
-rt
.top
;
1727 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+g_fullscreen
.orgPos
.right
-rt
.right
;
1728 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+g_fullscreen
.orgPos
.bottom
-rt
.bottom
;
1730 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
1732 MoveWindow(hwnd
, g_fullscreen
.orgPos
.left
, g_fullscreen
.orgPos
.top
,
1733 g_fullscreen
.orgPos
.right
-g_fullscreen
.orgPos
.left
,
1734 g_fullscreen
.orgPos
.bottom
-g_fullscreen
.orgPos
.top
, TRUE
);
1736 if (g_fullscreen
.wasZoomed
)
1737 ShowWindow(hwnd
, WS_MAXIMIZE
);
1740 return g_fullscreen
.mode
;
1743 static void fullscreen_move(HWND hwnd
)
1746 GetWindowRect(hwnd
, &pos
);
1748 Frame_CalcFrameClient(hwnd
, &rt
);
1749 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
1750 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
1752 rt
.left
= pos
.left
-rt
.left
;
1753 rt
.top
= pos
.top
-rt
.top
;
1754 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+pos
.right
-rt
.right
;
1755 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+pos
.bottom
-rt
.bottom
;
1757 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
1763 static void toggle_child(HWND hwnd
, UINT cmd
, HWND hchild
)
1765 BOOL vis
= IsWindowVisible(hchild
);
1767 CheckMenuItem(Globals
.hMenuOptions
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
1769 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
1771 #ifndef _NO_EXTENSIONS
1772 if (g_fullscreen
.mode
)
1773 fullscreen_move(hwnd
);
1776 resize_frame_client(hwnd
);
1779 BOOL
activate_drive_window(LPCTSTR path
)
1781 TCHAR drv1
[_MAX_DRIVE
], drv2
[_MAX_DRIVE
];
1784 _tsplitpath(path
, drv1
, 0, 0, 0);
1786 /* search for a already open window for the same drive */
1787 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
1788 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(child_wnd
, GWL_USERDATA
);
1791 _tsplitpath(child
->root
.path
, drv2
, 0, 0, 0);
1793 if (!lstrcmpi(drv2
, drv1
)) {
1794 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
1796 if (IsMinimized(child_wnd
))
1797 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
1807 BOOL
activate_fs_window(LPCTSTR filesys
)
1811 /* search for a already open window of the given file system name */
1812 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
1813 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(child_wnd
, GWL_USERDATA
);
1816 if (!lstrcmpi(child
->root
.fs
, filesys
)) {
1817 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
1819 if (IsMinimized(child_wnd
))
1820 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
1830 LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1832 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1836 DestroyWindow(hwnd
);
1838 /* clear handle variables */
1839 Globals
.hMenuFrame
= 0;
1840 Globals
.hMenuView
= 0;
1841 Globals
.hMenuOptions
= 0;
1842 Globals
.hMainWnd
= 0;
1843 Globals
.hmdiclient
= 0;
1844 Globals
.hdrivebar
= 0;
1848 /* don't exit desktop when closing file manager window */
1849 if (!Globals
.hwndParent
)
1854 UINT cmd
= LOWORD(wparam
);
1855 HWND hwndClient
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
1857 if (SendMessage(hwndClient
, WM_DISPATCH_COMMAND
, wparam
, lparam
))
1860 if (cmd
>=ID_DRIVE_FIRST
&& cmd
<=ID_DRIVE_FIRST
+0xFF) {
1861 TCHAR drv
[_MAX_DRIVE
], path
[MAX_PATH
];
1863 LPCTSTR root
= Globals
.drives
;
1866 for(i
=cmd
-ID_DRIVE_FIRST
; i
--; root
++)
1870 if (activate_drive_window(root
))
1873 _tsplitpath(root
, drv
, 0, 0, 0);
1875 if (!SetCurrentDirectory(drv
)) {
1876 display_error(hwnd
, GetLastError());
1880 GetCurrentDirectory(MAX_PATH
, path
); /*TODO: store last directory per drive */
1881 child
= alloc_child_window(path
, NULL
, hwnd
);
1883 if (!create_child_window(child
))
1885 } else switch(cmd
) {
1887 SendMessage(hwnd
, WM_CLOSE
, 0, 0);
1890 case ID_WINDOW_NEW
: {
1891 TCHAR path
[MAX_PATH
];
1894 GetCurrentDirectory(MAX_PATH
, path
);
1895 child
= alloc_child_window(path
, NULL
, hwnd
);
1897 if (!create_child_window(child
))
1901 case ID_WINDOW_CASCADE
:
1902 SendMessage(Globals
.hmdiclient
, WM_MDICASCADE
, 0, 0);
1905 case ID_WINDOW_TILE_HORZ
:
1906 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
1909 case ID_WINDOW_TILE_VERT
:
1910 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
1913 case ID_WINDOW_ARRANGE
:
1914 SendMessage(Globals
.hmdiclient
, WM_MDIICONARRANGE
, 0, 0);
1917 case ID_SELECT_FONT
: {
1918 TCHAR dlg_name
[BUFFER_LEN
], dlg_info
[BUFFER_LEN
];
1922 HDC hdc
= GetDC(hwnd
);
1923 chFont
.lStructSize
= sizeof(CHOOSEFONT
);
1924 chFont
.hwndOwner
= hwnd
;
1926 chFont
.lpLogFont
= &lFont
;
1927 chFont
.Flags
= CF_SCREENFONTS
| CF_FORCEFONTEXIST
| CF_LIMITSIZE
| CF_NOSCRIPTSEL
;
1928 chFont
.rgbColors
= RGB(0,0,0);
1929 chFont
.lCustData
= 0;
1930 chFont
.lpfnHook
= NULL
;
1931 chFont
.lpTemplateName
= NULL
;
1932 chFont
.hInstance
= Globals
.hInstance
;
1933 chFont
.lpszStyle
= NULL
;
1934 chFont
.nFontType
= SIMULATED_FONTTYPE
;
1935 chFont
.nSizeMin
= 0;
1936 chFont
.nSizeMax
= 24;
1938 if (ChooseFont(&chFont
)) {
1941 Globals
.hfont
= CreateFontIndirect(&lFont
);
1942 SelectFont(hdc
, Globals
.hfont
);
1943 GetTextExtentPoint32(hdc
, sSpace
, 1, &Globals
.spaceSize
);
1945 /* change font in all open child windows */
1946 for(childWnd
=GetWindow(Globals
.hmdiclient
,GW_CHILD
); childWnd
; childWnd
=GetNextWindow(childWnd
,GW_HWNDNEXT
)) {
1947 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(childWnd
, GWL_USERDATA
);
1948 SetWindowFont(child
->left
.hwnd
, Globals
.hfont
, TRUE
);
1949 SetWindowFont(child
->right
.hwnd
, Globals
.hfont
, TRUE
);
1950 ListBox_SetItemHeight(child
->left
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1951 ListBox_SetItemHeight(child
->right
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1952 InvalidateRect(child
->left
.hwnd
, NULL
, TRUE
);
1953 InvalidateRect(child
->right
.hwnd
, NULL
, TRUE
);
1956 else if (CommDlgExtendedError()) {
1957 LoadString(Globals
.hInstance
, IDS_FONT_SEL_DLG_NAME
, dlg_name
, BUFFER_LEN
);
1958 LoadString(Globals
.hInstance
, IDS_FONT_SEL_ERROR
, dlg_info
, BUFFER_LEN
);
1959 MessageBox(hwnd
, dlg_info
, dlg_name
, MB_OK
);
1962 ReleaseDC(hwnd
, hdc
);
1966 case ID_VIEW_TOOL_BAR
:
1967 toggle_child(hwnd
, cmd
, Globals
.htoolbar
);
1970 case ID_VIEW_DRIVE_BAR
:
1971 toggle_child(hwnd
, cmd
, Globals
.hdrivebar
);
1974 case ID_VIEW_STATUSBAR
:
1975 toggle_child(hwnd
, cmd
, Globals
.hstatusbar
);
1979 struct ExecuteDialog dlg
;
1981 memset(&dlg
, 0, sizeof(struct ExecuteDialog
));
1983 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_EXECUTE
), hwnd
, ExecuteDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
1984 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, dlg
.cmd
/*file*/, NULL
/*parameters*/, NULL
/*dir*/, dlg
.cmdshow
);
1986 if ((int)hinst
<= 32)
1987 display_error(hwnd
, GetLastError());
1992 WinHelp(hwnd
, RS(b1
,IDS_WINEFILE
), HELP_INDEX
, 0);
1995 #ifndef _NO_EXTENSIONS
1996 case ID_VIEW_FULLSCREEN
:
1997 CheckMenuItem(Globals
.hMenuOptions
, cmd
, toggle_fullscreen(hwnd
)?MF_CHECKED
:0);
2001 case ID_DRIVE_UNIX_FS
: {
2002 TCHAR path
[MAX_PATH
];
2004 char cpath
[MAX_PATH
];
2008 if (activate_fs_window(RS(b1
,IDS_UNIXFS
)))
2013 call_getcwd(cpath
, MAX_PATH
);
2014 MultiByteToWideChar(CP_UNIXCP
, 0, cpath
, -1, path
, MAX_PATH
);
2016 call_getcwd(path
, MAX_PATH
);
2018 child
= alloc_child_window(path
, NULL
, hwnd
);
2020 if (!create_child_window(child
))
2025 #ifdef _SHELL_FOLDERS
2026 case ID_DRIVE_SHELL_NS
: {
2027 TCHAR path
[MAX_PATH
];
2030 if (activate_fs_window(RS(b1
,IDS_SHELL
)))
2033 GetCurrentDirectory(MAX_PATH
, path
);
2034 child
= alloc_child_window(path
, get_path_pidl(path
,hwnd
), hwnd
);
2036 if (!create_child_window(child
))
2042 /*TODO: There are even more menu items! */
2044 #ifndef _NO_EXTENSIONS
2047 WineLicense(Globals
.hMainWnd
);
2050 case ID_NO_WARRANTY
:
2051 WineWarranty(Globals
.hMainWnd
);
2056 ShellAbout(hwnd
, RS(b2
,IDS_WINE
), RS(b1
,IDS_WINEFILE
), 0);
2060 ShellAbout(hwnd
, RS(b1
,IDS_WINEFILE
), NULL
, 0);
2062 #endif /* _NO_EXTENSIONS */
2065 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2066 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2067 else */if ((cmd
<IDW_FIRST_CHILD
|| cmd
>=IDW_FIRST_CHILD
+0x100) &&
2068 (cmd
<SC_SIZE
|| cmd
>SC_RESTORE
))
2069 MessageBox(hwnd
, RS(b2
,IDS_NO_IMPL
), RS(b1
,IDS_WINEFILE
), MB_OK
);
2071 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2076 resize_frame(hwnd
, LOWORD(lparam
), HIWORD(lparam
));
2077 break; /* do not pass message to DefFrameProc */
2079 #ifndef _NO_EXTENSIONS
2080 case WM_GETMINMAXINFO
: {
2081 LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
2083 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2084 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2087 case FRM_CALC_CLIENT
:
2088 frame_get_clientspace(hwnd
, (PRECT
)lparam
);
2090 #endif /* _NO_EXTENSIONS */
2093 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2100 static TCHAR g_pos_names
[COLUMNS
][20] = {
2104 static const int g_pos_align
[] = {
2106 HDF_LEFT
, /* Name */
2107 HDF_RIGHT
, /* Size */
2108 HDF_LEFT
, /* CDate */
2109 #ifndef _NO_EXTENSIONS
2110 HDF_LEFT
, /* ADate */
2111 HDF_LEFT
, /* MDate */
2112 HDF_LEFT
, /* Index */
2113 HDF_CENTER
, /* Links */
2115 HDF_CENTER
, /* Attributes */
2116 #ifndef _NO_EXTENSIONS
2117 HDF_LEFT
/* Security */
2121 static void resize_tree(ChildWnd
* child
, int cx
, int cy
)
2123 HDWP hdwp
= BeginDeferWindowPos(4);
2131 cx
= child
->split_pos
+ SPLIT_WIDTH
/2;
2133 #ifndef _NO_EXTENSIONS
2141 Header_Layout(child
->left
.hwndHeader
, &hdl
);
2143 DeferWindowPos(hdwp
, child
->left
.hwndHeader
, wp
.hwndInsertAfter
,
2144 wp
.x
-1, wp
.y
, child
->split_pos
-SPLIT_WIDTH
/2+1, wp
.cy
, wp
.flags
);
2145 DeferWindowPos(hdwp
, child
->right
.hwndHeader
, wp
.hwndInsertAfter
,
2146 rt
.left
+cx
+1, wp
.y
, wp
.cx
-cx
+2, wp
.cy
, wp
.flags
);
2148 #endif /* _NO_EXTENSIONS */
2150 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
);
2151 DeferWindowPos(hdwp
, child
->right
.hwnd
, 0, rt
.left
+cx
+1, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
2153 EndDeferWindowPos(hdwp
);
2157 #ifndef _NO_EXTENSIONS
2159 static HWND
create_header(HWND parent
, Pane
* pane
, int id
)
2164 HWND hwnd
= CreateWindow(WC_HEADER
, 0, WS_CHILD
|WS_VISIBLE
|HDS_HORZ
/*TODO: |HDS_BUTTONS + sort orders*/,
2165 0, 0, 0, 0, parent
, (HMENU
)id
, Globals
.hInstance
, 0);
2169 SetWindowFont(hwnd
, GetStockObject(DEFAULT_GUI_FONT
), FALSE
);
2171 hdi
.mask
= HDI_TEXT
|HDI_WIDTH
|HDI_FORMAT
;
2173 for(idx
=0; idx
<COLUMNS
; idx
++) {
2174 hdi
.pszText
= g_pos_names
[idx
];
2175 hdi
.fmt
= HDF_STRING
| g_pos_align
[idx
];
2176 hdi
.cxy
= pane
->widths
[idx
];
2177 Header_InsertItem(hwnd
, idx
, &hdi
);
2183 #endif /* _NO_EXTENSIONS */
2186 static void init_output(HWND hwnd
)
2188 const static TCHAR s1000
[] = {'1','0','0','0','\0'};
2192 HDC hdc
= GetDC(hwnd
);
2194 if (GetNumberFormat(LOCALE_USER_DEFAULT
, 0, s1000
, 0, b
, 16) > 4)
2195 Globals
.num_sep
= b
[1];
2197 Globals
.num_sep
= TEXT('.');
2199 old_font
= SelectFont(hdc
, Globals
.hfont
);
2200 GetTextExtentPoint32(hdc
, sSpace
, 1, &Globals
.spaceSize
);
2201 SelectFont(hdc
, old_font
);
2202 ReleaseDC(hwnd
, hdc
);
2205 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
);
2208 /* calculate preferred width for all visible columns */
2210 static BOOL
calc_widths(Pane
* pane
, BOOL anyway
)
2212 int col
, x
, cx
, spc
=3*Globals
.spaceSize
.cx
;
2213 int entries
= ListBox_GetCount(pane
->hwnd
);
2214 int orgWidths
[COLUMNS
];
2215 int orgPositions
[COLUMNS
+1];
2221 memcpy(orgWidths
, pane
->widths
, sizeof(orgWidths
));
2222 memcpy(orgPositions
, pane
->positions
, sizeof(orgPositions
));
2225 for(col
=0; col
<COLUMNS
; col
++)
2226 pane
->widths
[col
] = 0;
2228 hdc
= GetDC(pane
->hwnd
);
2229 hfontOld
= SelectFont(hdc
, Globals
.hfont
);
2231 for(cnt
=0; cnt
<entries
; cnt
++) {
2232 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, cnt
);
2241 dis
.hwndItem
= pane
->hwnd
;
2243 dis
.rcItem
.left
= 0;
2245 dis
.rcItem
.right
= 0;
2246 dis
.rcItem
.bottom
= 0;
2247 /*dis.itemData = 0; */
2249 draw_item(pane
, &dis
, entry
, COLUMNS
);
2252 SelectObject(hdc
, hfontOld
);
2253 ReleaseDC(pane
->hwnd
, hdc
);
2256 for(col
=0; col
<COLUMNS
; col
++) {
2257 pane
->positions
[col
] = x
;
2258 cx
= pane
->widths
[col
];
2263 if (cx
< IMAGE_WIDTH
)
2266 pane
->widths
[col
] = cx
;
2272 pane
->positions
[COLUMNS
] = x
;
2274 ListBox_SetHorizontalExtent(pane
->hwnd
, x
);
2277 if (!memcmp(orgWidths
, pane
->widths
, sizeof(orgWidths
)))
2280 /* don't move, if only collapsing an entry */
2281 if (!anyway
&& pane
->widths
[0]<orgWidths
[0] &&
2282 !memcmp(orgWidths
+1, pane
->widths
+1, sizeof(orgWidths
)-sizeof(int))) {
2283 pane
->widths
[0] = orgWidths
[0];
2284 memcpy(pane
->positions
, orgPositions
, sizeof(orgPositions
));
2289 InvalidateRect(pane
->hwnd
, 0, TRUE
);
2295 /* calculate one preferred column width */
2297 static void calc_single_width(Pane
* pane
, int col
)
2301 int entries
= ListBox_GetCount(pane
->hwnd
);
2305 pane
->widths
[col
] = 0;
2307 hdc
= GetDC(pane
->hwnd
);
2308 hfontOld
= SelectFont(hdc
, Globals
.hfont
);
2310 for(cnt
=0; cnt
<entries
; cnt
++) {
2311 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, cnt
);
2319 dis
.hwndItem
= pane
->hwnd
;
2321 dis
.rcItem
.left
= 0;
2323 dis
.rcItem
.right
= 0;
2324 dis
.rcItem
.bottom
= 0;
2325 /*dis.itemData = 0; */
2327 draw_item(pane
, &dis
, entry
, col
);
2330 SelectObject(hdc
, hfontOld
);
2331 ReleaseDC(pane
->hwnd
, hdc
);
2333 cx
= pane
->widths
[col
];
2336 cx
+= 3*Globals
.spaceSize
.cx
;
2338 if (cx
< IMAGE_WIDTH
)
2342 pane
->widths
[col
] = cx
;
2344 x
= pane
->positions
[col
] + cx
;
2346 for(; col
<COLUMNS
; ) {
2347 pane
->positions
[++col
] = x
;
2348 x
+= pane
->widths
[col
];
2351 ListBox_SetHorizontalExtent(pane
->hwnd
, x
);
2355 /* insert listbox entries after index idx */
2357 static int insert_entries(Pane
* pane
, Entry
* dir
, int idx
)
2364 ShowWindow(pane
->hwnd
, SW_HIDE
);
2366 for(; entry
; entry
=entry
->next
) {
2368 if (pane
->treePane
&& !(entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
2372 /* don't display entries "." and ".." in the left pane */
2373 if (pane
->treePane
&& (entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
)
2374 && entry
->data
.cFileName
[0]==TEXT('.'))
2376 #ifndef _NO_EXTENSIONS
2377 entry
->data
.cFileName
[1]==TEXT('\0') ||
2379 (entry
->data
.cFileName
[1]==TEXT('.') && entry
->data
.cFileName
[2]==TEXT('\0')))
2385 ListBox_InsertItemData(pane
->hwnd
, idx
, entry
);
2387 if (pane
->treePane
&& entry
->expanded
)
2388 idx
= insert_entries(pane
, entry
->down
, idx
);
2391 ShowWindow(pane
->hwnd
, SW_SHOW
);
2397 static WNDPROC g_orgTreeWndProc
;
2399 static void create_tree_window(HWND parent
, Pane
* pane
, int id
, int id_header
)
2401 const static TCHAR sListBox
[] = {'L','i','s','t','B','o','x','\0'};
2403 static int s_init
= 0;
2404 Entry
* entry
= pane
->root
;
2406 pane
->hwnd
= CreateWindow(sListBox
, sEmpty
, WS_CHILD
|WS_VISIBLE
|WS_HSCROLL
|WS_VSCROLL
|
2407 LBS_DISABLENOSCROLL
|LBS_NOINTEGRALHEIGHT
|LBS_OWNERDRAWFIXED
|LBS_NOTIFY
,
2408 0, 0, 0, 0, parent
, (HMENU
)id
, Globals
.hInstance
, 0);
2410 SetWindowLong(pane
->hwnd
, GWL_USERDATA
, (LPARAM
)pane
);
2411 g_orgTreeWndProc
= SubclassWindow(pane
->hwnd
, TreeWndProc
);
2413 SetWindowFont(pane
->hwnd
, Globals
.hfont
, FALSE
);
2415 /* insert entries into listbox */
2417 insert_entries(pane
, entry
, -1);
2419 /* calculate column widths */
2422 init_output(pane
->hwnd
);
2425 calc_widths(pane
, TRUE
);
2427 #ifndef _NO_EXTENSIONS
2428 pane
->hwndHeader
= create_header(parent
, pane
, id_header
);
2433 static void InitChildWindow(ChildWnd
* child
)
2435 create_tree_window(child
->hwnd
, &child
->left
, IDW_TREE_LEFT
, IDW_HEADER_LEFT
);
2436 create_tree_window(child
->hwnd
, &child
->right
, IDW_TREE_RIGHT
, IDW_HEADER_RIGHT
);
2440 static void format_date(const FILETIME
* ft
, TCHAR
* buffer
, int visible_cols
)
2446 *buffer
= TEXT('\0');
2448 if (!ft
->dwLowDateTime
&& !ft
->dwHighDateTime
)
2451 if (!FileTimeToLocalFileTime(ft
, &lft
))
2452 {err
: _tcscpy(buffer
,sQMarks
); return;}
2454 if (!FileTimeToSystemTime(&lft
, &systime
))
2457 if (visible_cols
& COL_DATE
) {
2458 len
= GetDateFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
, BUFFER_LEN
);
2463 if (visible_cols
& COL_TIME
) {
2465 buffer
[len
-1] = ' ';
2467 buffer
[len
++] = ' ';
2469 if (!GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
+len
, BUFFER_LEN
-len
))
2470 buffer
[len
] = TEXT('\0');
2475 static void calc_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2477 RECT rt
= {0, 0, 0, 0};
2479 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
2481 if (rt
.right
> pane
->widths
[col
])
2482 pane
->widths
[col
] = rt
.right
;
2485 static void calc_tabbed_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2487 RECT rt
= {0, 0, 0, 0};
2489 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2490 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2492 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2493 /*FIXME rt (0,0) ??? */
2495 if (rt
.right
> pane
->widths
[col
])
2496 pane
->widths
[col
] = rt
.right
;
2500 static void output_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
, DWORD flags
)
2502 int x
= dis
->rcItem
.left
;
2505 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2506 rt
.top
= dis
->rcItem
.top
;
2507 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2508 rt
.bottom
= dis
->rcItem
.bottom
;
2510 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_SINGLELINE
|DT_NOPREFIX
|flags
);
2513 static void output_tabbed_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2515 int x
= dis
->rcItem
.left
;
2518 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2519 rt
.top
= dis
->rcItem
.top
;
2520 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2521 rt
.bottom
= dis
->rcItem
.bottom
;
2523 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2524 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2526 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2529 static void output_number(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2531 int x
= dis
->rcItem
.left
;
2538 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2539 rt
.top
= dis
->rcItem
.top
;
2540 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2541 rt
.bottom
= dis
->rcItem
.bottom
;
2546 /* insert number separator characters */
2547 pos
= lstrlen(s
) % 3;
2553 *d
++ = Globals
.num_sep
;
2557 DrawText(dis
->hDC
, b
, d
-b
, &rt
, DT_RIGHT
|DT_SINGLELINE
|DT_NOPREFIX
|DT_END_ELLIPSIS
);
2561 static int is_exe_file(LPCTSTR ext
)
2563 static const TCHAR executable_extensions
[][4] = {
2568 #ifndef _NO_EXTENSIONS
2572 #endif /* _NO_EXTENSIONS */
2576 TCHAR ext_buffer
[_MAX_EXT
];
2577 const TCHAR (*p
)[4];
2581 for(s
=ext
+1,d
=ext_buffer
; (*d
=tolower(*s
)); s
++)
2584 for(p
=executable_extensions
; (*p
)[0]; p
++)
2585 if (!_tcscmp(ext_buffer
, *p
))
2591 static int is_registered_type(LPCTSTR ext
)
2599 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
)
2601 TCHAR buffer
[BUFFER_LEN
];
2603 int visible_cols
= pane
->visible_cols
;
2604 COLORREF bkcolor
, textcolor
;
2605 RECT focusRect
= dis
->rcItem
;
2612 attrs
= entry
->data
.dwFileAttributes
;
2614 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) {
2615 if (entry
->data
.cFileName
[0]==TEXT('.') && entry
->data
.cFileName
[1]==TEXT('.')
2616 && entry
->data
.cFileName
[2]==TEXT('\0'))
2617 img
= IMG_FOLDER_UP
;
2618 #ifndef _NO_EXTENSIONS
2619 else if (entry
->data
.cFileName
[0]==TEXT('.') && entry
->data
.cFileName
[1]==TEXT('\0'))
2620 img
= IMG_FOLDER_CUR
;
2623 #ifdef _NO_EXTENSIONS
2626 (pane
->treePane
&& (dis
->itemState
&ODS_FOCUS
)))
2627 img
= IMG_OPEN_FOLDER
;
2631 LPCTSTR ext
= _tcsrchr(entry
->data
.cFileName
, '.');
2635 if (is_exe_file(ext
))
2636 img
= IMG_EXECUTABLE
;
2637 else if (is_registered_type(ext
))
2647 if (pane
->treePane
) {
2649 img_pos
= dis
->rcItem
.left
+ entry
->level
*(IMAGE_WIDTH
+TREE_LINE_DX
);
2651 if (calcWidthCol
== -1) {
2653 int y
= dis
->rcItem
.top
+ IMAGE_HEIGHT
/2;
2656 HRGN hrgn_org
= CreateRectRgn(0, 0, 0, 0);
2659 rt_clip
.left
= dis
->rcItem
.left
;
2660 rt_clip
.top
= dis
->rcItem
.top
;
2661 rt_clip
.right
= dis
->rcItem
.left
+pane
->widths
[col
];
2662 rt_clip
.bottom
= dis
->rcItem
.bottom
;
2664 hrgn
= CreateRectRgnIndirect(&rt_clip
);
2666 if (!GetClipRgn(dis
->hDC
, hrgn_org
)) {
2667 DeleteObject(hrgn_org
);
2671 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
2672 ExtSelectClipRgn(dis
->hDC
, hrgn
, RGN_AND
);
2675 if ((up
=entry
->up
) != NULL
) {
2676 MoveToEx(dis
->hDC
, img_pos
-IMAGE_WIDTH
/2, y
, 0);
2677 LineTo(dis
->hDC
, img_pos
-2, y
);
2679 x
= img_pos
- IMAGE_WIDTH
/2;
2682 x
-= IMAGE_WIDTH
+TREE_LINE_DX
;
2686 && (up
->next
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
2689 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
2690 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
2692 } while((up
=up
->up
) != NULL
);
2695 x
= img_pos
- IMAGE_WIDTH
/2;
2697 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
2698 LineTo(dis
->hDC
, x
, y
);
2702 && (entry
->next
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
)
2705 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
2707 if (entry
->down
&& entry
->expanded
) {
2708 x
+= IMAGE_WIDTH
+TREE_LINE_DX
;
2709 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
+IMAGE_HEIGHT
, 0);
2710 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
2713 SelectClipRgn(dis
->hDC
, hrgn_org
);
2714 if (hrgn_org
) DeleteObject(hrgn_org
);
2715 /* SelectObject(dis->hDC, holdPen); */
2716 } else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
) {
2717 int right
= img_pos
+ IMAGE_WIDTH
- TREE_LINE_DX
;
2719 if (right
> pane
->widths
[col
])
2720 pane
->widths
[col
] = right
;
2723 img_pos
= dis
->rcItem
.left
;
2726 img_pos
= dis
->rcItem
.left
;
2728 if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2729 pane
->widths
[col
] = IMAGE_WIDTH
;
2732 if (calcWidthCol
== -1) {
2733 focusRect
.left
= img_pos
- 2;
2735 #ifdef _NO_EXTENSIONS
2736 if (pane
->treePane
&& entry
) {
2739 DrawText(dis
->hDC
, entry
->data
.cFileName
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
2741 focusRect
.right
= dis
->rcItem
.left
+pane
->positions
[col
+1]+TREE_LINE_DX
+ rt
.right
+2;
2745 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
)
2746 textcolor
= COLOR_COMPRESSED
;
2748 #endif /* _NO_EXTENSIONS */
2749 textcolor
= RGB(0,0,0);
2751 if (dis
->itemState
& ODS_FOCUS
) {
2752 textcolor
= RGB(255,255,255);
2753 bkcolor
= COLOR_SELECTION
;
2755 bkcolor
= RGB(255,255,255);
2758 hbrush
= CreateSolidBrush(bkcolor
);
2759 FillRect(dis
->hDC
, &focusRect
, hbrush
);
2760 DeleteObject(hbrush
);
2762 SetBkMode(dis
->hDC
, TRANSPARENT
);
2763 SetTextColor(dis
->hDC
, textcolor
);
2765 cx
= pane
->widths
[col
];
2767 if (cx
&& img
!=IMG_NONE
) {
2768 if (cx
> IMAGE_WIDTH
)
2771 #ifdef _SHELL_FOLDERS
2772 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
2773 DrawIconEx(dis
->hDC
, img_pos
, dis
->rcItem
.top
, entry
->hicon
, cx
, GetSystemMetrics(SM_CYSMICON
), 0, 0, DI_NORMAL
);
2776 ImageList_DrawEx(Globals
.himl
, img
, dis
->hDC
,
2777 img_pos
, dis
->rcItem
.top
, cx
,
2778 IMAGE_HEIGHT
, bkcolor
, CLR_DEFAULT
, ILD_NORMAL
);
2785 #ifdef _NO_EXTENSIONS
2786 if (img
>= IMG_FOLDER_UP
)
2792 /* ouput file name */
2793 if (calcWidthCol
== -1)
2794 output_text(pane
, dis
, col
, entry
->data
.cFileName
, 0);
2795 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2796 calc_width(pane
, dis
, col
, entry
->data
.cFileName
);
2800 #ifdef _NO_EXTENSIONS
2801 if (!pane
->treePane
) {
2804 /* display file size */
2805 if (visible_cols
& COL_SIZE
) {
2806 #ifdef _NO_EXTENSIONS
2807 if (!(attrs
&FILE_ATTRIBUTE_DIRECTORY
))
2812 size
= ((ULONGLONG
)entry
->data
.nFileSizeHigh
<< 32) | entry
->data
.nFileSizeLow
;
2814 _stprintf(buffer
, sLongNumFmt
, size
);
2816 if (calcWidthCol
== -1)
2817 output_number(pane
, dis
, col
, buffer
);
2818 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2819 calc_width(pane
, dis
, col
, buffer
);/*TODO: not in every case time enough */
2825 /* display file date */
2826 if (visible_cols
& (COL_DATE
|COL_TIME
)) {
2827 #ifndef _NO_EXTENSIONS
2828 format_date(&entry
->data
.ftCreationTime
, buffer
, visible_cols
);
2829 if (calcWidthCol
== -1)
2830 output_text(pane
, dis
, col
, buffer
, 0);
2831 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2832 calc_width(pane
, dis
, col
, buffer
);
2835 format_date(&entry
->data
.ftLastAccessTime
, buffer
, visible_cols
);
2836 if (calcWidthCol
== -1)
2837 output_text(pane
, dis
, col
, buffer
, 0);
2838 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2839 calc_width(pane
, dis
, col
, buffer
);
2841 #endif /* _NO_EXTENSIONS */
2843 format_date(&entry
->data
.ftLastWriteTime
, buffer
, visible_cols
);
2844 if (calcWidthCol
== -1)
2845 output_text(pane
, dis
, col
, buffer
, 0);
2846 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2847 calc_width(pane
, dis
, col
, buffer
);
2851 #ifndef _NO_EXTENSIONS
2852 if (entry
->bhfi_valid
) {
2853 ULONGLONG index
= ((ULONGLONG
)entry
->bhfi
.nFileIndexHigh
<< 32) | entry
->bhfi
.nFileIndexLow
;
2855 if (visible_cols
& COL_INDEX
) {
2856 _stprintf(buffer
, sLongHexFmt
, index
);
2858 if (calcWidthCol
== -1)
2859 output_text(pane
, dis
, col
, buffer
, DT_RIGHT
);
2860 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2861 calc_width(pane
, dis
, col
, buffer
);
2866 if (visible_cols
& COL_LINKS
) {
2867 wsprintf(buffer
, sNumFmt
, entry
->bhfi
.nNumberOfLinks
);
2869 if (calcWidthCol
== -1)
2870 output_text(pane
, dis
, col
, buffer
, DT_CENTER
);
2871 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2872 calc_width(pane
, dis
, col
, buffer
);
2878 #endif /* _NO_EXTENSIONS */
2880 /* show file attributes */
2881 if (visible_cols
& COL_ATTRIBUTES
) {
2882 #ifdef _NO_EXTENSIONS
2883 const static TCHAR s4Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
2884 _tcscpy(buffer
, s4Tabs
);
2886 const static TCHAR s11Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
2887 _tcscpy(buffer
, s11Tabs
);
2890 if (attrs
& FILE_ATTRIBUTE_NORMAL
) buffer
[ 0] = 'N';
2892 if (attrs
& FILE_ATTRIBUTE_READONLY
) buffer
[ 2] = 'R';
2893 if (attrs
& FILE_ATTRIBUTE_HIDDEN
) buffer
[ 4] = 'H';
2894 if (attrs
& FILE_ATTRIBUTE_SYSTEM
) buffer
[ 6] = 'S';
2895 if (attrs
& FILE_ATTRIBUTE_ARCHIVE
) buffer
[ 8] = 'A';
2896 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
) buffer
[10] = 'C';
2897 #ifndef _NO_EXTENSIONS
2898 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) buffer
[12] = 'D';
2899 if (attrs
& FILE_ATTRIBUTE_ENCRYPTED
) buffer
[14] = 'E';
2900 if (attrs
& FILE_ATTRIBUTE_TEMPORARY
) buffer
[16] = 'T';
2901 if (attrs
& FILE_ATTRIBUTE_SPARSE_FILE
) buffer
[18] = 'P';
2902 if (attrs
& FILE_ATTRIBUTE_REPARSE_POINT
) buffer
[20] = 'Q';
2903 if (attrs
& FILE_ATTRIBUTE_OFFLINE
) buffer
[22] = 'O';
2904 if (attrs
& FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
) buffer
[24] = 'X';
2905 #endif /* _NO_EXTENSIONS */
2908 if (calcWidthCol
== -1)
2909 output_tabbed_text(pane
, dis
, col
, buffer
);
2910 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2911 calc_tabbed_width(pane
, dis
, col
, buffer
);
2917 if (flags.security) {
2918 const static TCHAR sSecTabs[] = {
2919 ' ','\t',' ','\t',' ','\t',' ',
2921 ' ','\t',' ','\t',' ','\t',' ',
2923 ' ','\t',' ','\t',' ','\t',' ',
2927 DWORD rights = get_access_mask();
2929 tcscpy(buffer, sSecTabs);
2931 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
2932 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
2933 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
2934 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
2935 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
2936 if (rights & FILE_EXECUTE) buffer[12] = 'X';
2937 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
2938 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
2939 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
2940 if (rights & WRITE_DAC) buffer[22] = 'C';
2941 if (rights & WRITE_OWNER) buffer[24] = 'O';
2942 if (rights & SYNCHRONIZE) buffer[26] = 'S';
2944 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
2947 if (flags.description) {
2948 get_description(buffer);
2949 output_text(dis, col++, buffer, 0, psize);
2953 #ifdef _NO_EXTENSIONS
2956 /* draw focus frame */
2957 if ((dis
->itemState
&ODS_FOCUS
) && calcWidthCol
==-1) {
2958 /* Currently [04/2000] Wine neither behaves exactly the same */
2959 /* way as WIN 95 nor like Windows NT... */
2964 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
2965 LOGBRUSH lb
= {PS_SOLID
, RGB(255,255,255)};
2966 hpen
= ExtCreatePen(PS_COSMETIC
|PS_ALTERNATE
, 1, &lb
, 0, 0);
2968 hpen
= CreatePen(PS_DOT
, 0, RGB(255,255,255));
2970 lastPen
= SelectPen(dis
->hDC
, hpen
);
2971 lastBrush
= SelectObject(dis
->hDC
, GetStockObject(HOLLOW_BRUSH
));
2972 SetROP2(dis
->hDC
, R2_XORPEN
);
2973 Rectangle(dis
->hDC
, focusRect
.left
, focusRect
.top
, focusRect
.right
, focusRect
.bottom
);
2974 SelectObject(dis
->hDC
, lastBrush
);
2975 SelectObject(dis
->hDC
, lastPen
);
2978 #endif /* _NO_EXTENSIONS */
2982 #ifdef _NO_EXTENSIONS
2984 static void draw_splitbar(HWND hwnd
, int x
)
2987 HDC hdc
= GetDC(hwnd
);
2989 GetClientRect(hwnd
, &rt
);
2991 rt
.left
= x
- SPLIT_WIDTH
/2;
2992 rt
.right
= x
+ SPLIT_WIDTH
/2+1;
2994 InvertRect(hdc
, &rt
);
2996 ReleaseDC(hwnd
, hdc
);
2999 #endif /* _NO_EXTENSIONS */
3002 #ifndef _NO_EXTENSIONS
3004 static void set_header(Pane
* pane
)
3007 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3010 item
.mask
= HDI_WIDTH
;
3013 for(; x
+pane
->widths
[i
]<scroll_pos
&& i
<COLUMNS
; i
++) {
3014 x
+= pane
->widths
[i
];
3015 Header_SetItem(pane
->hwndHeader
, i
, &item
);
3019 x
+= pane
->widths
[i
];
3020 item
.cxy
= x
- scroll_pos
;
3021 Header_SetItem(pane
->hwndHeader
, i
++, &item
);
3023 for(; i
<COLUMNS
; i
++) {
3024 item
.cxy
= pane
->widths
[i
];
3025 x
+= pane
->widths
[i
];
3026 Header_SetItem(pane
->hwndHeader
, i
, &item
);
3031 static LRESULT
pane_notify(Pane
* pane
, NMHDR
* pnmh
)
3033 switch(pnmh
->code
) {
3035 case HDN_ENDTRACK
: {
3036 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3037 int idx
= phdn
->iItem
;
3038 int dx
= phdn
->pitem
->cxy
- pane
->widths
[idx
];
3042 GetClientRect(pane
->hwnd
, &clnt
);
3044 /* move immediate to simulate HDS_FULLDRAG (for now [04/2000] not really needed with WINELIB) */
3045 Header_SetItem(pane
->hwndHeader
, idx
, phdn
->pitem
);
3047 pane
->widths
[idx
] += dx
;
3049 for(i
=idx
; ++i
<=COLUMNS
; )
3050 pane
->positions
[i
] += dx
;
3053 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3057 rt_scr
.left
= pane
->positions
[idx
+1]-scroll_pos
;
3059 rt_scr
.right
= clnt
.right
;
3060 rt_scr
.bottom
= clnt
.bottom
;
3062 rt_clip
.left
= pane
->positions
[idx
]-scroll_pos
;
3064 rt_clip
.right
= clnt
.right
;
3065 rt_clip
.bottom
= clnt
.bottom
;
3067 if (rt_scr
.left
< 0) rt_scr
.left
= 0;
3068 if (rt_clip
.left
< 0) rt_clip
.left
= 0;
3070 ScrollWindowEx(pane
->hwnd
, dx
, 0, &rt_scr
, &rt_clip
, 0, 0, SW_INVALIDATE
);
3072 rt_clip
.right
= pane
->positions
[idx
+1];
3073 RedrawWindow(pane
->hwnd
, &rt_clip
, 0, RDW_INVALIDATE
|RDW_UPDATENOW
);
3075 if (pnmh
->code
== HDN_ENDTRACK
) {
3076 ListBox_SetHorizontalExtent(pane
->hwnd
, pane
->positions
[COLUMNS
]);
3078 if (GetScrollPos(pane
->hwnd
, SB_HORZ
) != scroll_pos
)
3086 case HDN_DIVIDERDBLCLICK
: {
3087 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3090 calc_single_width(pane
, phdn
->iItem
);
3091 item
.mask
= HDI_WIDTH
;
3092 item
.cxy
= pane
->widths
[phdn
->iItem
];
3094 Header_SetItem(pane
->hwndHeader
, phdn
->iItem
, &item
);
3095 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3102 #endif /* _NO_EXTENSIONS */
3105 static void scan_entry(ChildWnd
* child
, Entry
* entry
, HWND hwnd
)
3107 TCHAR path
[MAX_PATH
];
3108 int idx
= ListBox_GetCurSel(child
->left
.hwnd
);
3109 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
3111 /* delete sub entries in left pane */
3113 LRESULT res
= ListBox_GetItemData(child
->left
.hwnd
, idx
+1);
3114 Entry
* sub
= (Entry
*) res
;
3116 if (res
==LB_ERR
|| !sub
|| sub
->level
<=entry
->level
)
3119 ListBox_DeleteString(child
->left
.hwnd
, idx
+1);
3122 /* empty right pane */
3123 ListBox_ResetContent(child
->right
.hwnd
);
3125 /* release memory */
3126 free_entries(entry
);
3128 /* read contents from disk */
3129 #ifdef _SHELL_FOLDERS
3130 if (entry
->etype
== ET_SHELL
)
3132 read_directory(entry
, NULL
, child
->sortOrder
, hwnd
);
3137 get_path(entry
, path
);
3138 read_directory(entry
, path
, child
->sortOrder
, hwnd
);
3141 /* insert found entries in right pane */
3142 insert_entries(&child
->right
, entry
->down
, -1);
3143 calc_widths(&child
->right
, FALSE
);
3144 #ifndef _NO_EXTENSIONS
3145 set_header(&child
->right
);
3148 child
->header_wdths_ok
= FALSE
;
3150 SetCursor(old_cursor
);
3154 /* expand a directory entry */
3156 static BOOL
expand_entry(ChildWnd
* child
, Entry
* dir
)
3161 if (!dir
|| dir
->expanded
|| !dir
->down
)
3166 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='\0' && p
->next
) {
3169 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='.' &&
3170 p
->data
.cFileName
[2]=='\0' && p
->next
)
3174 /* no subdirectories ? */
3175 if (!(p
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
3178 idx
= ListBox_FindItemData(child
->left
.hwnd
, 0, dir
);
3180 dir
->expanded
= TRUE
;
3182 /* insert entries in left pane */
3183 insert_entries(&child
->left
, p
, idx
);
3185 if (!child
->header_wdths_ok
) {
3186 if (calc_widths(&child
->left
, FALSE
)) {
3187 #ifndef _NO_EXTENSIONS
3188 set_header(&child
->left
);
3191 child
->header_wdths_ok
= TRUE
;
3199 static void collapse_entry(Pane
* pane
, Entry
* dir
)
3201 int idx
= ListBox_FindItemData(pane
->hwnd
, 0, dir
);
3203 ShowWindow(pane
->hwnd
, SW_HIDE
);
3205 /* hide sub entries */
3207 LRESULT res
= ListBox_GetItemData(pane
->hwnd
, idx
+1);
3208 Entry
* sub
= (Entry
*) res
;
3210 if (res
==LB_ERR
|| !sub
|| sub
->level
<=dir
->level
)
3213 ListBox_DeleteString(pane
->hwnd
, idx
+1);
3216 dir
->expanded
= FALSE
;
3218 ShowWindow(pane
->hwnd
, SW_SHOW
);
3222 static void set_curdir(ChildWnd
* child
, Entry
* entry
, HWND hwnd
)
3224 TCHAR path
[MAX_PATH
];
3228 child
->left
.cur
= entry
;
3229 child
->right
.root
= entry
->down
? entry
->down
: entry
;
3230 child
->right
.cur
= entry
;
3232 if (!entry
->scanned
)
3233 scan_entry(child
, entry
, hwnd
);
3235 ListBox_ResetContent(child
->right
.hwnd
);
3236 insert_entries(&child
->right
, entry
->down
, -1);
3237 calc_widths(&child
->right
, FALSE
);
3238 #ifndef _NO_EXTENSIONS
3239 set_header(&child
->right
);
3243 get_path(entry
, path
);
3244 lstrcpy(child
->path
, path
);
3246 if (child
->hwnd
) /* only change window title, if the window already exists */
3247 SetWindowText(child
->hwnd
, path
);
3250 SetCurrentDirectory(path
);
3254 BOOL
launch_file(HWND hwnd
, LPCTSTR cmd
, UINT nCmdShow
)
3256 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3258 if ((int)hinst
<= 32) {
3259 display_error(hwnd
, GetLastError());
3267 BOOL
launch_fileA(HWND hwnd
, LPSTR cmd
, UINT nCmdShow
)
3269 HINSTANCE hinst
= ShellExecuteA(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3271 if ((int)hinst
<= 32) {
3272 display_error(hwnd
, GetLastError());
3281 BOOL
launch_entry(Entry
* entry
, HWND hwnd
, UINT nCmdShow
)
3283 TCHAR cmd
[MAX_PATH
];
3285 #ifdef _SHELL_FOLDERS
3286 if (entry
->etype
== ET_SHELL
) {
3289 SHELLEXECUTEINFO shexinfo
;
3291 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFO
);
3292 shexinfo
.fMask
= SEE_MASK_IDLIST
;
3293 shexinfo
.hwnd
= hwnd
;
3294 shexinfo
.lpVerb
= NULL
;
3295 shexinfo
.lpFile
= NULL
;
3296 shexinfo
.lpParameters
= NULL
;
3297 shexinfo
.lpDirectory
= NULL
;
3298 shexinfo
.nShow
= nCmdShow
;
3299 shexinfo
.lpIDList
= get_to_absolute_pidl(entry
, hwnd
);
3301 if (!ShellExecuteEx(&shexinfo
)) {
3302 display_error(hwnd
, GetLastError());
3306 if (shexinfo
.lpIDList
!= entry
->pidl
)
3307 (*Globals
.iMalloc
->lpVtbl
->Free
)(Globals
.iMalloc
, shexinfo
.lpIDList
);
3313 get_path(entry
, cmd
);
3315 /* start program, open document... */
3316 return launch_file(hwnd
, cmd
, nCmdShow
);
3320 static void activate_entry(ChildWnd
* child
, Pane
* pane
, HWND hwnd
)
3322 Entry
* entry
= pane
->cur
;
3327 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
3328 int scanned_old
= entry
->scanned
;
3331 scan_entry(child
, entry
, hwnd
);
3333 #ifndef _NO_EXTENSIONS
3334 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='\0')
3338 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='.' && entry
->data
.cFileName
[2]=='\0') {
3339 entry
= child
->left
.cur
->up
;
3340 collapse_entry(&child
->left
, entry
);
3342 } else if (entry
->expanded
)
3343 collapse_entry(pane
, child
->left
.cur
);
3345 expand_entry(child
, child
->left
.cur
);
3347 if (!pane
->treePane
) focus_entry
: {
3348 int idx
= ListBox_FindItemData(child
->left
.hwnd
, ListBox_GetCurSel(child
->left
.hwnd
), entry
);
3349 ListBox_SetCurSel(child
->left
.hwnd
, idx
);
3350 set_curdir(child
, entry
, hwnd
);
3355 calc_widths(pane
, FALSE
);
3357 #ifndef _NO_EXTENSIONS
3362 launch_entry(entry
, child
->hwnd
, SW_SHOWNORMAL
);
3367 static BOOL
pane_command(Pane
* pane
, UINT cmd
)
3371 if (pane
->visible_cols
) {
3372 pane
->visible_cols
= 0;
3373 calc_widths(pane
, TRUE
);
3374 #ifndef _NO_EXTENSIONS
3377 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3378 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
|MF_CHECKED
);
3379 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
);
3380 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
3384 case ID_VIEW_ALL_ATTRIBUTES
:
3385 if (pane
->visible_cols
!= COL_ALL
) {
3386 pane
->visible_cols
= COL_ALL
;
3387 calc_widths(pane
, TRUE
);
3388 #ifndef _NO_EXTENSIONS
3391 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3392 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
);
3393 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
|MF_CHECKED
);
3394 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
3398 #ifndef _NO_EXTENSIONS
3399 case ID_PREFERRED_SIZES
: {
3400 calc_widths(pane
, TRUE
);
3402 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3406 /* TODO: more command ids... */
3416 static IContextMenu2
* s_pctxmenu2
= NULL
;
3418 #ifndef __MINGW32__ // IContextMenu3 missing in MinGW (as of 6.2.2005)
3419 static IContextMenu3
* s_pctxmenu3
= NULL
;
3422 static void CtxMenu_reset()
3426 #ifndef __MINGW32__ // IContextMenu3 missing in MinGW (as of 6.2.2005)
3431 IContextMenu
* CtxMenu_query_interfaces(IContextMenu
* pcm1
)
3433 IContextMenu
* pcm
= NULL
;
3437 #ifndef __MINGW32__ // IContextMenu3 missing in MinGW (as of 6.2.2005)
3438 if ((*pcm1
->lpVtbl
->QueryInterface
)(pcm1
, &IID_IContextMenu3
, (void**)&pcm
) == NOERROR
)
3439 s_pctxmenu3
= (LPCONTEXTMENU3
)pcm
;
3442 if ((*pcm1
->lpVtbl
->QueryInterface
)(pcm1
, &IID_IContextMenu2
, (void**)&pcm
) == NOERROR
)
3443 s_pctxmenu2
= (LPCONTEXTMENU2
)pcm
;
3446 (*pcm1
->lpVtbl
->Release
)(pcm1
);
3452 static BOOL
CtxMenu_HandleMenuMsg(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3454 #ifndef __MINGW32__ // IContextMenu3 missing in MinGW (as of 6.2.2005)
3456 if (SUCCEEDED((*s_pctxmenu3
->lpVtbl
->HandleMenuMsg
)(s_pctxmenu3
, nmsg
, wparam
, lparam
)))
3462 if (SUCCEEDED((*s_pctxmenu2
->lpVtbl
->HandleMenuMsg
)(s_pctxmenu2
, nmsg
, wparam
, lparam
)))
3469 static HRESULT
ShellFolderContextMenu(IShellFolder
* shell_folder
, HWND hwndParent
, int cidl
, LPCITEMIDLIST
* apidl
, int x
, int y
)
3473 HRESULT hr
= (*shell_folder
->lpVtbl
->GetUIObjectOf
)(shell_folder
, hwndParent
, cidl
, apidl
, &IID_IContextMenu
, NULL
, (LPVOID
*)&pcm
);
3474 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
3476 if (SUCCEEDED(hr
)) {
3477 HMENU hmenu
= CreatePopupMenu();
3479 pcm
= CtxMenu_query_interfaces(pcm
);
3482 hr
= (*pcm
->lpVtbl
->QueryContextMenu
)(pcm
, hmenu
, 0, FCIDM_SHVIEWFIRST
, FCIDM_SHVIEWLAST
, CMF_NORMAL
);
3484 if (SUCCEEDED(hr
)) {
3485 UINT idCmd
= TrackPopupMenu(hmenu
, TPM_LEFTALIGN
|TPM_RETURNCMD
|TPM_RIGHTBUTTON
, x
, y
, 0, hwndParent
, NULL
);
3490 CMINVOKECOMMANDINFO cmi
;
3492 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFO
);
3494 cmi
.hwnd
= hwndParent
;
3495 cmi
.lpVerb
= (LPCSTR
)(INT_PTR
)(idCmd
- FCIDM_SHVIEWFIRST
);
3496 cmi
.lpParameters
= NULL
;
3497 cmi
.lpDirectory
= NULL
;
3498 cmi
.nShow
= SW_SHOWNORMAL
;
3502 hr
= (*pcm
->lpVtbl
->InvokeCommand
)(pcm
, &cmi
);
3508 (*pcm
->lpVtbl
->Release
)(pcm
);
3515 LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3517 static int last_split
;
3519 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(hwnd
, GWL_USERDATA
);
3524 LPDRAWITEMSTRUCT dis
= (LPDRAWITEMSTRUCT
)lparam
;
3525 Entry
* entry
= (Entry
*) dis
->itemData
;
3527 if (dis
->CtlID
== IDW_TREE_LEFT
)
3528 draw_item(&child
->left
, dis
, entry
, -1);
3529 else if (dis
->CtlID
== IDW_TREE_RIGHT
)
3530 draw_item(&child
->right
, dis
, entry
, -1);
3532 goto draw_menu_item
;
3537 InitChildWindow(child
);
3541 free_child_window(child
);
3542 SetWindowLong(hwnd
, GWL_USERDATA
, 0);
3549 GetClientRect(hwnd
, &rt
);
3550 BeginPaint(hwnd
, &ps
);
3551 rt
.left
= child
->split_pos
-SPLIT_WIDTH
/2;
3552 rt
.right
= child
->split_pos
+SPLIT_WIDTH
/2+1;
3553 lastBrush
= SelectBrush(ps
.hdc
, (HBRUSH
)GetStockObject(COLOR_SPLITBAR
));
3554 Rectangle(ps
.hdc
, rt
.left
, rt
.top
-1, rt
.right
, rt
.bottom
+1);
3555 SelectObject(ps
.hdc
, lastBrush
);
3556 #ifdef _NO_EXTENSIONS
3557 rt
.top
= rt
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
3558 FillRect(ps
.hdc
, &rt
, GetStockObject(BLACK_BRUSH
));
3560 EndPaint(hwnd
, &ps
);
3564 if (LOWORD(lparam
) == HTCLIENT
) {
3567 ScreenToClient(hwnd
, &pt
);
3569 if (pt
.x
>=child
->split_pos
-SPLIT_WIDTH
/2 && pt
.x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
3570 SetCursor(LoadCursor(0, IDC_SIZEWE
));
3576 case WM_LBUTTONDOWN
: {
3578 int x
= GET_X_LPARAM(lparam
);
3580 GetClientRect(hwnd
, &rt
);
3582 if (x
>=child
->split_pos
-SPLIT_WIDTH
/2 && x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
3583 last_split
= child
->split_pos
;
3584 #ifdef _NO_EXTENSIONS
3585 draw_splitbar(hwnd
, last_split
);
3593 if (GetCapture() == hwnd
) {
3594 #ifdef _NO_EXTENSIONS
3596 int x
= LOWORD(lparam
);
3597 draw_splitbar(hwnd
, last_split
);
3599 GetClientRect(hwnd
, &rt
);
3600 child
->split_pos
= x
;
3601 resize_tree(child
, rt
.right
, rt
.bottom
);
3607 #ifdef _NO_EXTENSIONS
3608 case WM_CAPTURECHANGED
:
3609 if (GetCapture()==hwnd
&& last_split
>=0)
3610 draw_splitbar(hwnd
, last_split
);
3615 if (wparam
== VK_ESCAPE
)
3616 if (GetCapture() == hwnd
) {
3618 #ifdef _NO_EXTENSIONS
3619 draw_splitbar(hwnd
, last_split
);
3621 child
->split_pos
= last_split
;
3623 GetClientRect(hwnd
, &rt
);
3624 resize_tree(child
, rt
.right
, rt
.bottom
);
3627 SetCursor(LoadCursor(0, IDC_ARROW
));
3632 if (GetCapture() == hwnd
) {
3634 int x
= LOWORD(lparam
);
3636 #ifdef _NO_EXTENSIONS
3637 HDC hdc
= GetDC(hwnd
);
3638 GetClientRect(hwnd
, &rt
);
3640 rt
.left
= last_split
-SPLIT_WIDTH
/2;
3641 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
3642 InvertRect(hdc
, &rt
);
3645 rt
.left
= x
-SPLIT_WIDTH
/2;
3646 rt
.right
= x
+SPLIT_WIDTH
/2+1;
3647 InvertRect(hdc
, &rt
);
3649 ReleaseDC(hwnd
, hdc
);
3651 GetClientRect(hwnd
, &rt
);
3653 if (x
>=0 && x
<rt
.right
) {
3654 child
->split_pos
= x
;
3655 resize_tree(child
, rt
.right
, rt
.bottom
);
3656 rt
.left
= x
-SPLIT_WIDTH
/2;
3657 rt
.right
= x
+SPLIT_WIDTH
/2+1;
3658 InvalidateRect(hwnd
, &rt
, FALSE
);
3659 UpdateWindow(child
->left
.hwnd
);
3661 UpdateWindow(child
->right
.hwnd
);
3667 #ifndef _NO_EXTENSIONS
3668 case WM_GETMINMAXINFO
:
3669 DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
3671 {LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
3673 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
3674 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
3676 #endif /* _NO_EXTENSIONS */
3679 SetCurrentDirectory(child
->path
);
3680 SetFocus(child
->focus_pane
? child
->right
.hwnd
: child
->left
.hwnd
);
3683 case WM_DISPATCH_COMMAND
: {
3684 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
3686 switch(LOWORD(wparam
)) {
3687 case ID_WINDOW_NEW
: {
3688 ChildWnd
* new_child
= alloc_child_window(child
->path
, NULL
, hwnd
);
3690 if (!create_child_window(new_child
))
3696 scan_entry(child
, pane
->cur
, hwnd
);
3700 activate_entry(child
, pane
, hwnd
);
3703 case ID_FILE_MOVE
: {
3704 TCHAR new_name
[BUFFER_LEN
], old_name
[BUFFER_LEN
];
3707 int ret
= DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_SELECT_DESTINATION
), hwnd
, DestinationDlgProc
, (LPARAM
)new_name
);
3711 if (new_name
[0]!='/' && new_name
[1]!=':') {
3712 get_path(pane
->cur
->up
, old_name
);
3713 len
= lstrlen(old_name
);
3715 if (old_name
[len
-1]!='\\' && old_name
[len
-1]!='/') {
3716 old_name
[len
++] = '/';
3717 old_name
[len
] = '\n';
3720 lstrcpy(&old_name
[len
], new_name
);
3721 lstrcpy(new_name
, old_name
);
3724 get_path(pane
->cur
, old_name
);
3726 if (MoveFileEx(old_name
, new_name
, MOVEFILE_COPY_ALLOWED
)) {
3727 if (pane
->treePane
) {
3728 pane
->root
->scanned
= FALSE
;
3729 pane
->cur
= pane
->root
;
3730 activate_entry(child
, pane
, hwnd
);
3733 scan_entry(child
, pane
->root
, hwnd
);
3736 display_error(hwnd
, GetLastError());
3740 return pane_command(pane
, LOWORD(wparam
));
3746 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
3748 switch(HIWORD(wparam
)) {
3749 case LBN_SELCHANGE
: {
3750 int idx
= ListBox_GetCurSel(pane
->hwnd
);
3751 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, idx
);
3753 if (pane
== &child
->left
)
3754 set_curdir(child
, entry
, hwnd
);
3760 activate_entry(child
, pane
, hwnd
);
3765 #ifndef _NO_EXTENSIONS
3767 NMHDR
* pnmh
= (NMHDR
*) lparam
;
3768 return pane_notify(pnmh
->idFrom
==IDW_HEADER_LEFT
? &child
->left
: &child
->right
, pnmh
);}
3771 #ifdef _SHELL_FOLDERS
3772 case WM_CONTEXTMENU
: {
3777 /* first select the current item in the listbox */
3778 HWND hpanel
= (HWND
) wparam
;
3779 pt_clnt
.x
= pt
.x
= (short)LOWORD(lparam
);
3780 pt_clnt
.y
= pt
.y
= (short)HIWORD(lparam
);
3781 ScreenToClient(hpanel
, &pt_clnt
);
3782 SendMessage(hpanel
, WM_LBUTTONDOWN
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
3783 SendMessage(hpanel
, WM_LBUTTONUP
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
3785 /* now create the popup menu using shell namespace and IContextMenu */
3786 pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
3787 idx
= ListBox_GetCurSel(pane
->hwnd
);
3791 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, idx
);
3793 LPITEMIDLIST pidl_abs
= get_to_absolute_pidl(entry
, hwnd
);
3796 IShellFolder
* parentFolder
;
3797 LPCITEMIDLIST pidlLast
;
3799 /* get and use the parent folder to display correct context menu in all cases */
3800 if (SUCCEEDED(SHBindToParent(pidl_abs
, &IID_IShellFolder
, (LPVOID
*)&parentFolder
, &pidlLast
))) {
3801 hr
= ShellFolderContextMenu(parentFolder
, hwnd
, 1, &pidlLast
, pt
.x
, pt
.y
);
3803 (*parentFolder
->lpVtbl
->Release
)(parentFolder
);
3806 (*Globals
.iMalloc
->lpVtbl
->Free
)(Globals
.iMalloc
, pidl_abs
);
3812 case WM_MEASUREITEM
:
3814 if (!wparam
) // Is the message menu-related?
3815 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
3820 case WM_INITMENUPOPUP
:
3821 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
3826 #ifndef __MINGW32__ // IContextMenu3 missing in MinGW (as of 6.2.2005)
3827 case WM_MENUCHAR
: // only supported by IContextMenu3
3829 LRESULT lResult
= 0;
3831 (*s_pctxmenu3
->lpVtbl
->HandleMenuMsg2
)(s_pctxmenu3
, nmsg
, wparam
, lparam
, &lResult
);
3840 if (wparam
!= SIZE_MINIMIZED
)
3841 resize_tree(child
, LOWORD(lparam
), HIWORD(lparam
));
3845 return DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
3852 LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3854 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(GetParent(hwnd
), GWL_USERDATA
);
3855 Pane
* pane
= (Pane
*) GetWindowLong(hwnd
, GWL_USERDATA
);
3859 #ifndef _NO_EXTENSIONS
3866 child
->focus_pane
= pane
==&child
->right
? 1: 0;
3867 ListBox_SetSel(hwnd
, TRUE
, 1);
3868 /*TODO: check menu items */
3872 if (wparam
== VK_TAB
) {
3873 /*TODO: SetFocus(Globals.hdrivebar) */
3874 SetFocus(child
->focus_pane
? child
->left
.hwnd
: child
->right
.hwnd
);
3878 return CallWindowProc(g_orgTreeWndProc
, hwnd
, nmsg
, wparam
, lparam
);
3882 static void InitInstance(HINSTANCE hinstance
)
3884 const static TCHAR sFont
[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
3891 INITCOMMONCONTROLSEX icc
= {
3892 sizeof(INITCOMMONCONTROLSEX
),
3898 setlocale(LC_COLLATE
, ""); /* set collating rules to local settings for compareName */
3900 InitCommonControlsEx(&icc
);
3903 /* register frame window class */
3905 wcFrame
.cbSize
= sizeof(WNDCLASSEX
);
3907 wcFrame
.lpfnWndProc
= FrameWndProc
;
3908 wcFrame
.cbClsExtra
= 0;
3909 wcFrame
.cbWndExtra
= 0;
3910 wcFrame
.hInstance
= hinstance
;
3911 wcFrame
.hIcon
= LoadIcon(hinstance
, MAKEINTRESOURCE(IDI_WINEFILE
));
3912 wcFrame
.hCursor
= LoadCursor(0, IDC_ARROW
);
3913 wcFrame
.hbrBackground
= 0;
3914 wcFrame
.lpszMenuName
= 0;
3915 wcFrame
.lpszClassName
= sWINEFILEFRAME
;
3916 wcFrame
.hIconSm
= (HICON
)LoadImage(hinstance
,
3917 MAKEINTRESOURCE(IDI_WINEFILE
),
3919 GetSystemMetrics(SM_CXSMICON
),
3920 GetSystemMetrics(SM_CYSMICON
),
3923 Globals
.hframeClass
= RegisterClassEx(&wcFrame
);
3926 /* register tree windows class */
3928 wcChild
.style
= CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
;
3929 wcChild
.lpfnWndProc
= ChildWndProc
;
3930 wcChild
.cbClsExtra
= 0;
3931 wcChild
.cbWndExtra
= 0;
3932 wcChild
.hInstance
= hinstance
;
3934 wcChild
.hCursor
= LoadCursor(0, IDC_ARROW
);
3935 wcChild
.hbrBackground
= 0;
3936 wcChild
.lpszMenuName
= 0;
3937 wcChild
.lpszClassName
= sWINEFILETREE
;
3939 hChildClass
= RegisterClass(&wcChild
);
3942 Globals
.haccel
= LoadAccelerators(hinstance
, MAKEINTRESOURCE(IDA_WINEFILE
));
3944 Globals
.hfont
= CreateFont(-MulDiv(8,GetDeviceCaps(hdc
,LOGPIXELSY
),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont
);
3948 Globals
.hInstance
= hinstance
;
3950 #ifdef _SHELL_FOLDERS
3952 CoGetMalloc(MEMCTX_TASK
, &Globals
.iMalloc
);
3953 SHGetDesktopFolder(&Globals
.iDesktop
);
3955 Globals
.cfStrFName
= RegisterClipboardFormatA(CFSTR_FILENAME
);
3957 Globals
.cfStrFName
= RegisterClipboardFormat(CFSTR_FILENAME
);
3961 /* load column strings */
3964 load_string(g_pos_names
[col
++], IDS_COL_NAME
);
3965 load_string(g_pos_names
[col
++], IDS_COL_SIZE
);
3966 load_string(g_pos_names
[col
++], IDS_COL_CDATE
);
3967 #ifndef _NO_EXTENSIONS
3968 load_string(g_pos_names
[col
++], IDS_COL_ADATE
);
3969 load_string(g_pos_names
[col
++], IDS_COL_MDATE
);
3970 load_string(g_pos_names
[col
++], IDS_COL_IDX
);
3971 load_string(g_pos_names
[col
++], IDS_COL_LINKS
);
3973 load_string(g_pos_names
[col
++], IDS_COL_ATTR
);
3974 #ifndef _NO_EXTENSIONS
3975 load_string(g_pos_names
[col
++], IDS_COL_SEC
);
3980 void show_frame(HWND hwndParent
, int cmdshow
)
3982 const static TCHAR sMDICLIENT
[] = {'M','D','I','C','L','I','E','N','T','\0'};
3984 TCHAR path
[MAX_PATH
], b1
[BUFFER_LEN
];
3986 HMENU hMenuFrame
, hMenuWindow
;
3988 CLIENTCREATESTRUCT ccs
;
3990 if (Globals
.hMainWnd
)
3993 Globals
.hwndParent
= hwndParent
;
3995 hMenuFrame
= LoadMenu(Globals
.hInstance
, MAKEINTRESOURCE(IDM_WINEFILE
));
3996 hMenuWindow
= GetSubMenu(hMenuFrame
, GetMenuItemCount(hMenuFrame
)-2);
3998 Globals
.hMenuFrame
= hMenuFrame
;
3999 Globals
.hMenuView
= GetSubMenu(hMenuFrame
, 3);
4000 Globals
.hMenuOptions
= GetSubMenu(hMenuFrame
, 4);
4002 ccs
.hWindowMenu
= hMenuWindow
;
4003 ccs
.idFirstChild
= IDW_FIRST_CHILD
;
4006 /* create main window */
4007 Globals
.hMainWnd
= CreateWindowEx(0, (LPCTSTR
)(int)Globals
.hframeClass
, RS(b1
,IDS_WINE_FILE
), WS_OVERLAPPEDWINDOW
,
4008 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
4009 hwndParent
, Globals
.hMenuFrame
, Globals
.hInstance
, 0/*lpParam*/);
4012 Globals
.hmdiclient
= CreateWindowEx(0, sMDICLIENT
, NULL
,
4013 WS_CHILD
|WS_CLIPCHILDREN
|WS_VSCROLL
|WS_HSCROLL
|WS_VISIBLE
|WS_BORDER
,
4015 Globals
.hMainWnd
, 0, Globals
.hInstance
, &ccs
);
4019 TBBUTTON drivebarBtn
= {0, 0, TBSTATE_ENABLED
, BTNS_SEP
, {0, 0}, 0, 0};
4023 Globals
.hdrivebar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
,
4024 IDW_DRIVEBAR
, 2, Globals
.hInstance
, IDB_DRIVEBAR
, &drivebarBtn
,
4025 1, 16, 13, 16, 13, sizeof(TBBUTTON
));
4026 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_DRIVE_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4028 GetLogicalDriveStrings(BUFFER_LEN
, Globals
.drives
);
4030 drivebarBtn
.fsStyle
= BTNS_BUTTON
;
4032 #ifndef _NO_EXTENSIONS
4034 /* insert unix file system button */
4038 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
4040 drivebarBtn
.idCommand
= ID_DRIVE_UNIX_FS
;
4041 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
4042 drivebarBtn
.iString
++;
4044 #ifdef _SHELL_FOLDERS
4045 /* insert shell namespace button */
4046 load_string(b1
, IDS_SHELL
);
4047 b1
[lstrlen(b1
)+1] = '\0';
4048 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
4050 drivebarBtn
.idCommand
= ID_DRIVE_SHELL_NS
;
4051 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
4052 drivebarBtn
.iString
++;
4055 /* register windows drive root strings */
4056 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)Globals
.drives
);
4059 drivebarBtn
.idCommand
= ID_DRIVE_FIRST
;
4061 for(p
=Globals
.drives
; *p
; ) {
4062 #ifdef _NO_EXTENSIONS
4063 /* insert drive letter */
4064 TCHAR b
[3] = {tolower(*p
)};
4065 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b
);
4067 switch(GetDriveType(p
)) {
4068 case DRIVE_REMOVABLE
: drivebarBtn
.iBitmap
= 1; break;
4069 case DRIVE_CDROM
: drivebarBtn
.iBitmap
= 3; break;
4070 case DRIVE_REMOTE
: drivebarBtn
.iBitmap
= 4; break;
4071 case DRIVE_RAMDISK
: drivebarBtn
.iBitmap
= 5; break;
4072 default:/*DRIVE_FIXED*/ drivebarBtn
.iBitmap
= 2;
4075 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
4076 drivebarBtn
.idCommand
++;
4077 drivebarBtn
.iString
++;
4084 TBBUTTON toolbarBtns
[] = {
4085 {0, 0, 0, BTNS_SEP
, {0, 0}, 0, 0},
4086 {0, ID_WINDOW_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4087 {1, ID_WINDOW_CASCADE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4088 {2, ID_WINDOW_TILE_HORZ
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4089 {3, ID_WINDOW_TILE_VERT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4091 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4092 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4095 Globals
.htoolbar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
,
4096 IDW_TOOLBAR
, 2, Globals
.hInstance
, IDB_TOOLBAR
, toolbarBtns
,
4097 sizeof(toolbarBtns
)/sizeof(TBBUTTON
), 16, 15, 16, 15, sizeof(TBBUTTON
));
4098 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_TOOL_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4101 Globals
.hstatusbar
= CreateStatusWindow(WS_CHILD
|WS_VISIBLE
, 0, Globals
.hMainWnd
, IDW_STATUSBAR
);
4102 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
4104 /* CreateStatusWindow does not accept WS_BORDER
4105 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
4106 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
4107 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
4109 /*TODO: read paths and window placements from registry */
4110 GetCurrentDirectory(MAX_PATH
, path
);
4112 ShowWindow(Globals
.hMainWnd
, cmdshow
);
4114 //#if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4115 // // Shell Namespace as default:
4116 // child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
4118 child
= alloc_child_window(path
, NULL
, Globals
.hMainWnd
);
4121 child
->pos
.showCmd
= SW_SHOWMAXIMIZED
;
4122 child
->pos
.rcNormalPosition
.left
= 0;
4123 child
->pos
.rcNormalPosition
.top
= 0;
4124 child
->pos
.rcNormalPosition
.right
= 320;
4125 child
->pos
.rcNormalPosition
.bottom
= 280;
4127 if (!create_child_window(child
))
4130 SetWindowPlacement(child
->hwnd
, &child
->pos
);
4132 Globals
.himl
= ImageList_LoadBitmap(Globals
.hInstance
, MAKEINTRESOURCE(IDB_IMAGES
), 16, 0, RGB(0,255,0));
4134 Globals
.prescan_node
= FALSE
;
4136 UpdateWindow(Globals
.hMainWnd
);
4141 #ifdef _SHELL_FOLDERS
4142 (*Globals
.iDesktop
->lpVtbl
->Release
)(Globals
.iDesktop
);
4143 (*Globals
.iMalloc
->lpVtbl
->Release
)(Globals
.iMalloc
);
4147 ImageList_Destroy(Globals
.himl
);
4151 /* search for already running win[e]files */
4153 static int g_foundPrevInstance
= 0;
4155 static BOOL CALLBACK
EnumWndProc(HWND hwnd
, LPARAM lparam
)
4159 GetClassName(hwnd
, cls
, 128);
4161 if (!lstrcmp(cls
, (LPCTSTR
)lparam
)) {
4162 g_foundPrevInstance
++;
4169 /* search for window of given class name to allow only one running instance */
4170 int find_window_class(LPCTSTR classname
)
4172 EnumWindows(EnumWndProc
, (LPARAM
)classname
);
4174 if (g_foundPrevInstance
)
4181 int winefile_main(HINSTANCE hinstance
, HWND hwndParent
, int cmdshow
)
4185 InitInstance(hinstance
);
4187 if (cmdshow
== SW_SHOWNORMAL
)
4188 /*TODO: read window placement from registry */
4189 cmdshow
= SW_MAXIMIZE
;
4191 show_frame(hwndParent
, cmdshow
);
4193 while(GetMessage(&msg
, 0, 0, 0)) {
4194 if (Globals
.hmdiclient
&& TranslateMDISysAccel(Globals
.hmdiclient
, &msg
))
4197 if (Globals
.hMainWnd
&& TranslateAccelerator(Globals
.hMainWnd
, Globals
.haccel
, &msg
))
4200 TranslateMessage(&msg
);
4201 DispatchMessage(&msg
);
4210 int APIENTRY
WinMain(HINSTANCE hinstance
,
4211 HINSTANCE previnstance
,
4215 #ifdef _NO_EXTENSIONS
4216 if (find_window_class(sWINEFILEFRAME
))
4220 winefile_main(hinstance
, 0, cmdshow
);