4 * Copyright 2000, 2003, 2004 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
= &(*(Entry
**)arg1
)->data
;
1107 const WIN32_FIND_DATA
* fd2
= &(*(Entry
**)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
= &(*(Entry
**)arg1
)->data
;
1119 const WIN32_FIND_DATA
* fd2
= &(*(Entry
**)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 WIN32_FIND_DATA
* fd1
= &(*(Entry
**)arg1
)->data
;
1152 WIN32_FIND_DATA
* fd2
= &(*(Entry
**)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 WIN32_FIND_DATA
* fd1
= &(*(Entry
**)arg1
)->data
;
1173 WIN32_FIND_DATA
* fd2
= &(*(Entry
**)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 prefered 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 prefered 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 void 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 insert_entries(pane
, entry
->down
, idx
);
2391 ShowWindow(pane
->hwnd
, SW_SHOW
);
2395 static WNDPROC g_orgTreeWndProc
;
2397 static void create_tree_window(HWND parent
, Pane
* pane
, int id
, int id_header
)
2399 const static TCHAR sListBox
[] = {'L','i','s','t','B','o','x','\0'};
2401 static int s_init
= 0;
2402 Entry
* entry
= pane
->root
;
2404 pane
->hwnd
= CreateWindow(sListBox
, sEmpty
, WS_CHILD
|WS_VISIBLE
|WS_HSCROLL
|WS_VSCROLL
|
2405 LBS_DISABLENOSCROLL
|LBS_NOINTEGRALHEIGHT
|LBS_OWNERDRAWFIXED
|LBS_NOTIFY
,
2406 0, 0, 0, 0, parent
, (HMENU
)id
, Globals
.hInstance
, 0);
2408 SetWindowLong(pane
->hwnd
, GWL_USERDATA
, (LPARAM
)pane
);
2409 g_orgTreeWndProc
= SubclassWindow(pane
->hwnd
, TreeWndProc
);
2411 SetWindowFont(pane
->hwnd
, Globals
.hfont
, FALSE
);
2413 /* insert entries into listbox */
2415 insert_entries(pane
, entry
, -1);
2417 /* calculate column widths */
2420 init_output(pane
->hwnd
);
2423 calc_widths(pane
, TRUE
);
2425 #ifndef _NO_EXTENSIONS
2426 pane
->hwndHeader
= create_header(parent
, pane
, id_header
);
2431 static void InitChildWindow(ChildWnd
* child
)
2433 create_tree_window(child
->hwnd
, &child
->left
, IDW_TREE_LEFT
, IDW_HEADER_LEFT
);
2434 create_tree_window(child
->hwnd
, &child
->right
, IDW_TREE_RIGHT
, IDW_HEADER_RIGHT
);
2438 static void format_date(const FILETIME
* ft
, TCHAR
* buffer
, int visible_cols
)
2444 *buffer
= TEXT('\0');
2446 if (!ft
->dwLowDateTime
&& !ft
->dwHighDateTime
)
2449 if (!FileTimeToLocalFileTime(ft
, &lft
))
2450 {err
: _tcscpy(buffer
,sQMarks
); return;}
2452 if (!FileTimeToSystemTime(&lft
, &systime
))
2455 if (visible_cols
& COL_DATE
) {
2456 len
= GetDateFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
, BUFFER_LEN
);
2461 if (visible_cols
& COL_TIME
) {
2463 buffer
[len
-1] = ' ';
2465 buffer
[len
++] = ' ';
2467 if (!GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
+len
, BUFFER_LEN
-len
))
2468 buffer
[len
] = TEXT('\0');
2473 static void calc_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2475 RECT rt
= {0, 0, 0, 0};
2477 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
2479 if (rt
.right
> pane
->widths
[col
])
2480 pane
->widths
[col
] = rt
.right
;
2483 static void calc_tabbed_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2485 RECT rt
= {0, 0, 0, 0};
2487 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2488 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2490 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2491 /*FIXME rt (0,0) ??? */
2493 if (rt
.right
> pane
->widths
[col
])
2494 pane
->widths
[col
] = rt
.right
;
2498 static void output_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
, DWORD flags
)
2500 int x
= dis
->rcItem
.left
;
2503 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2504 rt
.top
= dis
->rcItem
.top
;
2505 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2506 rt
.bottom
= dis
->rcItem
.bottom
;
2508 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_SINGLELINE
|DT_NOPREFIX
|flags
);
2511 static void output_tabbed_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2513 int x
= dis
->rcItem
.left
;
2516 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2517 rt
.top
= dis
->rcItem
.top
;
2518 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2519 rt
.bottom
= dis
->rcItem
.bottom
;
2521 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2522 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2524 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2527 static void output_number(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2529 int x
= dis
->rcItem
.left
;
2536 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2537 rt
.top
= dis
->rcItem
.top
;
2538 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2539 rt
.bottom
= dis
->rcItem
.bottom
;
2544 /* insert number separator characters */
2545 pos
= lstrlen(s
) % 3;
2551 *d
++ = Globals
.num_sep
;
2555 DrawText(dis
->hDC
, b
, d
-b
, &rt
, DT_RIGHT
|DT_SINGLELINE
|DT_NOPREFIX
|DT_END_ELLIPSIS
);
2559 static int is_exe_file(LPCTSTR ext
)
2561 static const TCHAR executable_extensions
[][4] = {
2566 #ifndef _NO_EXTENSIONS
2570 #endif /* _NO_EXTENSIONS */
2574 TCHAR ext_buffer
[_MAX_EXT
];
2575 const TCHAR (*p
)[4];
2579 for(s
=ext
+1,d
=ext_buffer
; (*d
=tolower(*s
)); s
++)
2582 for(p
=executable_extensions
; (*p
)[0]; p
++)
2583 if (!_tcscmp(ext_buffer
, *p
))
2589 static int is_registered_type(LPCTSTR ext
)
2597 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
)
2599 TCHAR buffer
[BUFFER_LEN
];
2601 int visible_cols
= pane
->visible_cols
;
2602 COLORREF bkcolor
, textcolor
;
2603 RECT focusRect
= dis
->rcItem
;
2610 attrs
= entry
->data
.dwFileAttributes
;
2612 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) {
2613 if (entry
->data
.cFileName
[0]==TEXT('.') && entry
->data
.cFileName
[1]==TEXT('.')
2614 && entry
->data
.cFileName
[2]==TEXT('\0'))
2615 img
= IMG_FOLDER_UP
;
2616 #ifndef _NO_EXTENSIONS
2617 else if (entry
->data
.cFileName
[0]==TEXT('.') && entry
->data
.cFileName
[1]==TEXT('\0'))
2618 img
= IMG_FOLDER_CUR
;
2621 #ifdef _NO_EXTENSIONS
2624 (pane
->treePane
&& (dis
->itemState
&ODS_FOCUS
)))
2625 img
= IMG_OPEN_FOLDER
;
2629 LPCTSTR ext
= _tcsrchr(entry
->data
.cFileName
, '.');
2633 if (is_exe_file(ext
))
2634 img
= IMG_EXECUTABLE
;
2635 else if (is_registered_type(ext
))
2645 if (pane
->treePane
) {
2647 img_pos
= dis
->rcItem
.left
+ entry
->level
*(IMAGE_WIDTH
+TREE_LINE_DX
);
2649 if (calcWidthCol
== -1) {
2651 int y
= dis
->rcItem
.top
+ IMAGE_HEIGHT
/2;
2654 HRGN hrgn_org
= CreateRectRgn(0, 0, 0, 0);
2657 rt_clip
.left
= dis
->rcItem
.left
;
2658 rt_clip
.top
= dis
->rcItem
.top
;
2659 rt_clip
.right
= dis
->rcItem
.left
+pane
->widths
[col
];
2660 rt_clip
.bottom
= dis
->rcItem
.bottom
;
2662 hrgn
= CreateRectRgnIndirect(&rt_clip
);
2664 if (!GetClipRgn(dis
->hDC
, hrgn_org
)) {
2665 DeleteObject(hrgn_org
);
2669 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
2670 ExtSelectClipRgn(dis
->hDC
, hrgn
, RGN_AND
);
2673 if ((up
=entry
->up
) != NULL
) {
2674 MoveToEx(dis
->hDC
, img_pos
-IMAGE_WIDTH
/2, y
, 0);
2675 LineTo(dis
->hDC
, img_pos
-2, y
);
2677 x
= img_pos
- IMAGE_WIDTH
/2;
2680 x
-= IMAGE_WIDTH
+TREE_LINE_DX
;
2684 && (up
->next
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
2687 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
2688 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
2690 } while((up
=up
->up
) != NULL
);
2693 x
= img_pos
- IMAGE_WIDTH
/2;
2695 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
2696 LineTo(dis
->hDC
, x
, y
);
2700 && (entry
->next
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
)
2703 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
2705 if (entry
->down
&& entry
->expanded
) {
2706 x
+= IMAGE_WIDTH
+TREE_LINE_DX
;
2707 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
+IMAGE_HEIGHT
, 0);
2708 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
2711 SelectClipRgn(dis
->hDC
, hrgn_org
);
2712 if (hrgn_org
) DeleteObject(hrgn_org
);
2713 /* SelectObject(dis->hDC, holdPen); */
2714 } else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
) {
2715 int right
= img_pos
+ IMAGE_WIDTH
- TREE_LINE_DX
;
2717 if (right
> pane
->widths
[col
])
2718 pane
->widths
[col
] = right
;
2721 img_pos
= dis
->rcItem
.left
;
2724 img_pos
= dis
->rcItem
.left
;
2726 if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2727 pane
->widths
[col
] = IMAGE_WIDTH
;
2730 if (calcWidthCol
== -1) {
2731 focusRect
.left
= img_pos
- 2;
2733 #ifdef _NO_EXTENSIONS
2734 if (pane
->treePane
&& entry
) {
2737 DrawText(dis
->hDC
, entry
->data
.cFileName
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
2739 focusRect
.right
= dis
->rcItem
.left
+pane
->positions
[col
+1]+TREE_LINE_DX
+ rt
.right
+2;
2743 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
)
2744 textcolor
= COLOR_COMPRESSED
;
2746 #endif /* _NO_EXTENSIONS */
2747 textcolor
= RGB(0,0,0);
2749 if (dis
->itemState
& ODS_FOCUS
) {
2750 textcolor
= RGB(255,255,255);
2751 bkcolor
= COLOR_SELECTION
;
2753 bkcolor
= RGB(255,255,255);
2756 hbrush
= CreateSolidBrush(bkcolor
);
2757 FillRect(dis
->hDC
, &focusRect
, hbrush
);
2758 DeleteObject(hbrush
);
2760 SetBkMode(dis
->hDC
, TRANSPARENT
);
2761 SetTextColor(dis
->hDC
, textcolor
);
2763 cx
= pane
->widths
[col
];
2765 if (cx
&& img
!=IMG_NONE
) {
2766 if (cx
> IMAGE_WIDTH
)
2769 #ifdef _SHELL_FOLDERS
2770 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
2771 DrawIconEx(dis
->hDC
, img_pos
, dis
->rcItem
.top
, entry
->hicon
, cx
, GetSystemMetrics(SM_CYSMICON
), 0, 0, DI_NORMAL
);
2774 ImageList_DrawEx(Globals
.himl
, img
, dis
->hDC
,
2775 img_pos
, dis
->rcItem
.top
, cx
,
2776 IMAGE_HEIGHT
, bkcolor
, CLR_DEFAULT
, ILD_NORMAL
);
2783 #ifdef _NO_EXTENSIONS
2784 if (img
>= IMG_FOLDER_UP
)
2790 /* ouput file name */
2791 if (calcWidthCol
== -1)
2792 output_text(pane
, dis
, col
, entry
->data
.cFileName
, 0);
2793 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2794 calc_width(pane
, dis
, col
, entry
->data
.cFileName
);
2798 #ifdef _NO_EXTENSIONS
2799 if (!pane
->treePane
) {
2802 /* display file size */
2803 if (visible_cols
& COL_SIZE
) {
2804 #ifdef _NO_EXTENSIONS
2805 if (!(attrs
&FILE_ATTRIBUTE_DIRECTORY
))
2810 size
= ((ULONGLONG
)entry
->data
.nFileSizeHigh
<< 32) | entry
->data
.nFileSizeLow
;
2812 _stprintf(buffer
, sLongNumFmt
, size
);
2814 if (calcWidthCol
== -1)
2815 output_number(pane
, dis
, col
, buffer
);
2816 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2817 calc_width(pane
, dis
, col
, buffer
);/*TODO: not in every case time enough */
2823 /* display file date */
2824 if (visible_cols
& (COL_DATE
|COL_TIME
)) {
2825 #ifndef _NO_EXTENSIONS
2826 format_date(&entry
->data
.ftCreationTime
, buffer
, visible_cols
);
2827 if (calcWidthCol
== -1)
2828 output_text(pane
, dis
, col
, buffer
, 0);
2829 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2830 calc_width(pane
, dis
, col
, buffer
);
2833 format_date(&entry
->data
.ftLastAccessTime
, buffer
, visible_cols
);
2834 if (calcWidthCol
== -1)
2835 output_text(pane
, dis
, col
, buffer
, 0);
2836 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2837 calc_width(pane
, dis
, col
, buffer
);
2839 #endif /* _NO_EXTENSIONS */
2841 format_date(&entry
->data
.ftLastWriteTime
, buffer
, visible_cols
);
2842 if (calcWidthCol
== -1)
2843 output_text(pane
, dis
, col
, buffer
, 0);
2844 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2845 calc_width(pane
, dis
, col
, buffer
);
2849 #ifndef _NO_EXTENSIONS
2850 if (entry
->bhfi_valid
) {
2851 ULONGLONG index
= ((ULONGLONG
)entry
->bhfi
.nFileIndexHigh
<< 32) | entry
->bhfi
.nFileIndexLow
;
2853 if (visible_cols
& COL_INDEX
) {
2854 _stprintf(buffer
, sLongHexFmt
, index
);
2856 if (calcWidthCol
== -1)
2857 output_text(pane
, dis
, col
, buffer
, DT_RIGHT
);
2858 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2859 calc_width(pane
, dis
, col
, buffer
);
2864 if (visible_cols
& COL_LINKS
) {
2865 wsprintf(buffer
, sNumFmt
, entry
->bhfi
.nNumberOfLinks
);
2867 if (calcWidthCol
== -1)
2868 output_text(pane
, dis
, col
, buffer
, DT_CENTER
);
2869 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2870 calc_width(pane
, dis
, col
, buffer
);
2876 #endif /* _NO_EXTENSIONS */
2878 /* show file attributes */
2879 if (visible_cols
& COL_ATTRIBUTES
) {
2880 #ifdef _NO_EXTENSIONS
2881 const static TCHAR s4Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
2882 _tcscpy(buffer
, s4Tabs
);
2884 const static TCHAR s11Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
2885 _tcscpy(buffer
, s11Tabs
);
2888 if (attrs
& FILE_ATTRIBUTE_NORMAL
) buffer
[ 0] = 'N';
2890 if (attrs
& FILE_ATTRIBUTE_READONLY
) buffer
[ 2] = 'R';
2891 if (attrs
& FILE_ATTRIBUTE_HIDDEN
) buffer
[ 4] = 'H';
2892 if (attrs
& FILE_ATTRIBUTE_SYSTEM
) buffer
[ 6] = 'S';
2893 if (attrs
& FILE_ATTRIBUTE_ARCHIVE
) buffer
[ 8] = 'A';
2894 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
) buffer
[10] = 'C';
2895 #ifndef _NO_EXTENSIONS
2896 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) buffer
[12] = 'D';
2897 if (attrs
& FILE_ATTRIBUTE_ENCRYPTED
) buffer
[14] = 'E';
2898 if (attrs
& FILE_ATTRIBUTE_TEMPORARY
) buffer
[16] = 'T';
2899 if (attrs
& FILE_ATTRIBUTE_SPARSE_FILE
) buffer
[18] = 'P';
2900 if (attrs
& FILE_ATTRIBUTE_REPARSE_POINT
) buffer
[20] = 'Q';
2901 if (attrs
& FILE_ATTRIBUTE_OFFLINE
) buffer
[22] = 'O';
2902 if (attrs
& FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
) buffer
[24] = 'X';
2903 #endif /* _NO_EXTENSIONS */
2906 if (calcWidthCol
== -1)
2907 output_tabbed_text(pane
, dis
, col
, buffer
);
2908 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2909 calc_tabbed_width(pane
, dis
, col
, buffer
);
2915 if (flags.security) {
2916 const static TCHAR sSecTabs[] = {
2917 ' ','\t',' ','\t',' ','\t',' ',
2919 ' ','\t',' ','\t',' ','\t',' ',
2921 ' ','\t',' ','\t',' ','\t',' ',
2925 DWORD rights = get_access_mask();
2927 tcscpy(buffer, sSecTabs);
2929 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
2930 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
2931 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
2932 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
2933 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
2934 if (rights & FILE_EXECUTE) buffer[12] = 'X';
2935 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
2936 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
2937 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
2938 if (rights & WRITE_DAC) buffer[22] = 'C';
2939 if (rights & WRITE_OWNER) buffer[24] = 'O';
2940 if (rights & SYNCHRONIZE) buffer[26] = 'S';
2942 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
2945 if (flags.description) {
2946 get_description(buffer);
2947 output_text(dis, col++, buffer, 0, psize);
2951 #ifdef _NO_EXTENSIONS
2954 /* draw focus frame */
2955 if ((dis
->itemState
&ODS_FOCUS
) && calcWidthCol
==-1) {
2956 /* Currently [04/2000] Wine neither behaves exactly the same */
2957 /* way as WIN 95 nor like Windows NT... */
2962 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
2963 LOGBRUSH lb
= {PS_SOLID
, RGB(255,255,255)};
2964 hpen
= ExtCreatePen(PS_COSMETIC
|PS_ALTERNATE
, 1, &lb
, 0, 0);
2966 hpen
= CreatePen(PS_DOT
, 0, RGB(255,255,255));
2968 lastPen
= SelectPen(dis
->hDC
, hpen
);
2969 lastBrush
= SelectObject(dis
->hDC
, GetStockObject(HOLLOW_BRUSH
));
2970 SetROP2(dis
->hDC
, R2_XORPEN
);
2971 Rectangle(dis
->hDC
, focusRect
.left
, focusRect
.top
, focusRect
.right
, focusRect
.bottom
);
2972 SelectObject(dis
->hDC
, lastBrush
);
2973 SelectObject(dis
->hDC
, lastPen
);
2976 #endif /* _NO_EXTENSIONS */
2980 #ifdef _NO_EXTENSIONS
2982 static void draw_splitbar(HWND hwnd
, int x
)
2985 HDC hdc
= GetDC(hwnd
);
2987 GetClientRect(hwnd
, &rt
);
2989 rt
.left
= x
- SPLIT_WIDTH
/2;
2990 rt
.right
= x
+ SPLIT_WIDTH
/2+1;
2992 InvertRect(hdc
, &rt
);
2994 ReleaseDC(hwnd
, hdc
);
2997 #endif /* _NO_EXTENSIONS */
3000 #ifndef _NO_EXTENSIONS
3002 static void set_header(Pane
* pane
)
3005 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3008 item
.mask
= HDI_WIDTH
;
3011 for(; x
+pane
->widths
[i
]<scroll_pos
&& i
<COLUMNS
; i
++) {
3012 x
+= pane
->widths
[i
];
3013 Header_SetItem(pane
->hwndHeader
, i
, &item
);
3017 x
+= pane
->widths
[i
];
3018 item
.cxy
= x
- scroll_pos
;
3019 Header_SetItem(pane
->hwndHeader
, i
++, &item
);
3021 for(; i
<COLUMNS
; i
++) {
3022 item
.cxy
= pane
->widths
[i
];
3023 x
+= pane
->widths
[i
];
3024 Header_SetItem(pane
->hwndHeader
, i
, &item
);
3029 static LRESULT
pane_notify(Pane
* pane
, NMHDR
* pnmh
)
3031 switch(pnmh
->code
) {
3033 case HDN_ENDTRACK
: {
3034 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3035 int idx
= phdn
->iItem
;
3036 int dx
= phdn
->pitem
->cxy
- pane
->widths
[idx
];
3040 GetClientRect(pane
->hwnd
, &clnt
);
3042 /* move immediate to simulate HDS_FULLDRAG (for now [04/2000] not really needed with WINELIB) */
3043 Header_SetItem(pane
->hwndHeader
, idx
, phdn
->pitem
);
3045 pane
->widths
[idx
] += dx
;
3047 for(i
=idx
; ++i
<=COLUMNS
; )
3048 pane
->positions
[i
] += dx
;
3051 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3055 rt_scr
.left
= pane
->positions
[idx
+1]-scroll_pos
;
3057 rt_scr
.right
= clnt
.right
;
3058 rt_scr
.bottom
= clnt
.bottom
;
3060 rt_clip
.left
= pane
->positions
[idx
]-scroll_pos
;
3062 rt_clip
.right
= clnt
.right
;
3063 rt_clip
.bottom
= clnt
.bottom
;
3065 if (rt_scr
.left
< 0) rt_scr
.left
= 0;
3066 if (rt_clip
.left
< 0) rt_clip
.left
= 0;
3068 ScrollWindowEx(pane
->hwnd
, dx
, 0, &rt_scr
, &rt_clip
, 0, 0, SW_INVALIDATE
);
3070 rt_clip
.right
= pane
->positions
[idx
+1];
3071 RedrawWindow(pane
->hwnd
, &rt_clip
, 0, RDW_INVALIDATE
|RDW_UPDATENOW
);
3073 if (pnmh
->code
== HDN_ENDTRACK
) {
3074 ListBox_SetHorizontalExtent(pane
->hwnd
, pane
->positions
[COLUMNS
]);
3076 if (GetScrollPos(pane
->hwnd
, SB_HORZ
) != scroll_pos
)
3084 case HDN_DIVIDERDBLCLICK
: {
3085 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3088 calc_single_width(pane
, phdn
->iItem
);
3089 item
.mask
= HDI_WIDTH
;
3090 item
.cxy
= pane
->widths
[phdn
->iItem
];
3092 Header_SetItem(pane
->hwndHeader
, phdn
->iItem
, &item
);
3093 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3100 #endif /* _NO_EXTENSIONS */
3103 static void scan_entry(ChildWnd
* child
, Entry
* entry
, HWND hwnd
)
3105 TCHAR path
[MAX_PATH
];
3106 int idx
= ListBox_GetCurSel(child
->left
.hwnd
);
3107 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
3109 /* delete sub entries in left pane */
3111 LRESULT res
= ListBox_GetItemData(child
->left
.hwnd
, idx
+1);
3112 Entry
* sub
= (Entry
*) res
;
3114 if (res
==LB_ERR
|| !sub
|| sub
->level
<=entry
->level
)
3117 ListBox_DeleteString(child
->left
.hwnd
, idx
+1);
3120 /* empty right pane */
3121 ListBox_ResetContent(child
->right
.hwnd
);
3123 /* release memory */
3124 free_entries(entry
);
3126 /* read contents from disk */
3127 #ifdef _SHELL_FOLDERS
3128 if (entry
->etype
== ET_SHELL
)
3130 read_directory(entry
, NULL
, child
->sortOrder
, hwnd
);
3135 get_path(entry
, path
);
3136 read_directory(entry
, path
, child
->sortOrder
, hwnd
);
3139 /* insert found entries in right pane */
3140 insert_entries(&child
->right
, entry
->down
, -1);
3141 calc_widths(&child
->right
, FALSE
);
3142 #ifndef _NO_EXTENSIONS
3143 set_header(&child
->right
);
3146 child
->header_wdths_ok
= FALSE
;
3148 SetCursor(old_cursor
);
3152 /* expand a directory entry */
3154 static BOOL
expand_entry(ChildWnd
* child
, Entry
* dir
)
3159 if (!dir
|| dir
->expanded
|| !dir
->down
)
3164 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='\0' && p
->next
) {
3167 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='.' &&
3168 p
->data
.cFileName
[2]=='\0' && p
->next
)
3172 /* no subdirectories ? */
3173 if (!(p
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
3176 idx
= ListBox_FindItemData(child
->left
.hwnd
, 0, dir
);
3178 dir
->expanded
= TRUE
;
3180 /* insert entries in left pane */
3181 insert_entries(&child
->left
, p
, idx
);
3183 if (!child
->header_wdths_ok
) {
3184 if (calc_widths(&child
->left
, FALSE
)) {
3185 #ifndef _NO_EXTENSIONS
3186 set_header(&child
->left
);
3189 child
->header_wdths_ok
= TRUE
;
3197 static void collapse_entry(Pane
* pane
, Entry
* dir
)
3199 int idx
= ListBox_FindItemData(pane
->hwnd
, 0, dir
);
3201 ShowWindow(pane
->hwnd
, SW_HIDE
);
3203 /* hide sub entries */
3205 LRESULT res
= ListBox_GetItemData(pane
->hwnd
, idx
+1);
3206 Entry
* sub
= (Entry
*) res
;
3208 if (res
==LB_ERR
|| !sub
|| sub
->level
<=dir
->level
)
3211 ListBox_DeleteString(pane
->hwnd
, idx
+1);
3214 dir
->expanded
= FALSE
;
3216 ShowWindow(pane
->hwnd
, SW_SHOW
);
3220 static void set_curdir(ChildWnd
* child
, Entry
* entry
, HWND hwnd
)
3222 TCHAR path
[MAX_PATH
];
3226 child
->left
.cur
= entry
;
3227 child
->right
.root
= entry
->down
? entry
->down
: entry
;
3228 child
->right
.cur
= entry
;
3230 if (!entry
->scanned
)
3231 scan_entry(child
, entry
, hwnd
);
3233 ListBox_ResetContent(child
->right
.hwnd
);
3234 insert_entries(&child
->right
, entry
->down
, -1);
3235 calc_widths(&child
->right
, FALSE
);
3236 #ifndef _NO_EXTENSIONS
3237 set_header(&child
->right
);
3241 get_path(entry
, path
);
3242 lstrcpy(child
->path
, path
);
3244 if (child
->hwnd
) /* only change window title, if the window already exists */
3245 SetWindowText(child
->hwnd
, path
);
3248 SetCurrentDirectory(path
);
3252 BOOL
launch_file(HWND hwnd
, LPCTSTR cmd
, UINT nCmdShow
)
3254 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3256 if ((int)hinst
<= 32) {
3257 display_error(hwnd
, GetLastError());
3265 BOOL
launch_fileA(HWND hwnd
, LPSTR cmd
, UINT nCmdShow
)
3267 HINSTANCE hinst
= ShellExecuteA(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3269 if ((int)hinst
<= 32) {
3270 display_error(hwnd
, GetLastError());
3279 BOOL
launch_entry(Entry
* entry
, HWND hwnd
, UINT nCmdShow
)
3281 TCHAR cmd
[MAX_PATH
];
3283 #ifdef _SHELL_FOLDERS
3284 if (entry
->etype
== ET_SHELL
) {
3287 SHELLEXECUTEINFO shexinfo
;
3289 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFO
);
3290 shexinfo
.fMask
= SEE_MASK_IDLIST
;
3291 shexinfo
.hwnd
= hwnd
;
3292 shexinfo
.lpVerb
= NULL
;
3293 shexinfo
.lpFile
= NULL
;
3294 shexinfo
.lpParameters
= NULL
;
3295 shexinfo
.lpDirectory
= NULL
;
3296 shexinfo
.nShow
= nCmdShow
;
3297 shexinfo
.lpIDList
= get_to_absolute_pidl(entry
, hwnd
);
3299 if (!ShellExecuteEx(&shexinfo
)) {
3300 display_error(hwnd
, GetLastError());
3304 if (shexinfo
.lpIDList
!= entry
->pidl
)
3305 (*Globals
.iMalloc
->lpVtbl
->Free
)(Globals
.iMalloc
, shexinfo
.lpIDList
);
3311 get_path(entry
, cmd
);
3313 /* start program, open document... */
3314 return launch_file(hwnd
, cmd
, nCmdShow
);
3318 static void activate_entry(ChildWnd
* child
, Pane
* pane
, HWND hwnd
)
3320 Entry
* entry
= pane
->cur
;
3325 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
3326 int scanned_old
= entry
->scanned
;
3329 scan_entry(child
, entry
, hwnd
);
3331 #ifndef _NO_EXTENSIONS
3332 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='\0')
3336 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='.' && entry
->data
.cFileName
[2]=='\0') {
3337 entry
= child
->left
.cur
->up
;
3338 collapse_entry(&child
->left
, entry
);
3340 } else if (entry
->expanded
)
3341 collapse_entry(pane
, child
->left
.cur
);
3343 expand_entry(child
, child
->left
.cur
);
3345 if (!pane
->treePane
) focus_entry
: {
3346 int idx
= ListBox_FindItemData(child
->left
.hwnd
, ListBox_GetCurSel(child
->left
.hwnd
), entry
);
3347 ListBox_SetCurSel(child
->left
.hwnd
, idx
);
3348 set_curdir(child
, entry
, hwnd
);
3353 calc_widths(pane
, FALSE
);
3355 #ifndef _NO_EXTENSIONS
3360 launch_entry(entry
, child
->hwnd
, SW_SHOWNORMAL
);
3365 static BOOL
pane_command(Pane
* pane
, UINT cmd
)
3369 if (pane
->visible_cols
) {
3370 pane
->visible_cols
= 0;
3371 calc_widths(pane
, TRUE
);
3372 #ifndef _NO_EXTENSIONS
3375 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3376 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
|MF_CHECKED
);
3377 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
);
3378 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
3382 case ID_VIEW_ALL_ATTRIBUTES
:
3383 if (pane
->visible_cols
!= COL_ALL
) {
3384 pane
->visible_cols
= COL_ALL
;
3385 calc_widths(pane
, TRUE
);
3386 #ifndef _NO_EXTENSIONS
3389 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3390 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
);
3391 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
|MF_CHECKED
);
3392 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
3396 #ifndef _NO_EXTENSIONS
3397 case ID_PREFERED_SIZES
: {
3398 calc_widths(pane
, TRUE
);
3400 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3404 /* TODO: more command ids... */
3414 static IContextMenu2
* s_pctxmenu2
= NULL
;
3416 #ifndef __MINGW32__ // IContextMenu3 missing in MinGW (as of 6.2.2005)
3417 static IContextMenu3
* s_pctxmenu3
= NULL
;
3420 static void CtxMenu_reset()
3424 #ifndef __MINGW32__ // IContextMenu3 missing in MinGW (as of 6.2.2005)
3429 IContextMenu
* CtxMenu_query_interfaces(IContextMenu
* pcm1
)
3431 IContextMenu
* pcm
= NULL
;
3435 #ifndef __MINGW32__ // IContextMenu3 missing in MinGW (as of 6.2.2005)
3436 if ((*pcm1
->lpVtbl
->QueryInterface
)(pcm1
, &IID_IContextMenu3
, (void**)&pcm
) == NOERROR
)
3437 s_pctxmenu3
= (LPCONTEXTMENU3
)pcm
;
3440 if ((*pcm1
->lpVtbl
->QueryInterface
)(pcm1
, &IID_IContextMenu2
, (void**)&pcm
) == NOERROR
)
3441 s_pctxmenu2
= (LPCONTEXTMENU2
)pcm
;
3444 (*pcm1
->lpVtbl
->Release
)(pcm1
);
3450 static BOOL
CtxMenu_HandleMenuMsg(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3452 #ifndef __MINGW32__ // IContextMenu3 missing in MinGW (as of 6.2.2005)
3454 if (SUCCEEDED((*s_pctxmenu3
->lpVtbl
->HandleMenuMsg
)(s_pctxmenu3
, nmsg
, wparam
, lparam
)))
3460 if (SUCCEEDED((*s_pctxmenu2
->lpVtbl
->HandleMenuMsg
)(s_pctxmenu2
, nmsg
, wparam
, lparam
)))
3467 static HRESULT
ShellFolderContextMenu(IShellFolder
* shell_folder
, HWND hwndParent
, int cidl
, LPCITEMIDLIST
* apidl
, int x
, int y
)
3471 HRESULT hr
= (*shell_folder
->lpVtbl
->GetUIObjectOf
)(shell_folder
, hwndParent
, cidl
, apidl
, &IID_IContextMenu
, NULL
, (LPVOID
*)&pcm
);
3472 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
3474 if (SUCCEEDED(hr
)) {
3475 HMENU hmenu
= CreatePopupMenu();
3477 pcm
= CtxMenu_query_interfaces(pcm
);
3480 hr
= (*pcm
->lpVtbl
->QueryContextMenu
)(pcm
, hmenu
, 0, FCIDM_SHVIEWFIRST
, FCIDM_SHVIEWLAST
, CMF_NORMAL
);
3482 if (SUCCEEDED(hr
)) {
3483 UINT idCmd
= TrackPopupMenu(hmenu
, TPM_LEFTALIGN
|TPM_RETURNCMD
|TPM_RIGHTBUTTON
, x
, y
, 0, hwndParent
, NULL
);
3488 CMINVOKECOMMANDINFO cmi
;
3490 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFO
);
3492 cmi
.hwnd
= hwndParent
;
3493 cmi
.lpVerb
= (LPCSTR
)(INT_PTR
)(idCmd
- FCIDM_SHVIEWFIRST
);
3494 cmi
.lpParameters
= NULL
;
3495 cmi
.lpDirectory
= NULL
;
3496 cmi
.nShow
= SW_SHOWNORMAL
;
3500 hr
= (*pcm
->lpVtbl
->InvokeCommand
)(pcm
, &cmi
);
3506 (*pcm
->lpVtbl
->Release
)(pcm
);
3513 LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3515 static int last_split
;
3517 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(hwnd
, GWL_USERDATA
);
3522 LPDRAWITEMSTRUCT dis
= (LPDRAWITEMSTRUCT
)lparam
;
3523 Entry
* entry
= (Entry
*) dis
->itemData
;
3525 if (dis
->CtlID
== IDW_TREE_LEFT
)
3526 draw_item(&child
->left
, dis
, entry
, -1);
3527 else if (dis
->CtlID
== IDW_TREE_RIGHT
)
3528 draw_item(&child
->right
, dis
, entry
, -1);
3530 goto draw_menu_item
;
3535 InitChildWindow(child
);
3539 free_child_window(child
);
3540 SetWindowLong(hwnd
, GWL_USERDATA
, 0);
3547 GetClientRect(hwnd
, &rt
);
3548 BeginPaint(hwnd
, &ps
);
3549 rt
.left
= child
->split_pos
-SPLIT_WIDTH
/2;
3550 rt
.right
= child
->split_pos
+SPLIT_WIDTH
/2+1;
3551 lastBrush
= SelectBrush(ps
.hdc
, (HBRUSH
)GetStockObject(COLOR_SPLITBAR
));
3552 Rectangle(ps
.hdc
, rt
.left
, rt
.top
-1, rt
.right
, rt
.bottom
+1);
3553 SelectObject(ps
.hdc
, lastBrush
);
3554 #ifdef _NO_EXTENSIONS
3555 rt
.top
= rt
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
3556 FillRect(ps
.hdc
, &rt
, GetStockObject(BLACK_BRUSH
));
3558 EndPaint(hwnd
, &ps
);
3562 if (LOWORD(lparam
) == HTCLIENT
) {
3565 ScreenToClient(hwnd
, &pt
);
3567 if (pt
.x
>=child
->split_pos
-SPLIT_WIDTH
/2 && pt
.x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
3568 SetCursor(LoadCursor(0, IDC_SIZEWE
));
3574 case WM_LBUTTONDOWN
: {
3576 int x
= GET_X_LPARAM(lparam
);
3578 GetClientRect(hwnd
, &rt
);
3580 if (x
>=child
->split_pos
-SPLIT_WIDTH
/2 && x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
3581 last_split
= child
->split_pos
;
3582 #ifdef _NO_EXTENSIONS
3583 draw_splitbar(hwnd
, last_split
);
3591 if (GetCapture() == hwnd
) {
3592 #ifdef _NO_EXTENSIONS
3594 int x
= LOWORD(lparam
);
3595 draw_splitbar(hwnd
, last_split
);
3597 GetClientRect(hwnd
, &rt
);
3598 child
->split_pos
= x
;
3599 resize_tree(child
, rt
.right
, rt
.bottom
);
3605 #ifdef _NO_EXTENSIONS
3606 case WM_CAPTURECHANGED
:
3607 if (GetCapture()==hwnd
&& last_split
>=0)
3608 draw_splitbar(hwnd
, last_split
);
3613 if (wparam
== VK_ESCAPE
)
3614 if (GetCapture() == hwnd
) {
3616 #ifdef _NO_EXTENSIONS
3617 draw_splitbar(hwnd
, last_split
);
3619 child
->split_pos
= last_split
;
3621 GetClientRect(hwnd
, &rt
);
3622 resize_tree(child
, rt
.right
, rt
.bottom
);
3625 SetCursor(LoadCursor(0, IDC_ARROW
));
3630 if (GetCapture() == hwnd
) {
3632 int x
= LOWORD(lparam
);
3634 #ifdef _NO_EXTENSIONS
3635 HDC hdc
= GetDC(hwnd
);
3636 GetClientRect(hwnd
, &rt
);
3638 rt
.left
= last_split
-SPLIT_WIDTH
/2;
3639 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
3640 InvertRect(hdc
, &rt
);
3643 rt
.left
= x
-SPLIT_WIDTH
/2;
3644 rt
.right
= x
+SPLIT_WIDTH
/2+1;
3645 InvertRect(hdc
, &rt
);
3647 ReleaseDC(hwnd
, hdc
);
3649 GetClientRect(hwnd
, &rt
);
3651 if (x
>=0 && x
<rt
.right
) {
3652 child
->split_pos
= x
;
3653 resize_tree(child
, rt
.right
, rt
.bottom
);
3654 rt
.left
= x
-SPLIT_WIDTH
/2;
3655 rt
.right
= x
+SPLIT_WIDTH
/2+1;
3656 InvalidateRect(hwnd
, &rt
, FALSE
);
3657 UpdateWindow(child
->left
.hwnd
);
3659 UpdateWindow(child
->right
.hwnd
);
3665 #ifndef _NO_EXTENSIONS
3666 case WM_GETMINMAXINFO
:
3667 DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
3669 {LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
3671 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
3672 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
3674 #endif /* _NO_EXTENSIONS */
3677 SetCurrentDirectory(child
->path
);
3678 SetFocus(child
->focus_pane
? child
->right
.hwnd
: child
->left
.hwnd
);
3681 case WM_DISPATCH_COMMAND
: {
3682 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
3684 switch(LOWORD(wparam
)) {
3685 case ID_WINDOW_NEW
: {
3686 ChildWnd
* new_child
= alloc_child_window(child
->path
, NULL
, hwnd
);
3688 if (!create_child_window(new_child
))
3694 scan_entry(child
, pane
->cur
, hwnd
);
3698 activate_entry(child
, pane
, hwnd
);
3701 case ID_FILE_MOVE
: {
3702 TCHAR new_name
[BUFFER_LEN
], old_name
[BUFFER_LEN
];
3705 int ret
= DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_SELECT_DESTINATION
), hwnd
, DestinationDlgProc
, (LPARAM
)new_name
);
3709 if (new_name
[0]!='/' && new_name
[1]!=':') {
3710 get_path(pane
->cur
->up
, old_name
);
3711 len
= lstrlen(old_name
);
3713 if (old_name
[len
-1]!='\\' && old_name
[len
-1]!='/') {
3714 old_name
[len
++] = '/';
3715 old_name
[len
] = '\n';
3718 lstrcpy(&old_name
[len
], new_name
);
3719 lstrcpy(new_name
, old_name
);
3722 get_path(pane
->cur
, old_name
);
3724 if (MoveFileEx(old_name
, new_name
, MOVEFILE_COPY_ALLOWED
)) {
3725 if (pane
->treePane
) {
3726 pane
->root
->scanned
= FALSE
;
3727 pane
->cur
= pane
->root
;
3728 activate_entry(child
, pane
, hwnd
);
3731 scan_entry(child
, pane
->root
, hwnd
);
3734 display_error(hwnd
, GetLastError());
3738 return pane_command(pane
, LOWORD(wparam
));
3744 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
3746 switch(HIWORD(wparam
)) {
3747 case LBN_SELCHANGE
: {
3748 int idx
= ListBox_GetCurSel(pane
->hwnd
);
3749 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, idx
);
3751 if (pane
== &child
->left
)
3752 set_curdir(child
, entry
, hwnd
);
3758 activate_entry(child
, pane
, hwnd
);
3763 #ifndef _NO_EXTENSIONS
3765 NMHDR
* pnmh
= (NMHDR
*) lparam
;
3766 return pane_notify(pnmh
->idFrom
==IDW_HEADER_LEFT
? &child
->left
: &child
->right
, pnmh
);}
3769 #ifdef _SHELL_FOLDERS
3770 case WM_CONTEXTMENU
: {
3774 /* first select the current item in the listbox */
3775 HWND hpanel
= (HWND
) wparam
;
3776 POINTS
* ppos
= &MAKEPOINTS(lparam
);
3777 POINT pt
; POINTSTOPOINT(pt
, *ppos
);
3778 ScreenToClient(hpanel
, &pt
);
3779 SendMessage(hpanel
, WM_LBUTTONDOWN
, 0, MAKELONG(pt
.x
, pt
.y
));
3780 SendMessage(hpanel
, WM_LBUTTONUP
, 0, MAKELONG(pt
.x
, pt
.y
));
3782 /* now create the popup menu using shell namespace and IContextMenu */
3783 pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
3784 idx
= ListBox_GetCurSel(pane
->hwnd
);
3788 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, idx
);
3790 LPITEMIDLIST pidl_abs
= get_to_absolute_pidl(entry
, hwnd
);
3793 IShellFolder
* parentFolder
;
3794 LPCITEMIDLIST pidlLast
;
3796 /* get and use the parent folder to display correct context menu in all cases */
3797 if (SUCCEEDED(SHBindToParent(pidl_abs
, &IID_IShellFolder
, (LPVOID
*)&parentFolder
, &pidlLast
))) {
3798 hr
= ShellFolderContextMenu(parentFolder
, hwnd
, 1, &pidlLast
, ppos
->x
, ppos
->y
);
3800 (*parentFolder
->lpVtbl
->Release
)(parentFolder
);
3803 (*Globals
.iMalloc
->lpVtbl
->Free
)(Globals
.iMalloc
, pidl_abs
);
3809 case WM_MEASUREITEM
:
3811 if (!wparam
) // Is the message menu-related?
3812 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
3817 case WM_INITMENUPOPUP
:
3818 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
3823 #ifndef __MINGW32__ // IContextMenu3 missing in MinGW (as of 6.2.2005)
3824 case WM_MENUCHAR
: // only supported by IContextMenu3
3826 LRESULT lResult
= 0;
3828 (*s_pctxmenu3
->lpVtbl
->HandleMenuMsg2
)(s_pctxmenu3
, nmsg
, wparam
, lparam
, &lResult
);
3837 if (wparam
!= SIZE_MINIMIZED
)
3838 resize_tree(child
, LOWORD(lparam
), HIWORD(lparam
));
3842 return DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
3849 LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3851 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(GetParent(hwnd
), GWL_USERDATA
);
3852 Pane
* pane
= (Pane
*) GetWindowLong(hwnd
, GWL_USERDATA
);
3856 #ifndef _NO_EXTENSIONS
3863 child
->focus_pane
= pane
==&child
->right
? 1: 0;
3864 ListBox_SetSel(hwnd
, TRUE
, 1);
3865 /*TODO: check menu items */
3869 if (wparam
== VK_TAB
) {
3870 /*TODO: SetFocus(Globals.hdrivebar) */
3871 SetFocus(child
->focus_pane
? child
->left
.hwnd
: child
->right
.hwnd
);
3875 return CallWindowProc(g_orgTreeWndProc
, hwnd
, nmsg
, wparam
, lparam
);
3879 static void InitInstance(HINSTANCE hinstance
)
3881 const static TCHAR sFont
[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
3888 INITCOMMONCONTROLSEX icc
= {
3889 sizeof(INITCOMMONCONTROLSEX
),
3895 setlocale(LC_COLLATE
, ""); /* set collating rules to local settings for compareName */
3897 InitCommonControlsEx(&icc
);
3900 /* register frame window class */
3902 wcFrame
.cbSize
= sizeof(WNDCLASSEX
);
3904 wcFrame
.lpfnWndProc
= FrameWndProc
;
3905 wcFrame
.cbClsExtra
= 0;
3906 wcFrame
.cbWndExtra
= 0;
3907 wcFrame
.hInstance
= hinstance
;
3908 wcFrame
.hIcon
= LoadIcon(hinstance
, MAKEINTRESOURCE(IDI_WINEFILE
));
3909 wcFrame
.hCursor
= LoadCursor(0, IDC_ARROW
);
3910 wcFrame
.hbrBackground
= 0;
3911 wcFrame
.lpszMenuName
= 0;
3912 wcFrame
.lpszClassName
= sWINEFILEFRAME
;
3913 wcFrame
.hIconSm
= (HICON
)LoadImage(hinstance
,
3914 MAKEINTRESOURCE(IDI_WINEFILE
),
3916 GetSystemMetrics(SM_CXSMICON
),
3917 GetSystemMetrics(SM_CYSMICON
),
3920 Globals
.hframeClass
= RegisterClassEx(&wcFrame
);
3923 /* register tree windows class */
3925 wcChild
.style
= CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
;
3926 wcChild
.lpfnWndProc
= ChildWndProc
;
3927 wcChild
.cbClsExtra
= 0;
3928 wcChild
.cbWndExtra
= 0;
3929 wcChild
.hInstance
= hinstance
;
3931 wcChild
.hCursor
= LoadCursor(0, IDC_ARROW
);
3932 wcChild
.hbrBackground
= 0;
3933 wcChild
.lpszMenuName
= 0;
3934 wcChild
.lpszClassName
= sWINEFILETREE
;
3936 hChildClass
= RegisterClass(&wcChild
);
3939 Globals
.haccel
= LoadAccelerators(hinstance
, MAKEINTRESOURCE(IDA_WINEFILE
));
3941 Globals
.hfont
= CreateFont(-MulDiv(8,GetDeviceCaps(hdc
,LOGPIXELSY
),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont
);
3945 Globals
.hInstance
= hinstance
;
3947 #ifdef _SHELL_FOLDERS
3949 CoGetMalloc(MEMCTX_TASK
, &Globals
.iMalloc
);
3950 SHGetDesktopFolder(&Globals
.iDesktop
);
3952 Globals
.cfStrFName
= RegisterClipboardFormatA(CFSTR_FILENAME
);
3954 Globals
.cfStrFName
= RegisterClipboardFormat(CFSTR_FILENAME
);
3958 /* load column strings */
3961 load_string(g_pos_names
[col
++], IDS_COL_NAME
);
3962 load_string(g_pos_names
[col
++], IDS_COL_SIZE
);
3963 load_string(g_pos_names
[col
++], IDS_COL_CDATE
);
3964 #ifndef _NO_EXTENSIONS
3965 load_string(g_pos_names
[col
++], IDS_COL_ADATE
);
3966 load_string(g_pos_names
[col
++], IDS_COL_MDATE
);
3967 load_string(g_pos_names
[col
++], IDS_COL_IDX
);
3968 load_string(g_pos_names
[col
++], IDS_COL_LINKS
);
3970 load_string(g_pos_names
[col
++], IDS_COL_ATTR
);
3971 #ifndef _NO_EXTENSIONS
3972 load_string(g_pos_names
[col
++], IDS_COL_SEC
);
3977 void show_frame(HWND hwndParent
, int cmdshow
)
3979 const static TCHAR sMDICLIENT
[] = {'M','D','I','C','L','I','E','N','T','\0'};
3981 TCHAR path
[MAX_PATH
], b1
[BUFFER_LEN
];
3983 HMENU hMenuFrame
, hMenuWindow
;
3985 CLIENTCREATESTRUCT ccs
;
3987 if (Globals
.hMainWnd
)
3990 Globals
.hwndParent
= hwndParent
;
3992 hMenuFrame
= LoadMenu(Globals
.hInstance
, MAKEINTRESOURCE(IDM_WINEFILE
));
3993 hMenuWindow
= GetSubMenu(hMenuFrame
, GetMenuItemCount(hMenuFrame
)-2);
3995 Globals
.hMenuFrame
= hMenuFrame
;
3996 Globals
.hMenuView
= GetSubMenu(hMenuFrame
, 3);
3997 Globals
.hMenuOptions
= GetSubMenu(hMenuFrame
, 4);
3999 ccs
.hWindowMenu
= hMenuWindow
;
4000 ccs
.idFirstChild
= IDW_FIRST_CHILD
;
4003 /* create main window */
4004 Globals
.hMainWnd
= CreateWindowEx(0, (LPCTSTR
)(int)Globals
.hframeClass
, RS(b1
,IDS_WINE_FILE
), WS_OVERLAPPEDWINDOW
,
4005 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
4006 hwndParent
, Globals
.hMenuFrame
, Globals
.hInstance
, 0/*lpParam*/);
4009 Globals
.hmdiclient
= CreateWindowEx(0, sMDICLIENT
, NULL
,
4010 WS_CHILD
|WS_CLIPCHILDREN
|WS_VSCROLL
|WS_HSCROLL
|WS_VISIBLE
|WS_BORDER
,
4012 Globals
.hMainWnd
, 0, Globals
.hInstance
, &ccs
);
4016 TBBUTTON drivebarBtn
= {0, 0, TBSTATE_ENABLED
, BTNS_SEP
, {0, 0}, 0, 0};
4020 Globals
.hdrivebar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
,
4021 IDW_DRIVEBAR
, 2, Globals
.hInstance
, IDB_DRIVEBAR
, &drivebarBtn
,
4022 1, 16, 13, 16, 13, sizeof(TBBUTTON
));
4023 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_DRIVE_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4025 GetLogicalDriveStrings(BUFFER_LEN
, Globals
.drives
);
4027 drivebarBtn
.fsStyle
= BTNS_BUTTON
;
4029 #ifndef _NO_EXTENSIONS
4031 /* insert unix file system button */
4035 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
4037 drivebarBtn
.idCommand
= ID_DRIVE_UNIX_FS
;
4038 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
4039 drivebarBtn
.iString
++;
4041 #ifdef _SHELL_FOLDERS
4042 /* insert shell namespace button */
4043 load_string(b1
, IDS_SHELL
);
4044 b1
[lstrlen(b1
)+1] = '\0';
4045 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
4047 drivebarBtn
.idCommand
= ID_DRIVE_SHELL_NS
;
4048 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
4049 drivebarBtn
.iString
++;
4052 /* register windows drive root strings */
4053 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)Globals
.drives
);
4056 drivebarBtn
.idCommand
= ID_DRIVE_FIRST
;
4058 for(p
=Globals
.drives
; *p
; ) {
4059 #ifdef _NO_EXTENSIONS
4060 /* insert drive letter */
4061 TCHAR b
[3] = {tolower(*p
)};
4062 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b
);
4064 switch(GetDriveType(p
)) {
4065 case DRIVE_REMOVABLE
: drivebarBtn
.iBitmap
= 1; break;
4066 case DRIVE_CDROM
: drivebarBtn
.iBitmap
= 3; break;
4067 case DRIVE_REMOTE
: drivebarBtn
.iBitmap
= 4; break;
4068 case DRIVE_RAMDISK
: drivebarBtn
.iBitmap
= 5; break;
4069 default:/*DRIVE_FIXED*/ drivebarBtn
.iBitmap
= 2;
4072 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
4073 drivebarBtn
.idCommand
++;
4074 drivebarBtn
.iString
++;
4081 TBBUTTON toolbarBtns
[] = {
4082 {0, 0, 0, BTNS_SEP
, {0, 0}, 0, 0},
4083 {0, ID_WINDOW_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4084 {1, ID_WINDOW_CASCADE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4085 {2, ID_WINDOW_TILE_HORZ
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4086 {3, ID_WINDOW_TILE_VERT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4088 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4089 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4092 Globals
.htoolbar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
,
4093 IDW_TOOLBAR
, 2, Globals
.hInstance
, IDB_TOOLBAR
, toolbarBtns
,
4094 sizeof(toolbarBtns
)/sizeof(TBBUTTON
), 16, 15, 16, 15, sizeof(TBBUTTON
));
4095 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_TOOL_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4098 Globals
.hstatusbar
= CreateStatusWindow(WS_CHILD
|WS_VISIBLE
, 0, Globals
.hMainWnd
, IDW_STATUSBAR
);
4099 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
4101 /* CreateStatusWindow does not accept WS_BORDER
4102 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
4103 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
4104 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
4106 /*TODO: read paths and window placements from registry */
4107 GetCurrentDirectory(MAX_PATH
, path
);
4109 ShowWindow(Globals
.hMainWnd
, cmdshow
);
4111 //#if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4112 // // Shell Namespace as default:
4113 // child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
4115 child
= alloc_child_window(path
, NULL
, Globals
.hMainWnd
);
4118 child
->pos
.showCmd
= SW_SHOWMAXIMIZED
;
4119 child
->pos
.rcNormalPosition
.left
= 0;
4120 child
->pos
.rcNormalPosition
.top
= 0;
4121 child
->pos
.rcNormalPosition
.right
= 320;
4122 child
->pos
.rcNormalPosition
.bottom
= 280;
4124 if (!create_child_window(child
))
4127 SetWindowPlacement(child
->hwnd
, &child
->pos
);
4129 Globals
.himl
= ImageList_LoadBitmap(Globals
.hInstance
, MAKEINTRESOURCE(IDB_IMAGES
), 16, 0, RGB(0,255,0));
4131 Globals
.prescan_node
= FALSE
;
4133 UpdateWindow(Globals
.hMainWnd
);
4138 #ifdef _SHELL_FOLDERS
4139 (*Globals
.iDesktop
->lpVtbl
->Release
)(Globals
.iDesktop
);
4140 (*Globals
.iMalloc
->lpVtbl
->Release
)(Globals
.iMalloc
);
4144 ImageList_Destroy(Globals
.himl
);
4148 /* search for already running win[e]files */
4150 static int g_foundPrevInstance
= 0;
4152 static BOOL CALLBACK
EnumWndProc(HWND hwnd
, LPARAM lparam
)
4156 GetClassName(hwnd
, cls
, 128);
4158 if (!lstrcmp(cls
, (LPCTSTR
)lparam
)) {
4159 g_foundPrevInstance
++;
4166 /* search for window of given class name to allow only one running instance */
4167 int find_window_class(LPCTSTR classname
)
4169 EnumWindows(EnumWndProc
, (LPARAM
)classname
);
4171 if (g_foundPrevInstance
)
4178 int winefile_main(HINSTANCE hinstance
, HWND hwndParent
, int cmdshow
)
4182 InitInstance(hinstance
);
4184 if (cmdshow
== SW_SHOWNORMAL
)
4185 /*TODO: read window placement from registry */
4186 cmdshow
= SW_MAXIMIZE
;
4188 show_frame(hwndParent
, cmdshow
);
4190 while(GetMessage(&msg
, 0, 0, 0)) {
4191 if (Globals
.hmdiclient
&& TranslateMDISysAccel(Globals
.hmdiclient
, &msg
))
4194 if (Globals
.hMainWnd
&& TranslateAccelerator(Globals
.hMainWnd
, Globals
.haccel
, &msg
))
4197 TranslateMessage(&msg
);
4198 DispatchMessage(&msg
);
4207 int APIENTRY
WinMain(HINSTANCE hinstance
,
4208 HINSTANCE previnstance
,
4212 #ifdef _NO_EXTENSIONS
4213 if (find_window_class(sWINEFILEFRAME
))
4217 winefile_main(hinstance
, 0, cmdshow
);