4 * Copyright 2000, 2003, 2004, 2005 Martin Fuchs
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
25 /* for unix filesystem function calls */
27 #include <sys/types.h>
40 #define _MAX_FNAME 256
41 #define _MAX_DIR _MAX_FNAME
42 #define _MAX_EXT _MAX_FNAME
46 #ifdef NONAMELESSUNION
47 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
49 #define UNION_MEMBER(x) x
54 #define DEFAULT_SPLIT_POS 300
56 #define DEFAULT_SPLIT_POS 200
68 typedef struct _Entry
{
79 #ifndef _NO_EXTENSIONS
80 BY_HANDLE_FILE_INFORMATION bhfi
;
82 enum ENTRY_TYPE etype
;
94 TCHAR volname
[_MAX_FNAME
];
104 COL_ATTRIBUTES
= 0x08,
106 #ifdef _NO_EXTENSIONS
107 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
111 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
|COL_INDEX
|COL_LINKS
124 #ifndef _NO_EXTENSIONS
128 #ifndef _NO_EXTENSIONS
134 int positions
[COLUMNS
+1];
146 int focus_pane
; /* 0: left 1: right */
149 BOOL header_wdths_ok
;
151 TCHAR path
[MAX_PATH
];
152 TCHAR filter_pattern
[MAX_PATH
];
156 SORT_ORDER sortOrder
;
161 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
);
162 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
);
163 static void refresh_child(ChildWnd
* child
);
164 static void refresh_drives(void);
165 static void get_path(Entry
* dir
, PTSTR path
);
166 static void format_date(const FILETIME
* ft
, TCHAR
* buffer
, int visible_cols
);
168 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
169 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
170 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
174 WINEFILE_GLOBALS Globals
;
176 static int last_split
;
178 /* some common string constants */
179 const static TCHAR sEmpty
[] = {'\0'};
180 const static TCHAR sSpace
[] = {' ', '\0'};
181 const static TCHAR sNumFmt
[] = {'%','d','\0'};
182 const static TCHAR sQMarks
[] = {'?','?','?','\0'};
184 /* window class names */
185 const static TCHAR sWINEFILEFRAME
[] = {'W','F','S','_','F','r','a','m','e','\0'};
186 const static TCHAR sWINEFILETREE
[] = {'W','F','S','_','T','r','e','e','\0'};
189 /* #define LONGLONGARG _T("I64") */
190 const static TCHAR sLongHexFmt
[] = {'%','I','6','4','X','\0'};
191 const static TCHAR sLongNumFmt
[] = {'%','I','6','4','d','\0'};
193 /* #define LONGLONGARG _T("L") */
194 const static TCHAR sLongHexFmt
[] = {'%','L','X','\0'};
195 const static TCHAR sLongNumFmt
[] = {'%','L','d','\0'};
199 /* load resource string */
200 static LPTSTR
load_string(LPTSTR buffer
, UINT id
)
202 LoadString(Globals
.hInstance
, id
, buffer
, BUFFER_LEN
);
207 #define RS(b, i) load_string(b, i)
210 /* display error message for the specified WIN32 error code */
211 static void display_error(HWND hwnd
, DWORD error
)
213 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
216 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_FROM_SYSTEM
,
217 0, error
, MAKELANGID(LANG_NEUTRAL
,SUBLANG_DEFAULT
), (PTSTR
)&msg
, 0, NULL
))
218 MessageBox(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
220 MessageBox(hwnd
, RS(b1
,IDS_ERROR
), RS(b2
,IDS_WINEFILE
), MB_OK
);
226 /* display network error message using WNetGetLastError() */
227 static void display_network_error(HWND hwnd
)
229 TCHAR msg
[BUFFER_LEN
], provider
[BUFFER_LEN
], b2
[BUFFER_LEN
];
232 if (WNetGetLastError(&error
, msg
, BUFFER_LEN
, provider
, BUFFER_LEN
) == NO_ERROR
)
233 MessageBox(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
241 /* call vswprintf() in msvcrt.dll */
242 /*TODO: fix swprintf() in non-msvcrt mode, so that this dynamic linking function can be removed */
243 static int msvcrt_swprintf(WCHAR
* buffer
, const WCHAR
* fmt
, ...)
245 static int (__cdecl
*pvswprintf
)(WCHAR
*, const WCHAR
*, va_list) = NULL
;
250 HMODULE hModMsvcrt
= LoadLibraryA("msvcrt");
251 pvswprintf
= (int(__cdecl
*)(WCHAR
*,const WCHAR
*,va_list)) GetProcAddress(hModMsvcrt
, "vswprintf");
255 ret
= (*pvswprintf
)(buffer
, fmt
, ap
);
261 static LPCWSTR
my_wcsrchr(LPCWSTR str
, WCHAR c
)
276 #define _tcsrchr my_wcsrchr
278 #define _tcsrchr strrchr
281 #endif /* __WINE__ */
284 /* allocate and initialise a directory entry */
285 static Entry
* alloc_entry(void)
287 Entry
* entry
= (Entry
*) malloc(sizeof(Entry
));
289 #ifdef _SHELL_FOLDERS
291 entry
->folder
= NULL
;
298 /* free a directory entry */
299 static void free_entry(Entry
* entry
)
301 #ifdef _SHELL_FOLDERS
302 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
303 DestroyIcon(entry
->hicon
);
305 if (entry
->folder
&& entry
->folder
!=Globals
.iDesktop
)
306 (*entry
->folder
->lpVtbl
->Release
)(entry
->folder
);
309 (*Globals
.iMalloc
->lpVtbl
->Free
)(Globals
.iMalloc
, entry
->pidl
);
315 /* recursively free all child entries */
316 static void free_entries(Entry
* dir
)
318 Entry
*entry
, *next
=dir
->down
;
334 static void read_directory_win(Entry
* dir
, LPCTSTR path
)
336 Entry
* first_entry
= NULL
;
340 int level
= dir
->level
+ 1;
341 WIN32_FIND_DATA w32fd
;
343 #ifndef _NO_EXTENSIONS
347 TCHAR buffer
[MAX_PATH
], *p
;
348 for(p
=buffer
; *path
; )
355 hFind
= FindFirstFile(buffer
, &w32fd
);
357 if (hFind
!= INVALID_HANDLE_VALUE
) {
359 #ifdef _NO_EXTENSIONS
360 /* hide directory entry "." */
361 if (w32fd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
362 LPCTSTR name
= w32fd
.cFileName
;
364 if (name
[0]=='.' && name
[1]=='\0')
368 entry
= alloc_entry();
376 memcpy(&entry
->data
, &w32fd
, sizeof(WIN32_FIND_DATA
));
379 entry
->expanded
= FALSE
;
380 entry
->scanned
= FALSE
;
381 entry
->level
= level
;
383 #ifndef _NO_EXTENSIONS
384 entry
->etype
= ET_WINDOWS
;
385 entry
->bhfi_valid
= FALSE
;
387 lstrcpy(p
, entry
->data
.cFileName
);
389 hFile
= CreateFile(buffer
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
390 0, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0);
392 if (hFile
!= INVALID_HANDLE_VALUE
) {
393 if (GetFileInformationByHandle(hFile
, &entry
->bhfi
))
394 entry
->bhfi_valid
= TRUE
;
401 } while(FindNextFile(hFind
, &w32fd
));
409 dir
->down
= first_entry
;
414 static Entry
* find_entry_win(Entry
* dir
, LPCTSTR name
)
418 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
420 LPCTSTR q
= entry
->data
.cFileName
;
423 if (!*p
|| *p
==TEXT('\\') || *p
==TEXT('/'))
425 } while(tolower(*p
++) == tolower(*q
++));
428 q
= entry
->data
.cAlternateFileName
;
431 if (!*p
|| *p
==TEXT('\\') || *p
==TEXT('/'))
433 } while(tolower(*p
++) == tolower(*q
++));
440 static Entry
* read_tree_win(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
442 TCHAR buffer
[MAX_PATH
];
443 Entry
* entry
= &root
->entry
;
447 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
449 #ifndef _NO_EXTENSIONS
450 entry
->etype
= ET_WINDOWS
;
454 while(*s
&& *s
!=TEXT('\\') && *s
!=TEXT('/'))
457 while(*s
==TEXT('\\') || *s
==TEXT('/'))
463 read_directory(entry
, buffer
, sortOrder
, hwnd
);
466 entry
->expanded
= TRUE
;
471 entry
= find_entry_win(entry
, s
);
474 SetCursor(old_cursor
);
480 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
482 static BOOL
time_to_filetime(const time_t* t
, FILETIME
* ftime
)
484 struct tm
* tm
= gmtime(t
);
490 stime
.wYear
= tm
->tm_year
+1900;
491 stime
.wMonth
= tm
->tm_mon
+1;
492 /* stime.wDayOfWeek */
493 stime
.wDay
= tm
->tm_mday
;
494 stime
.wHour
= tm
->tm_hour
;
495 stime
.wMinute
= tm
->tm_min
;
496 stime
.wSecond
= tm
->tm_sec
;
498 return SystemTimeToFileTime(&stime
, ftime
);
501 static void read_directory_unix(Entry
* dir
, LPCTSTR path
)
503 Entry
* first_entry
= NULL
;
508 int level
= dir
->level
+ 1;
510 char cpath
[MAX_PATH
];
512 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, cpath
, MAX_PATH
, NULL
, NULL
);
514 const char* cpath
= path
;
517 pdir
= opendir(cpath
);
522 char buffer
[MAX_PATH
], *p
;
525 for(p
=buffer
,s
=cpath
; *s
; )
528 if (p
==buffer
|| p
[-1]!='/')
531 while((ent
=readdir(pdir
))) {
532 entry
= alloc_entry();
540 entry
->etype
= ET_UNIX
;
542 strcpy(p
, ent
->d_name
);
544 MultiByteToWideChar(CP_UNIXCP
, 0, p
, -1, entry
->data
.cFileName
, MAX_PATH
);
546 lstrcpy(entry
->data
.cFileName
, p
);
549 if (!stat(buffer
, &st
)) {
550 entry
->data
.dwFileAttributes
= p
[0]=='.'? FILE_ATTRIBUTE_HIDDEN
: 0;
552 if (S_ISDIR(st
.st_mode
))
553 entry
->data
.dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
555 entry
->data
.nFileSizeLow
= st
.st_size
& 0xFFFFFFFF;
556 entry
->data
.nFileSizeHigh
= st
.st_size
>> 32;
558 memset(&entry
->data
.ftCreationTime
, 0, sizeof(FILETIME
));
559 time_to_filetime(&st
.st_atime
, &entry
->data
.ftLastAccessTime
);
560 time_to_filetime(&st
.st_mtime
, &entry
->data
.ftLastWriteTime
);
562 entry
->bhfi
.nFileIndexLow
= ent
->d_ino
;
563 entry
->bhfi
.nFileIndexHigh
= 0;
565 entry
->bhfi
.nNumberOfLinks
= st
.st_nlink
;
567 entry
->bhfi_valid
= TRUE
;
569 entry
->data
.nFileSizeLow
= 0;
570 entry
->data
.nFileSizeHigh
= 0;
571 entry
->bhfi_valid
= FALSE
;
576 entry
->expanded
= FALSE
;
577 entry
->scanned
= FALSE
;
578 entry
->level
= level
;
589 dir
->down
= first_entry
;
593 static Entry
* find_entry_unix(Entry
* dir
, LPCTSTR name
)
597 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
599 LPCTSTR q
= entry
->data
.cFileName
;
602 if (!*p
|| *p
==TEXT('/'))
604 } while(*p
++ == *q
++);
610 static Entry
* read_tree_unix(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
612 TCHAR buffer
[MAX_PATH
];
613 Entry
* entry
= &root
->entry
;
617 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
619 entry
->etype
= ET_UNIX
;
622 while(*s
&& *s
!=TEXT('/'))
625 while(*s
== TEXT('/'))
631 read_directory(entry
, buffer
, sortOrder
, hwnd
);
634 entry
->expanded
= TRUE
;
639 entry
= find_entry_unix(entry
, s
);
642 SetCursor(old_cursor
);
647 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
650 #ifdef _SHELL_FOLDERS
653 #define get_strret get_strretW
654 #define path_from_pidl path_from_pidlW
656 #define get_strret get_strretA
657 #define path_from_pidl path_from_pidlA
661 static void free_strret(STRRET
* str
)
663 if (str
->uType
== STRRET_WSTR
)
664 (*Globals
.iMalloc
->lpVtbl
->Free
)(Globals
.iMalloc
, str
->UNION_MEMBER(pOleStr
));
670 static LPSTR
strcpyn(LPSTR dest
, LPCSTR source
, size_t count
)
675 for(s
=source
; count
&&(*d
++=*s
++); )
681 static void get_strretA(STRRET
* str
, const SHITEMID
* shiid
, LPSTR buffer
, int len
)
685 WideCharToMultiByte(CP_ACP
, 0, str
->UNION_MEMBER(pOleStr
), -1, buffer
, len
, NULL
, NULL
);
689 strcpyn(buffer
, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), len
);
693 strcpyn(buffer
, str
->UNION_MEMBER(cStr
), len
);
697 static HRESULT
path_from_pidlA(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPSTR buffer
, int len
)
701 /* SHGDN_FORPARSING: get full path of id list */
702 HRESULT hr
= (*folder
->lpVtbl
->GetDisplayNameOf
)(folder
, pidl
, SHGDN_FORPARSING
, &str
);
705 get_strretA(&str
, &pidl
->mkid
, buffer
, len
);
715 static LPWSTR
wcscpyn(LPWSTR dest
, LPCWSTR source
, size_t count
)
720 for(s
=source
; count
&&(*d
++=*s
++); )
726 static void get_strretW(STRRET
* str
, const SHITEMID
* shiid
, LPWSTR buffer
, int len
)
730 wcscpyn(buffer
, str
->UNION_MEMBER(pOleStr
), len
);
734 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), -1, buffer
, len
);
738 MultiByteToWideChar(CP_ACP
, 0, str
->UNION_MEMBER(cStr
), -1, buffer
, len
);
743 static HRESULT
name_from_pidl(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPTSTR buffer
, int len
, SHGDNF flags
)
747 HRESULT hr
= (*folder
->lpVtbl
->GetDisplayNameOf
)(folder
, pidl
, flags
, &str
);
750 get_strret(&str
, &pidl
->mkid
, buffer
, len
);
759 static HRESULT
path_from_pidlW(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPWSTR buffer
, int len
)
763 /* SHGDN_FORPARSING: get full path of id list */
764 HRESULT hr
= (*folder
->lpVtbl
->GetDisplayNameOf
)(folder
, pidl
, SHGDN_FORPARSING
, &str
);
767 get_strretW(&str
, &pidl
->mkid
, buffer
, len
);
776 /* create an item id list from a file system path */
778 static LPITEMIDLIST
get_path_pidl(LPTSTR path
, HWND hwnd
)
785 LPWSTR buffer
= path
;
787 WCHAR buffer
[MAX_PATH
];
788 MultiByteToWideChar(CP_ACP
, 0, path
, -1, buffer
, MAX_PATH
);
791 hr
= (*Globals
.iDesktop
->lpVtbl
->ParseDisplayName
)(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
799 /* convert an item id list from relative to absolute (=relative to the desktop) format */
801 static LPITEMIDLIST
get_to_absolute_pidl(Entry
* entry
, HWND hwnd
)
803 if (entry
->up
&& entry
->up
->etype
==ET_SHELL
) {
804 IShellFolder
* folder
= entry
->up
->folder
;
805 WCHAR buffer
[MAX_PATH
];
807 HRESULT hr
= path_from_pidlW(folder
, entry
->pidl
, buffer
, MAX_PATH
);
813 hr
= (*Globals
.iDesktop
->lpVtbl
->ParseDisplayName
)(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
818 } else if (entry
->etype
== ET_WINDOWS
) {
819 TCHAR path
[MAX_PATH
];
821 get_path(entry
, path
);
823 return get_path_pidl(path
, hwnd
);
824 } else if (entry
->pidl
)
825 return ILClone(entry
->pidl
);
831 static HICON
extract_icon(IShellFolder
* folder
, LPCITEMIDLIST pidl
)
833 IExtractIcon
* pExtract
;
835 if (SUCCEEDED((*folder
->lpVtbl
->GetUIObjectOf
)(folder
, 0, 1, (LPCITEMIDLIST
*)&pidl
, &IID_IExtractIcon
, 0, (LPVOID
*)&pExtract
))) {
836 TCHAR path
[_MAX_PATH
];
841 if (SUCCEEDED((*pExtract
->lpVtbl
->GetIconLocation
)(pExtract
, GIL_FORSHELL
, path
, _MAX_PATH
, &idx
, &flags
))) {
842 if (!(flags
& GIL_NOTFILENAME
)) {
844 idx
= 0; /* special case for some control panel applications */
846 if ((int)ExtractIconEx(path
, idx
, 0, &hicon
, 1) > 0)
847 flags
&= ~GIL_DONTCACHE
;
849 HICON hIconLarge
= 0;
851 HRESULT hr
= (*pExtract
->lpVtbl
->Extract
)(pExtract
, path
, idx
, &hIconLarge
, &hicon
, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON
)));
854 DestroyIcon(hIconLarge
);
865 static Entry
* find_entry_shell(Entry
* dir
, LPCITEMIDLIST pidl
)
869 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
870 if (entry
->pidl
->mkid
.cb
== pidl
->mkid
.cb
&&
871 !memcmp(entry
->pidl
, pidl
, entry
->pidl
->mkid
.cb
))
878 static Entry
* read_tree_shell(Root
* root
, LPITEMIDLIST pidl
, SORT_ORDER sortOrder
, HWND hwnd
)
880 Entry
* entry
= &root
->entry
;
882 LPITEMIDLIST next_pidl
= pidl
;
883 IShellFolder
* folder
;
884 IShellFolder
* child
= NULL
;
887 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
889 #ifndef _NO_EXTENSIONS
890 entry
->etype
= ET_SHELL
;
893 folder
= Globals
.iDesktop
;
896 entry
->pidl
= next_pidl
;
897 entry
->folder
= folder
;
902 /* copy first element of item idlist */
903 next_pidl
= (*Globals
.iMalloc
->lpVtbl
->Alloc
)(Globals
.iMalloc
, pidl
->mkid
.cb
+sizeof(USHORT
));
904 memcpy(next_pidl
, pidl
, pidl
->mkid
.cb
);
905 ((LPITEMIDLIST
)((LPBYTE
)next_pidl
+pidl
->mkid
.cb
))->mkid
.cb
= 0;
907 hr
= (*folder
->lpVtbl
->BindToObject
)(folder
, next_pidl
, 0, &IID_IShellFolder
, (void**)&child
);
911 read_directory(entry
, NULL
, sortOrder
, hwnd
);
914 entry
->expanded
= TRUE
;
916 next
= find_entry_shell(entry
, next_pidl
);
923 /* go to next element */
924 pidl
= (LPITEMIDLIST
) ((LPBYTE
)pidl
+pidl
->mkid
.cb
);
927 SetCursor(old_cursor
);
933 static void fill_w32fdata_shell(IShellFolder
* folder
, LPCITEMIDLIST pidl
, SFGAOF attribs
, WIN32_FIND_DATA
* w32fdata
)
935 if (!(attribs
& SFGAO_FILESYSTEM
) ||
936 FAILED(SHGetDataFromIDList(folder
, pidl
, SHGDFIL_FINDDATA
, w32fdata
, sizeof(WIN32_FIND_DATA
)))) {
937 WIN32_FILE_ATTRIBUTE_DATA fad
;
938 IDataObject
* pDataObj
;
940 STGMEDIUM medium
= {0, {0}, 0};
941 FORMATETC fmt
= {Globals
.cfStrFName
, 0, DVASPECT_CONTENT
, -1, TYMED_HGLOBAL
};
943 HRESULT hr
= (*folder
->lpVtbl
->GetUIObjectOf
)(folder
, 0, 1, &pidl
, &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
946 hr
= (*pDataObj
->lpVtbl
->GetData
)(pDataObj
, &fmt
, &medium
);
948 (*pDataObj
->lpVtbl
->Release
)(pDataObj
);
951 LPCTSTR path
= (LPCTSTR
)GlobalLock(medium
.UNION_MEMBER(hGlobal
));
952 UINT sem_org
= SetErrorMode(SEM_FAILCRITICALERRORS
);
954 if (GetFileAttributesEx(path
, GetFileExInfoStandard
, &fad
)) {
955 w32fdata
->dwFileAttributes
= fad
.dwFileAttributes
;
956 w32fdata
->ftCreationTime
= fad
.ftCreationTime
;
957 w32fdata
->ftLastAccessTime
= fad
.ftLastAccessTime
;
958 w32fdata
->ftLastWriteTime
= fad
.ftLastWriteTime
;
960 if (!(fad
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)) {
961 w32fdata
->nFileSizeLow
= fad
.nFileSizeLow
;
962 w32fdata
->nFileSizeHigh
= fad
.nFileSizeHigh
;
966 SetErrorMode(sem_org
);
968 GlobalUnlock(medium
.UNION_MEMBER(hGlobal
));
969 GlobalFree(medium
.UNION_MEMBER(hGlobal
));
974 if (attribs
& (SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
))
975 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
977 if (attribs
& SFGAO_READONLY
)
978 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_READONLY
;
980 if (attribs
& SFGAO_COMPRESSED
)
981 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_COMPRESSED
;
985 static void read_directory_shell(Entry
* dir
, HWND hwnd
)
987 IShellFolder
* folder
= dir
->folder
;
988 int level
= dir
->level
+ 1;
994 Entry
* first_entry
= NULL
;
1001 hr
= (*folder
->lpVtbl
->EnumObjects
)(folder
, hwnd
, SHCONTF_FOLDERS
|SHCONTF_NONFOLDERS
|SHCONTF_INCLUDEHIDDEN
|SHCONTF_SHAREABLE
|SHCONTF_STORAGE
, &idlist
);
1003 if (SUCCEEDED(hr
)) {
1005 #define FETCH_ITEM_COUNT 32
1006 LPITEMIDLIST pidls
[FETCH_ITEM_COUNT
];
1011 memset(pidls
, 0, sizeof(pidls
));
1013 hr
= (*idlist
->lpVtbl
->Next
)(idlist
, FETCH_ITEM_COUNT
, pidls
, &cnt
);
1020 for(n
=0; n
<cnt
; ++n
) {
1021 entry
= alloc_entry();
1024 first_entry
= entry
;
1029 memset(&entry
->data
, 0, sizeof(WIN32_FIND_DATA
));
1030 entry
->bhfi_valid
= FALSE
;
1032 attribs
= ~SFGAO_FILESYSTEM
; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
1034 hr
= (*folder
->lpVtbl
->GetAttributesOf
)(folder
, 1, (LPCITEMIDLIST
*)&pidls
[n
], &attribs
);
1036 if (SUCCEEDED(hr
)) {
1037 if (attribs
!= (SFGAOF
)~SFGAO_FILESYSTEM
) {
1038 fill_w32fdata_shell(folder
, pidls
[n
], attribs
, &entry
->data
);
1040 entry
->bhfi_valid
= TRUE
;
1046 entry
->pidl
= pidls
[n
];
1048 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1049 hr
= (*folder
->lpVtbl
->BindToObject
)(folder
, pidls
[n
], 0, &IID_IShellFolder
, (void**)&child
);
1052 entry
->folder
= child
;
1054 entry
->folder
= NULL
;
1057 entry
->folder
= NULL
;
1059 if (!entry
->data
.cFileName
[0])
1060 /*hr = */name_from_pidl(folder
, pidls
[n
], entry
->data
.cFileName
, MAX_PATH
, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1062 /* get display icons for files and virtual objects */
1063 if (!(entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ||
1064 !(attribs
& SFGAO_FILESYSTEM
)) {
1065 entry
->hicon
= extract_icon(folder
, pidls
[n
]);
1068 entry
->hicon
= (HICON
)-1; /* don't try again later */
1073 entry
->expanded
= FALSE
;
1074 entry
->scanned
= FALSE
;
1075 entry
->level
= level
;
1077 #ifndef _NO_EXTENSIONS
1078 entry
->etype
= ET_SHELL
;
1079 entry
->bhfi_valid
= FALSE
;
1086 (*idlist
->lpVtbl
->Release
)(idlist
);
1092 dir
->down
= first_entry
;
1093 dir
->scanned
= TRUE
;
1096 #endif /* _SHELL_FOLDERS */
1099 /* sort order for different directory/file types */
1108 /* distinguish between ".", ".." and any other directory names */
1109 static int TypeOrderFromDirname(LPCTSTR name
)
1111 if (name
[0] == '.') {
1112 if (name
[1] == '\0')
1113 return TO_DOT
; /* "." */
1115 if (name
[1]=='.' && name
[2]=='\0')
1116 return TO_DOTDOT
; /* ".." */
1119 return TO_OTHER_DIR
; /* anything else */
1122 /* directories first... */
1123 static int compareType(const WIN32_FIND_DATA
* fd1
, const WIN32_FIND_DATA
* fd2
)
1125 int order1
= fd1
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1126 int order2
= fd2
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1128 /* Handle "." and ".." as special case and move them at the very first beginning. */
1129 if (order1
==TO_DIR
&& order2
==TO_DIR
) {
1130 order1
= TypeOrderFromDirname(fd1
->cFileName
);
1131 order2
= TypeOrderFromDirname(fd2
->cFileName
);
1134 return order2
==order1
? 0: order1
<order2
? -1: 1;
1138 static int compareName(const void* arg1
, const void* arg2
)
1140 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1141 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1143 int cmp
= compareType(fd1
, fd2
);
1147 return lstrcmpi(fd1
->cFileName
, fd2
->cFileName
);
1150 static int compareExt(const void* arg1
, const void* arg2
)
1152 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1153 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1154 const TCHAR
*name1
, *name2
, *ext1
, *ext2
;
1156 int cmp
= compareType(fd1
, fd2
);
1160 name1
= fd1
->cFileName
;
1161 name2
= fd2
->cFileName
;
1163 ext1
= _tcsrchr(name1
, TEXT('.'));
1164 ext2
= _tcsrchr(name2
, TEXT('.'));
1176 cmp
= lstrcmpi(ext1
, ext2
);
1180 return lstrcmpi(name1
, name2
);
1183 static int compareSize(const void* arg1
, const void* arg2
)
1185 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1186 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1188 int cmp
= compareType(fd1
, fd2
);
1192 cmp
= fd2
->nFileSizeHigh
- fd1
->nFileSizeHigh
;
1199 cmp
= fd2
->nFileSizeLow
- fd1
->nFileSizeLow
;
1201 return cmp
<0? -1: cmp
>0? 1: 0;
1204 static int compareDate(const void* arg1
, const void* arg2
)
1206 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1207 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1209 int cmp
= compareType(fd1
, fd2
);
1213 return CompareFileTime(&fd2
->ftLastWriteTime
, &fd1
->ftLastWriteTime
);
1217 static int (*sortFunctions
[])(const void* arg1
, const void* arg2
) = {
1218 compareName
, /* SORT_NAME */
1219 compareExt
, /* SORT_EXT */
1220 compareSize
, /* SORT_SIZE */
1221 compareDate
/* SORT_DATE */
1225 static void SortDirectory(Entry
* dir
, SORT_ORDER sortOrder
)
1227 Entry
* entry
= dir
->down
;
1232 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1236 array
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(Entry
*));
1239 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1242 /* call qsort with the appropriate compare function */
1243 qsort(array
, len
, sizeof(array
[0]), sortFunctions
[sortOrder
]);
1245 dir
->down
= array
[0];
1247 for(p
=array
; --len
; p
++)
1252 HeapFree(GetProcessHeap(), 0, array
);
1257 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
1259 TCHAR buffer
[MAX_PATH
];
1264 #ifdef _SHELL_FOLDERS
1265 if (dir
->etype
== ET_SHELL
)
1267 read_directory_shell(dir
, hwnd
);
1269 if (Globals
.prescan_node
) {
1278 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1279 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1280 read_directory_shell(entry
, hwnd
);
1281 SortDirectory(entry
, sortOrder
);
1287 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1288 if (dir
->etype
== ET_UNIX
)
1290 read_directory_unix(dir
, path
);
1292 if (Globals
.prescan_node
) {
1301 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1302 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1303 lstrcpy(d
, entry
->data
.cFileName
);
1304 read_directory_unix(entry
, buffer
);
1305 SortDirectory(entry
, sortOrder
);
1312 read_directory_win(dir
, path
);
1314 if (Globals
.prescan_node
) {
1323 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1324 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1325 lstrcpy(d
, entry
->data
.cFileName
);
1326 read_directory_win(entry
, buffer
);
1327 SortDirectory(entry
, sortOrder
);
1332 SortDirectory(dir
, sortOrder
);
1336 static Entry
* read_tree(Root
* root
, LPCTSTR path
, LPITEMIDLIST pidl
, LPTSTR drv
, SORT_ORDER sortOrder
, HWND hwnd
)
1338 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1339 const static TCHAR sSlash
[] = {'/', '\0'};
1341 const static TCHAR sBackslash
[] = {'\\', '\0'};
1343 #ifdef _SHELL_FOLDERS
1346 /* read shell namespace tree */
1347 root
->drive_type
= DRIVE_UNKNOWN
;
1350 load_string(root
->volname
, IDS_DESKTOP
);
1352 load_string(root
->fs
, IDS_SHELL
);
1354 return read_tree_shell(root
, pidl
, sortOrder
, hwnd
);
1358 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1361 /* read unix file system tree */
1362 root
->drive_type
= GetDriveType(path
);
1364 lstrcat(drv
, sSlash
);
1365 load_string(root
->volname
, IDS_ROOT_FS
);
1367 load_string(root
->fs
, IDS_UNIXFS
);
1369 lstrcpy(root
->path
, sSlash
);
1371 return read_tree_unix(root
, path
, sortOrder
, hwnd
);
1375 /* read WIN32 file system tree */
1376 root
->drive_type
= GetDriveType(path
);
1378 lstrcat(drv
, sBackslash
);
1379 GetVolumeInformation(drv
, root
->volname
, _MAX_FNAME
, 0, 0, &root
->fs_flags
, root
->fs
, _MAX_DIR
);
1381 lstrcpy(root
->path
, drv
);
1383 return read_tree_win(root
, path
, sortOrder
, hwnd
);
1387 /* flags to filter different file types */
1389 TF_DIRECTORIES
= 0x01,
1391 TF_DOCUMENTS
= 0x04,
1398 static ChildWnd
* alloc_child_window(LPCTSTR path
, LPITEMIDLIST pidl
, HWND hwnd
)
1400 TCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
1401 TCHAR b1
[BUFFER_LEN
];
1402 const static TCHAR sAsterics
[] = {'*', '\0'};
1404 ChildWnd
* child
= (ChildWnd
*) malloc(sizeof(ChildWnd
));
1405 Root
* root
= &child
->root
;
1408 memset(child
, 0, sizeof(ChildWnd
));
1410 child
->left
.treePane
= TRUE
;
1411 child
->left
.visible_cols
= 0;
1413 child
->right
.treePane
= FALSE
;
1414 #ifndef _NO_EXTENSIONS
1415 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_INDEX
|COL_LINKS
;
1417 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
;
1420 child
->pos
.length
= sizeof(WINDOWPLACEMENT
);
1421 child
->pos
.flags
= 0;
1422 child
->pos
.showCmd
= SW_SHOWNORMAL
;
1423 child
->pos
.rcNormalPosition
.left
= CW_USEDEFAULT
;
1424 child
->pos
.rcNormalPosition
.top
= CW_USEDEFAULT
;
1425 child
->pos
.rcNormalPosition
.right
= CW_USEDEFAULT
;
1426 child
->pos
.rcNormalPosition
.bottom
= CW_USEDEFAULT
;
1428 child
->focus_pane
= 0;
1429 child
->split_pos
= DEFAULT_SPLIT_POS
;
1430 child
->sortOrder
= SORT_NAME
;
1431 child
->header_wdths_ok
= FALSE
;
1435 lstrcpy(child
->path
, path
);
1437 _tsplitpath(path
, drv
, dir
, name
, ext
);
1440 lstrcpy(child
->filter_pattern
, sAsterics
);
1441 child
->filter_flags
= TF_ALL
;
1443 root
->entry
.level
= 0;
1445 entry
= read_tree(root
, path
, pidl
, drv
, child
->sortOrder
, hwnd
);
1447 #ifdef _SHELL_FOLDERS
1448 if (root
->entry
.etype
== ET_SHELL
)
1449 load_string(root
->entry
.data
.cFileName
, IDS_DESKTOP
);
1452 wsprintf(root
->entry
.data
.cFileName
, RS(b1
,IDS_TITLEFMT
), drv
, root
->fs
);
1454 root
->entry
.data
.dwFileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1456 child
->left
.root
= &root
->entry
;
1457 child
->right
.root
= NULL
;
1459 set_curdir(child
, entry
, 0, hwnd
);
1465 /* free all memory associated with a child window */
1466 static void free_child_window(ChildWnd
* child
)
1468 free_entries(&child
->root
.entry
);
1473 /* get full path of specified directory entry */
1474 static void get_path(Entry
* dir
, PTSTR path
)
1480 #ifdef _SHELL_FOLDERS
1481 if (dir
->etype
== ET_SHELL
)
1486 path
[0] = TEXT('\0');
1491 hr
= (*dir
->folder
->lpVtbl
->GetAttributesOf
)(dir
->folder
, 1, (LPCITEMIDLIST
*)&dir
->pidl
, &attribs
);
1493 if (SUCCEEDED(hr
) && (attribs
&SFGAO_FILESYSTEM
)) {
1494 IShellFolder
* parent
= dir
->up
? dir
->up
->folder
: Globals
.iDesktop
;
1496 hr
= path_from_pidl(parent
, dir
->pidl
, path
, MAX_PATH
);
1502 for(entry
=dir
; entry
; level
++) {
1508 name
= entry
->data
.cFileName
;
1511 for(l
=0; *s
&& *s
!=TEXT('/') && *s
!=TEXT('\\'); s
++)
1517 memmove(path
+l
+1, path
, len
*sizeof(TCHAR
));
1518 memcpy(path
+1, name
, l
*sizeof(TCHAR
));
1521 #ifndef _NO_EXTENSIONS
1522 if (entry
->etype
== ET_UNIX
)
1523 path
[0] = TEXT('/');
1526 path
[0] = TEXT('\\');
1531 memmove(path
+l
, path
, len
*sizeof(TCHAR
));
1532 memcpy(path
, name
, l
*sizeof(TCHAR
));
1539 #ifndef _NO_EXTENSIONS
1540 if (entry
->etype
== ET_UNIX
)
1541 path
[len
++] = TEXT('/');
1544 path
[len
++] = TEXT('\\');
1547 path
[len
] = TEXT('\0');
1552 static void resize_frame_rect(HWND hwnd
, PRECT prect
)
1557 if (IsWindowVisible(Globals
.htoolbar
)) {
1558 SendMessage(Globals
.htoolbar
, WM_SIZE
, 0, 0);
1559 GetClientRect(Globals
.htoolbar
, &rt
);
1560 prect
->top
= rt
.bottom
+3;
1561 prect
->bottom
-= rt
.bottom
+3;
1564 if (IsWindowVisible(Globals
.hdrivebar
)) {
1565 SendMessage(Globals
.hdrivebar
, WM_SIZE
, 0, 0);
1566 GetClientRect(Globals
.hdrivebar
, &rt
);
1567 new_top
= --prect
->top
+ rt
.bottom
+3;
1568 MoveWindow(Globals
.hdrivebar
, 0, prect
->top
, rt
.right
, new_top
, TRUE
);
1569 prect
->top
= new_top
;
1570 prect
->bottom
-= rt
.bottom
+2;
1573 if (IsWindowVisible(Globals
.hstatusbar
)) {
1574 int parts
[] = {300, 500};
1576 SendMessage(Globals
.hstatusbar
, WM_SIZE
, 0, 0);
1577 SendMessage(Globals
.hstatusbar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
1578 GetClientRect(Globals
.hstatusbar
, &rt
);
1579 prect
->bottom
-= rt
.bottom
;
1582 MoveWindow(Globals
.hmdiclient
, prect
->left
-1,prect
->top
-1,prect
->right
+2,prect
->bottom
+1, TRUE
);
1585 static void resize_frame(HWND hwnd
, int cx
, int cy
)
1594 resize_frame_rect(hwnd
, &rect
);
1597 static void resize_frame_client(HWND hwnd
)
1601 GetClientRect(hwnd
, &rect
);
1603 resize_frame_rect(hwnd
, &rect
);
1607 static HHOOK hcbthook
;
1608 static ChildWnd
* newchild
= NULL
;
1610 static LRESULT CALLBACK
CBTProc(int code
, WPARAM wparam
, LPARAM lparam
)
1612 if (code
==HCBT_CREATEWND
&& newchild
) {
1613 ChildWnd
* child
= newchild
;
1616 child
->hwnd
= (HWND
) wparam
;
1617 SetWindowLong(child
->hwnd
, GWL_USERDATA
, (LPARAM
)child
);
1620 return CallNextHookEx(hcbthook
, code
, wparam
, lparam
);
1623 static HWND
create_child_window(ChildWnd
* child
)
1625 MDICREATESTRUCT mcs
;
1628 mcs
.szClass
= sWINEFILETREE
;
1629 mcs
.szTitle
= (LPTSTR
)child
->path
;
1630 mcs
.hOwner
= Globals
.hInstance
;
1631 mcs
.x
= child
->pos
.rcNormalPosition
.left
;
1632 mcs
.y
= child
->pos
.rcNormalPosition
.top
;
1633 mcs
.cx
= child
->pos
.rcNormalPosition
.right
-child
->pos
.rcNormalPosition
.left
;
1634 mcs
.cy
= child
->pos
.rcNormalPosition
.bottom
-child
->pos
.rcNormalPosition
.top
;
1638 hcbthook
= SetWindowsHookEx(WH_CBT
, CBTProc
, 0, GetCurrentThreadId());
1641 child
->hwnd
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDICREATE
, 0, (LPARAM
)&mcs
);
1643 UnhookWindowsHookEx(hcbthook
);
1647 UnhookWindowsHookEx(hcbthook
);
1649 ListBox_SetItemHeight(child
->left
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1650 ListBox_SetItemHeight(child
->right
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1652 idx
= ListBox_FindItemData(child
->left
.hwnd
, 0, child
->left
.cur
);
1653 ListBox_SetCurSel(child
->left
.hwnd
, idx
);
1659 struct ExecuteDialog
{
1660 TCHAR cmd
[MAX_PATH
];
1664 static INT_PTR CALLBACK
ExecuteDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1666 static struct ExecuteDialog
* dlg
;
1670 dlg
= (struct ExecuteDialog
*) lparam
;
1674 int id
= (int)wparam
;
1677 GetWindowText(GetDlgItem(hwnd
, 201), dlg
->cmd
, MAX_PATH
);
1678 dlg
->cmdshow
= Button_GetState(GetDlgItem(hwnd
,214))&BST_CHECKED
?
1679 SW_SHOWMINIMIZED
: SW_SHOWNORMAL
;
1680 EndDialog(hwnd
, id
);
1681 } else if (id
== IDCANCEL
)
1682 EndDialog(hwnd
, id
);
1691 static INT_PTR CALLBACK
DestinationDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1693 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1697 SetWindowLong(hwnd
, GWL_USERDATA
, lparam
);
1698 SetWindowText(GetDlgItem(hwnd
, 201), (LPCTSTR
)lparam
);
1702 int id
= (int)wparam
;
1706 LPTSTR dest
= (LPTSTR
) GetWindowLong(hwnd
, GWL_USERDATA
);
1707 GetWindowText(GetDlgItem(hwnd
, 201), dest
, MAX_PATH
);
1708 EndDialog(hwnd
, id
);
1712 EndDialog(hwnd
, id
);
1716 MessageBox(hwnd
, RS(b1
,IDS_NO_IMPL
), RS(b2
,IDS_WINEFILE
), MB_OK
);
1728 struct FilterDialog
{
1729 TCHAR pattern
[MAX_PATH
];
1733 static INT_PTR CALLBACK
FilterDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1735 static struct FilterDialog
* dlg
;
1739 dlg
= (struct FilterDialog
*) lparam
;
1740 SetWindowText(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
);
1741 Button_SetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_DIRECTORIES
), (dlg
->flags
&TF_DIRECTORIES
? BST_CHECKED
: BST_UNCHECKED
));
1742 Button_SetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_PROGRAMS
), dlg
->flags
&TF_PROGRAMS
? BST_CHECKED
: BST_UNCHECKED
);
1743 Button_SetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_DOCUMENTS
), dlg
->flags
&TF_DOCUMENTS
? BST_CHECKED
: BST_UNCHECKED
);
1744 Button_SetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_OTHERS
), dlg
->flags
&TF_OTHERS
? BST_CHECKED
: BST_UNCHECKED
);
1745 Button_SetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_HIDDEN
), dlg
->flags
&TF_HIDDEN
? BST_CHECKED
: BST_UNCHECKED
);
1749 int id
= (int)wparam
;
1754 GetWindowText(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
, MAX_PATH
);
1756 flags
|= Button_GetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_DIRECTORIES
))&BST_CHECKED
? TF_DIRECTORIES
: 0;
1757 flags
|= Button_GetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_PROGRAMS
))&BST_CHECKED
? TF_PROGRAMS
: 0;
1758 flags
|= Button_GetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_DOCUMENTS
))&BST_CHECKED
? TF_DOCUMENTS
: 0;
1759 flags
|= Button_GetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_OTHERS
))&BST_CHECKED
? TF_OTHERS
: 0;
1760 flags
|= Button_GetCheck(GetDlgItem(hwnd
,IDC_VIEW_TYPE_HIDDEN
))&BST_CHECKED
? TF_HIDDEN
: 0;
1764 EndDialog(hwnd
, id
);
1765 } else if (id
== IDCANCEL
)
1766 EndDialog(hwnd
, id
);
1775 struct PropertiesDialog
{
1776 TCHAR path
[MAX_PATH
];
1781 /* Structure used to store enumerated languages and code pages. */
1782 struct LANGANDCODEPAGE
{
1787 static LPCSTR InfoStrings
[] = {
1803 static void PropDlg_DisplayValue(HWND hlbox
, HWND hedit
)
1805 int idx
= ListBox_GetCurSel(hlbox
);
1807 if (idx
!= LB_ERR
) {
1808 LPCTSTR pValue
= (LPCTSTR
) ListBox_GetItemData(hlbox
, idx
);
1811 SetWindowText(hedit
, pValue
);
1815 static void CheckForFileInfo(struct PropertiesDialog
* dlg
, HWND hwnd
, LPCTSTR strFilename
)
1817 static TCHAR sBackSlash
[] = {'\\','\0'};
1818 static TCHAR sTranslation
[] = {'\\','V','a','r','F','i','l','e','I','n','f','o','\\','T','r','a','n','s','l','a','t','i','o','n','\0'};
1819 static TCHAR sStringFileInfo
[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1820 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1821 DWORD dwVersionDataLen
= GetFileVersionInfoSize(strFilename
, NULL
);
1823 if (dwVersionDataLen
) {
1824 dlg
->pVersionData
= malloc(dwVersionDataLen
);
1826 if (GetFileVersionInfo(strFilename
, 0, dwVersionDataLen
, dlg
->pVersionData
)) {
1830 if (VerQueryValue(dlg
->pVersionData
, sBackSlash
, &pVal
, &nValLen
)) {
1831 if (nValLen
== sizeof(VS_FIXEDFILEINFO
)) {
1832 VS_FIXEDFILEINFO
* pFixedFileInfo
= (VS_FIXEDFILEINFO
*)pVal
;
1833 char buffer
[BUFFER_LEN
];
1835 sprintf(buffer
, "%d.%d.%d.%d",
1836 HIWORD(pFixedFileInfo
->dwFileVersionMS
), LOWORD(pFixedFileInfo
->dwFileVersionMS
),
1837 HIWORD(pFixedFileInfo
->dwFileVersionLS
), LOWORD(pFixedFileInfo
->dwFileVersionLS
));
1839 SetDlgItemTextA(hwnd
, IDC_STATIC_PROP_VERSION
, buffer
);
1843 /* Read the list of languages and code pages. */
1844 if (VerQueryValue(dlg
->pVersionData
, sTranslation
, &pVal
, &nValLen
)) {
1845 struct LANGANDCODEPAGE
* pTranslate
= (struct LANGANDCODEPAGE
*)pVal
;
1846 struct LANGANDCODEPAGE
* pEnd
= (struct LANGANDCODEPAGE
*)((LPBYTE
)pVal
+nValLen
);
1848 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
1850 /* Read the file description for each language and code page. */
1851 for(; pTranslate
<pEnd
; ++pTranslate
) {
1854 for(p
=InfoStrings
; *p
; ++p
) {
1855 TCHAR subblock
[200];
1862 LPCSTR pInfoString
= *p
;
1864 MultiByteToWideChar(CP_ACP
, 0, pInfoString
, -1, infoStr
, 100);
1866 #define infoStr pInfoString
1868 wsprintf(subblock
, sStringFileInfo
, pTranslate
->wLanguage
, pTranslate
->wCodePage
, infoStr
);
1870 /* Retrieve file description for language and code page */
1871 if (VerQueryValue(dlg
->pVersionData
, subblock
, (PVOID
)&pTxt
, &nValLen
)) {
1872 int idx
= ListBox_AddString(hlbox
, infoStr
);
1873 ListBox_SetItemData(hlbox
, idx
, pTxt
);
1878 ListBox_SetCurSel(hlbox
, 0);
1880 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
1886 static INT_PTR CALLBACK
PropertiesDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1888 static struct PropertiesDialog
* dlg
;
1891 case WM_INITDIALOG
: {
1892 const static TCHAR sByteFmt
[] = {'%','s',' ','B','y','t','e','s','\0'};
1893 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1894 LPWIN32_FIND_DATA pWFD
;
1897 dlg
= (struct PropertiesDialog
*) lparam
;
1898 pWFD
= (LPWIN32_FIND_DATA
) &dlg
->entry
.data
;
1900 GetWindowText(hwnd
, b1
, MAX_PATH
);
1901 wsprintf(b2
, b1
, pWFD
->cFileName
);
1902 SetWindowText(hwnd
, b2
);
1904 format_date(&pWFD
->ftLastWriteTime
, b1
, COL_DATE
|COL_TIME
);
1905 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_LASTCHANGE
), b1
);
1907 size
= ((ULONGLONG
)pWFD
->nFileSizeHigh
<< 32) | pWFD
->nFileSizeLow
;
1908 _stprintf(b1
, sLongNumFmt
, size
);
1909 wsprintf(b2
, sByteFmt
, b1
);
1910 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_SIZE
), b2
);
1912 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_FILENAME
), pWFD
->cFileName
);
1913 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_PATH
), dlg
->path
);
1915 Button_SetCheck(GetDlgItem(hwnd
,IDC_CHECK_READONLY
), (pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_READONLY
? BST_CHECKED
: BST_UNCHECKED
));
1916 Button_SetCheck(GetDlgItem(hwnd
,IDC_CHECK_ARCHIVE
), (pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_ARCHIVE
? BST_CHECKED
: BST_UNCHECKED
));
1917 Button_SetCheck(GetDlgItem(hwnd
,IDC_CHECK_COMPRESSED
), (pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_COMPRESSED
? BST_CHECKED
: BST_UNCHECKED
));
1918 Button_SetCheck(GetDlgItem(hwnd
,IDC_CHECK_HIDDEN
), (pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_HIDDEN
? BST_CHECKED
: BST_UNCHECKED
));
1919 Button_SetCheck(GetDlgItem(hwnd
,IDC_CHECK_SYSTEM
), (pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_SYSTEM
? BST_CHECKED
: BST_UNCHECKED
));
1921 CheckForFileInfo(dlg
, hwnd
, dlg
->path
);
1925 int id
= (int)wparam
;
1927 switch(HIWORD(wparam
)) {
1928 case LBN_SELCHANGE
: {
1929 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
1930 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
1935 if (id
==IDOK
|| id
==IDCANCEL
)
1936 EndDialog(hwnd
, id
);
1942 free(dlg
->pVersionData
);
1943 dlg
->pVersionData
= NULL
;
1950 static void show_properties_dlg(Entry
* entry
, HWND hwnd
)
1952 struct PropertiesDialog dlg
;
1954 memset(&dlg
, 0, sizeof(struct PropertiesDialog
));
1955 get_path(entry
, dlg
.path
);
1956 memcpy(&dlg
.entry
, entry
, sizeof(Entry
));
1958 DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_DIALOG_PROPERTIES
), hwnd
, PropertiesDialogDlgProc
, (LPARAM
)&dlg
);
1962 #ifndef _NO_EXTENSIONS
1964 static struct FullScreenParameters
{
1974 static void frame_get_clientspace(HWND hwnd
, PRECT prect
)
1978 if (!IsIconic(hwnd
))
1979 GetClientRect(hwnd
, prect
);
1983 GetWindowPlacement(hwnd
, &wp
);
1985 prect
->left
= prect
->top
= 0;
1986 prect
->right
= wp
.rcNormalPosition
.right
-wp
.rcNormalPosition
.left
-
1987 2*(GetSystemMetrics(SM_CXSIZEFRAME
)+GetSystemMetrics(SM_CXEDGE
));
1988 prect
->bottom
= wp
.rcNormalPosition
.bottom
-wp
.rcNormalPosition
.top
-
1989 2*(GetSystemMetrics(SM_CYSIZEFRAME
)+GetSystemMetrics(SM_CYEDGE
))-
1990 GetSystemMetrics(SM_CYCAPTION
)-GetSystemMetrics(SM_CYMENUSIZE
);
1993 if (IsWindowVisible(Globals
.htoolbar
)) {
1994 GetClientRect(Globals
.htoolbar
, &rt
);
1995 prect
->top
+= rt
.bottom
+2;
1998 if (IsWindowVisible(Globals
.hdrivebar
)) {
1999 GetClientRect(Globals
.hdrivebar
, &rt
);
2000 prect
->top
+= rt
.bottom
+2;
2003 if (IsWindowVisible(Globals
.hstatusbar
)) {
2004 GetClientRect(Globals
.hstatusbar
, &rt
);
2005 prect
->bottom
-= rt
.bottom
;
2009 static BOOL
toggle_fullscreen(HWND hwnd
)
2013 if ((g_fullscreen
.mode
=!g_fullscreen
.mode
)) {
2014 GetWindowRect(hwnd
, &g_fullscreen
.orgPos
);
2015 g_fullscreen
.wasZoomed
= IsZoomed(hwnd
);
2017 Frame_CalcFrameClient(hwnd
, &rt
);
2018 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
2019 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
2021 rt
.left
= g_fullscreen
.orgPos
.left
-rt
.left
;
2022 rt
.top
= g_fullscreen
.orgPos
.top
-rt
.top
;
2023 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+g_fullscreen
.orgPos
.right
-rt
.right
;
2024 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+g_fullscreen
.orgPos
.bottom
-rt
.bottom
;
2026 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
2028 MoveWindow(hwnd
, g_fullscreen
.orgPos
.left
, g_fullscreen
.orgPos
.top
,
2029 g_fullscreen
.orgPos
.right
-g_fullscreen
.orgPos
.left
,
2030 g_fullscreen
.orgPos
.bottom
-g_fullscreen
.orgPos
.top
, TRUE
);
2032 if (g_fullscreen
.wasZoomed
)
2033 ShowWindow(hwnd
, WS_MAXIMIZE
);
2036 return g_fullscreen
.mode
;
2039 static void fullscreen_move(HWND hwnd
)
2042 GetWindowRect(hwnd
, &pos
);
2044 Frame_CalcFrameClient(hwnd
, &rt
);
2045 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
2046 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
2048 rt
.left
= pos
.left
-rt
.left
;
2049 rt
.top
= pos
.top
-rt
.top
;
2050 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+pos
.right
-rt
.right
;
2051 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+pos
.bottom
-rt
.bottom
;
2053 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
2059 static void toggle_child(HWND hwnd
, UINT cmd
, HWND hchild
)
2061 BOOL vis
= IsWindowVisible(hchild
);
2063 CheckMenuItem(Globals
.hMenuOptions
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
2065 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
2067 #ifndef _NO_EXTENSIONS
2068 if (g_fullscreen
.mode
)
2069 fullscreen_move(hwnd
);
2072 resize_frame_client(hwnd
);
2075 static BOOL
activate_drive_window(LPCTSTR path
)
2077 TCHAR drv1
[_MAX_DRIVE
], drv2
[_MAX_DRIVE
];
2080 _tsplitpath(path
, drv1
, 0, 0, 0);
2082 /* search for a already open window for the same drive */
2083 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2084 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(child_wnd
, GWL_USERDATA
);
2087 _tsplitpath(child
->root
.path
, drv2
, 0, 0, 0);
2089 if (!lstrcmpi(drv2
, drv1
)) {
2090 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2092 if (IsMinimized(child_wnd
))
2093 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2103 static BOOL
activate_fs_window(LPCTSTR filesys
)
2107 /* search for a already open window of the given file system name */
2108 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2109 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(child_wnd
, GWL_USERDATA
);
2112 if (!lstrcmpi(child
->root
.fs
, filesys
)) {
2113 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2115 if (IsMinimized(child_wnd
))
2116 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2126 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
2128 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2132 DestroyWindow(hwnd
);
2134 /* clear handle variables */
2135 Globals
.hMenuFrame
= 0;
2136 Globals
.hMenuView
= 0;
2137 Globals
.hMenuOptions
= 0;
2138 Globals
.hMainWnd
= 0;
2139 Globals
.hmdiclient
= 0;
2140 Globals
.hdrivebar
= 0;
2144 /* don't exit desktop when closing file manager window */
2145 if (!Globals
.hwndParent
)
2149 case WM_INITMENUPOPUP
: {
2150 HWND hwndClient
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2152 if (!SendMessage(hwndClient
, WM_INITMENUPOPUP
, wparam
, lparam
))
2157 UINT cmd
= LOWORD(wparam
);
2158 HWND hwndClient
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2160 if (SendMessage(hwndClient
, WM_DISPATCH_COMMAND
, wparam
, lparam
))
2163 if (cmd
>=ID_DRIVE_FIRST
&& cmd
<=ID_DRIVE_FIRST
+0xFF) {
2164 TCHAR drv
[_MAX_DRIVE
], path
[MAX_PATH
];
2166 LPCTSTR root
= Globals
.drives
;
2169 for(i
=cmd
-ID_DRIVE_FIRST
; i
--; root
++)
2173 if (activate_drive_window(root
))
2176 _tsplitpath(root
, drv
, 0, 0, 0);
2178 if (!SetCurrentDirectory(drv
)) {
2179 display_error(hwnd
, GetLastError());
2183 GetCurrentDirectory(MAX_PATH
, path
); /*TODO: store last directory per drive */
2184 child
= alloc_child_window(path
, NULL
, hwnd
);
2186 if (!create_child_window(child
))
2188 } else switch(cmd
) {
2190 SendMessage(hwnd
, WM_CLOSE
, 0, 0);
2193 case ID_WINDOW_NEW
: {
2194 TCHAR path
[MAX_PATH
];
2197 GetCurrentDirectory(MAX_PATH
, path
);
2198 child
= alloc_child_window(path
, NULL
, hwnd
);
2200 if (!create_child_window(child
))
2208 case ID_WINDOW_CASCADE
:
2209 SendMessage(Globals
.hmdiclient
, WM_MDICASCADE
, 0, 0);
2212 case ID_WINDOW_TILE_HORZ
:
2213 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
2216 case ID_WINDOW_TILE_VERT
:
2217 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
2220 case ID_WINDOW_ARRANGE
:
2221 SendMessage(Globals
.hmdiclient
, WM_MDIICONARRANGE
, 0, 0);
2224 case ID_SELECT_FONT
: {
2225 TCHAR dlg_name
[BUFFER_LEN
], dlg_info
[BUFFER_LEN
];
2229 HDC hdc
= GetDC(hwnd
);
2230 chFont
.lStructSize
= sizeof(CHOOSEFONT
);
2231 chFont
.hwndOwner
= hwnd
;
2233 chFont
.lpLogFont
= &lFont
;
2234 chFont
.Flags
= CF_SCREENFONTS
| CF_FORCEFONTEXIST
| CF_LIMITSIZE
| CF_NOSCRIPTSEL
;
2235 chFont
.rgbColors
= RGB(0,0,0);
2236 chFont
.lCustData
= 0;
2237 chFont
.lpfnHook
= NULL
;
2238 chFont
.lpTemplateName
= NULL
;
2239 chFont
.hInstance
= Globals
.hInstance
;
2240 chFont
.lpszStyle
= NULL
;
2241 chFont
.nFontType
= SIMULATED_FONTTYPE
;
2242 chFont
.nSizeMin
= 0;
2243 chFont
.nSizeMax
= 24;
2245 if (ChooseFont(&chFont
)) {
2248 Globals
.hfont
= CreateFontIndirect(&lFont
);
2249 SelectFont(hdc
, Globals
.hfont
);
2250 GetTextExtentPoint32(hdc
, sSpace
, 1, &Globals
.spaceSize
);
2252 /* change font in all open child windows */
2253 for(childWnd
=GetWindow(Globals
.hmdiclient
,GW_CHILD
); childWnd
; childWnd
=GetNextWindow(childWnd
,GW_HWNDNEXT
)) {
2254 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(childWnd
, GWL_USERDATA
);
2255 SetWindowFont(child
->left
.hwnd
, Globals
.hfont
, TRUE
);
2256 SetWindowFont(child
->right
.hwnd
, Globals
.hfont
, TRUE
);
2257 ListBox_SetItemHeight(child
->left
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
2258 ListBox_SetItemHeight(child
->right
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
2259 InvalidateRect(child
->left
.hwnd
, NULL
, TRUE
);
2260 InvalidateRect(child
->right
.hwnd
, NULL
, TRUE
);
2263 else if (CommDlgExtendedError()) {
2264 LoadString(Globals
.hInstance
, IDS_FONT_SEL_DLG_NAME
, dlg_name
, BUFFER_LEN
);
2265 LoadString(Globals
.hInstance
, IDS_FONT_SEL_ERROR
, dlg_info
, BUFFER_LEN
);
2266 MessageBox(hwnd
, dlg_info
, dlg_name
, MB_OK
);
2269 ReleaseDC(hwnd
, hdc
);
2273 case ID_VIEW_TOOL_BAR
:
2274 toggle_child(hwnd
, cmd
, Globals
.htoolbar
);
2277 case ID_VIEW_DRIVE_BAR
:
2278 toggle_child(hwnd
, cmd
, Globals
.hdrivebar
);
2281 case ID_VIEW_STATUSBAR
:
2282 toggle_child(hwnd
, cmd
, Globals
.hstatusbar
);
2286 struct ExecuteDialog dlg
;
2288 memset(&dlg
, 0, sizeof(struct ExecuteDialog
));
2290 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_EXECUTE
), hwnd
, ExecuteDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
2291 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, dlg
.cmd
/*file*/, NULL
/*parameters*/, NULL
/*dir*/, dlg
.cmdshow
);
2293 if ((int)hinst
<= 32)
2294 display_error(hwnd
, GetLastError());
2298 case ID_CONNECT_NETWORK_DRIVE
: {
2299 DWORD ret
= WNetConnectionDialog(hwnd
, RESOURCETYPE_DISK
);
2300 if (ret
== NO_ERROR
)
2302 else if (ret
!= (DWORD
)-1) {
2303 if (ret
== ERROR_EXTENDED_ERROR
)
2304 display_network_error(hwnd
);
2306 display_error(hwnd
, ret
);
2310 case ID_DISCONNECT_NETWORK_DRIVE
: {
2311 DWORD ret
= WNetDisconnectDialog(hwnd
, RESOURCETYPE_DISK
);
2312 if (ret
== NO_ERROR
)
2314 else if (ret
!= (DWORD
)-1) {
2315 if (ret
== ERROR_EXTENDED_ERROR
)
2316 display_network_error(hwnd
);
2318 display_error(hwnd
, ret
);
2322 case ID_FORMAT_DISK
: {
2323 UINT sem_org
= SetErrorMode(0); /* Get the current Error Mode settings. */
2324 SetErrorMode(sem_org
& ~SEM_FAILCRITICALERRORS
); /* Force O/S to handle */
2325 SHFormatDrive(hwnd
, 0 /* A: */, SHFMT_ID_DEFAULT
, 0);
2326 SetErrorMode(sem_org
); /* Put it back the way it was. */
2330 WinHelp(hwnd
, RS(b1
,IDS_WINEFILE
), HELP_INDEX
, 0);
2333 #ifndef _NO_EXTENSIONS
2334 case ID_VIEW_FULLSCREEN
:
2335 CheckMenuItem(Globals
.hMenuOptions
, cmd
, toggle_fullscreen(hwnd
)?MF_CHECKED
:0);
2339 case ID_DRIVE_UNIX_FS
: {
2340 TCHAR path
[MAX_PATH
];
2342 char cpath
[MAX_PATH
];
2346 if (activate_fs_window(RS(b1
,IDS_UNIXFS
)))
2350 getcwd(cpath
, MAX_PATH
);
2351 MultiByteToWideChar(CP_UNIXCP
, 0, cpath
, -1, path
, MAX_PATH
);
2353 getcwd(path
, MAX_PATH
);
2355 child
= alloc_child_window(path
, NULL
, hwnd
);
2357 if (!create_child_window(child
))
2361 #ifdef _SHELL_FOLDERS
2362 case ID_DRIVE_SHELL_NS
: {
2363 TCHAR path
[MAX_PATH
];
2366 if (activate_fs_window(RS(b1
,IDS_SHELL
)))
2369 GetCurrentDirectory(MAX_PATH
, path
);
2370 child
= alloc_child_window(path
, get_path_pidl(path
,hwnd
), hwnd
);
2372 if (!create_child_window(child
))
2378 /*TODO: There are even more menu items! */
2380 #ifndef _NO_EXTENSIONS
2383 WineLicense(Globals
.hMainWnd
);
2386 case ID_NO_WARRANTY
:
2387 WineWarranty(Globals
.hMainWnd
);
2392 ShellAbout(hwnd
, RS(b2
,IDS_WINE
), RS(b1
,IDS_WINEFILE
), 0);
2396 ShellAbout(hwnd
, RS(b1
,IDS_WINEFILE
), NULL
, 0);
2398 #endif /* _NO_EXTENSIONS */
2401 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2402 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2403 else */if ((cmd
<IDW_FIRST_CHILD
|| cmd
>=IDW_FIRST_CHILD
+0x100) &&
2404 (cmd
<SC_SIZE
|| cmd
>SC_RESTORE
))
2405 MessageBox(hwnd
, RS(b2
,IDS_NO_IMPL
), RS(b1
,IDS_WINEFILE
), MB_OK
);
2407 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2412 resize_frame(hwnd
, LOWORD(lparam
), HIWORD(lparam
));
2413 break; /* do not pass message to DefFrameProc */
2415 #ifndef _NO_EXTENSIONS
2416 case WM_GETMINMAXINFO
: {
2417 LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
2419 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2420 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2423 case FRM_CALC_CLIENT
:
2424 frame_get_clientspace(hwnd
, (PRECT
)lparam
);
2426 #endif /* _NO_EXTENSIONS */
2429 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2436 static TCHAR g_pos_names
[COLUMNS
][20] = {
2440 static const int g_pos_align
[] = {
2442 HDF_LEFT
, /* Name */
2443 HDF_RIGHT
, /* Size */
2444 HDF_LEFT
, /* CDate */
2445 #ifndef _NO_EXTENSIONS
2446 HDF_LEFT
, /* ADate */
2447 HDF_LEFT
, /* MDate */
2448 HDF_LEFT
, /* Index */
2449 HDF_CENTER
, /* Links */
2451 HDF_CENTER
, /* Attributes */
2452 #ifndef _NO_EXTENSIONS
2453 HDF_LEFT
/* Security */
2457 static void resize_tree(ChildWnd
* child
, int cx
, int cy
)
2459 HDWP hdwp
= BeginDeferWindowPos(4);
2467 cx
= child
->split_pos
+ SPLIT_WIDTH
/2;
2469 #ifndef _NO_EXTENSIONS
2477 Header_Layout(child
->left
.hwndHeader
, &hdl
);
2479 DeferWindowPos(hdwp
, child
->left
.hwndHeader
, wp
.hwndInsertAfter
,
2480 wp
.x
-1, wp
.y
, child
->split_pos
-SPLIT_WIDTH
/2+1, wp
.cy
, wp
.flags
);
2481 DeferWindowPos(hdwp
, child
->right
.hwndHeader
, wp
.hwndInsertAfter
,
2482 rt
.left
+cx
+1, wp
.y
, wp
.cx
-cx
+2, wp
.cy
, wp
.flags
);
2484 #endif /* _NO_EXTENSIONS */
2486 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
);
2487 DeferWindowPos(hdwp
, child
->right
.hwnd
, 0, rt
.left
+cx
+1, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
2489 EndDeferWindowPos(hdwp
);
2493 #ifndef _NO_EXTENSIONS
2495 static HWND
create_header(HWND parent
, Pane
* pane
, int id
)
2500 HWND hwnd
= CreateWindow(WC_HEADER
, 0, WS_CHILD
|WS_VISIBLE
|HDS_HORZ
/*TODO: |HDS_BUTTONS + sort orders*/,
2501 0, 0, 0, 0, parent
, (HMENU
)id
, Globals
.hInstance
, 0);
2505 SetWindowFont(hwnd
, GetStockObject(DEFAULT_GUI_FONT
), FALSE
);
2507 hdi
.mask
= HDI_TEXT
|HDI_WIDTH
|HDI_FORMAT
;
2509 for(idx
=0; idx
<COLUMNS
; idx
++) {
2510 hdi
.pszText
= g_pos_names
[idx
];
2511 hdi
.fmt
= HDF_STRING
| g_pos_align
[idx
];
2512 hdi
.cxy
= pane
->widths
[idx
];
2513 Header_InsertItem(hwnd
, idx
, &hdi
);
2519 #endif /* _NO_EXTENSIONS */
2522 static void init_output(HWND hwnd
)
2524 const static TCHAR s1000
[] = {'1','0','0','0','\0'};
2528 HDC hdc
= GetDC(hwnd
);
2530 if (GetNumberFormat(LOCALE_USER_DEFAULT
, 0, s1000
, 0, b
, 16) > 4)
2531 Globals
.num_sep
= b
[1];
2533 Globals
.num_sep
= TEXT('.');
2535 old_font
= SelectFont(hdc
, Globals
.hfont
);
2536 GetTextExtentPoint32(hdc
, sSpace
, 1, &Globals
.spaceSize
);
2537 SelectFont(hdc
, old_font
);
2538 ReleaseDC(hwnd
, hdc
);
2541 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
);
2544 /* calculate preferred width for all visible columns */
2546 static BOOL
calc_widths(Pane
* pane
, BOOL anyway
)
2548 int col
, x
, cx
, spc
=3*Globals
.spaceSize
.cx
;
2549 int entries
= ListBox_GetCount(pane
->hwnd
);
2550 int orgWidths
[COLUMNS
];
2551 int orgPositions
[COLUMNS
+1];
2557 memcpy(orgWidths
, pane
->widths
, sizeof(orgWidths
));
2558 memcpy(orgPositions
, pane
->positions
, sizeof(orgPositions
));
2561 for(col
=0; col
<COLUMNS
; col
++)
2562 pane
->widths
[col
] = 0;
2564 hdc
= GetDC(pane
->hwnd
);
2565 hfontOld
= SelectFont(hdc
, Globals
.hfont
);
2567 for(cnt
=0; cnt
<entries
; cnt
++) {
2568 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, cnt
);
2577 dis
.hwndItem
= pane
->hwnd
;
2579 dis
.rcItem
.left
= 0;
2581 dis
.rcItem
.right
= 0;
2582 dis
.rcItem
.bottom
= 0;
2583 /*dis.itemData = 0; */
2585 draw_item(pane
, &dis
, entry
, COLUMNS
);
2588 SelectObject(hdc
, hfontOld
);
2589 ReleaseDC(pane
->hwnd
, hdc
);
2592 for(col
=0; col
<COLUMNS
; col
++) {
2593 pane
->positions
[col
] = x
;
2594 cx
= pane
->widths
[col
];
2599 if (cx
< IMAGE_WIDTH
)
2602 pane
->widths
[col
] = cx
;
2608 pane
->positions
[COLUMNS
] = x
;
2610 ListBox_SetHorizontalExtent(pane
->hwnd
, x
);
2613 if (!memcmp(orgWidths
, pane
->widths
, sizeof(orgWidths
)))
2616 /* don't move, if only collapsing an entry */
2617 if (!anyway
&& pane
->widths
[0]<orgWidths
[0] &&
2618 !memcmp(orgWidths
+1, pane
->widths
+1, sizeof(orgWidths
)-sizeof(int))) {
2619 pane
->widths
[0] = orgWidths
[0];
2620 memcpy(pane
->positions
, orgPositions
, sizeof(orgPositions
));
2625 InvalidateRect(pane
->hwnd
, 0, TRUE
);
2631 /* calculate one preferred column width */
2633 static void calc_single_width(Pane
* pane
, int col
)
2637 int entries
= ListBox_GetCount(pane
->hwnd
);
2641 pane
->widths
[col
] = 0;
2643 hdc
= GetDC(pane
->hwnd
);
2644 hfontOld
= SelectFont(hdc
, Globals
.hfont
);
2646 for(cnt
=0; cnt
<entries
; cnt
++) {
2647 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, cnt
);
2655 dis
.hwndItem
= pane
->hwnd
;
2657 dis
.rcItem
.left
= 0;
2659 dis
.rcItem
.right
= 0;
2660 dis
.rcItem
.bottom
= 0;
2661 /*dis.itemData = 0; */
2663 draw_item(pane
, &dis
, entry
, col
);
2666 SelectObject(hdc
, hfontOld
);
2667 ReleaseDC(pane
->hwnd
, hdc
);
2669 cx
= pane
->widths
[col
];
2672 cx
+= 3*Globals
.spaceSize
.cx
;
2674 if (cx
< IMAGE_WIDTH
)
2678 pane
->widths
[col
] = cx
;
2680 x
= pane
->positions
[col
] + cx
;
2682 for(; col
<COLUMNS
; ) {
2683 pane
->positions
[++col
] = x
;
2684 x
+= pane
->widths
[col
];
2687 ListBox_SetHorizontalExtent(pane
->hwnd
, x
);
2691 static BOOL
pattern_match(LPCTSTR str
, LPCTSTR pattern
)
2693 for( ; *str
&&*pattern
; str
++,pattern
++) {
2694 if (*pattern
== '*') {
2696 while(*pattern
== '*');
2702 if (*str
==*pattern
&& pattern_match(str
, pattern
))
2707 else if (*str
!=*pattern
&& *pattern
!='?')
2711 if (*str
|| *pattern
)
2712 if (*pattern
!='*' || pattern
[1]!='\0')
2718 static BOOL
pattern_imatch(LPCTSTR str
, LPCTSTR pattern
)
2720 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2723 lstrcpy(b2
, pattern
);
2727 return pattern_match(b1
, b2
);
2737 static enum FILE_TYPE
get_file_type(LPCTSTR filename
);
2740 /* insert listbox entries after index idx */
2742 static int insert_entries(Pane
* pane
, Entry
* dir
, LPCTSTR pattern
, int filter_flags
, int idx
)
2749 ShowWindow(pane
->hwnd
, SW_HIDE
);
2751 for(; entry
; entry
=entry
->next
) {
2753 if (pane
->treePane
&& !(entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
2757 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
2758 /* don't display entries "." and ".." in the left pane */
2759 if (pane
->treePane
&& entry
->data
.cFileName
[0]==TEXT('.'))
2761 #ifndef _NO_EXTENSIONS
2762 entry
->data
.cFileName
[1]==TEXT('\0') ||
2764 (entry
->data
.cFileName
[1]==TEXT('.') && entry
->data
.cFileName
[2]==TEXT('\0')))
2767 /* filter directories in right pane */
2768 if (!pane
->treePane
&& !(filter_flags
&TF_DIRECTORIES
))
2772 /* filter using the file name pattern */
2774 if (!pattern_imatch(entry
->data
.cFileName
, pattern
))
2777 /* filter system and hidden files */
2778 if (!(filter_flags
&TF_HIDDEN
) && (entry
->data
.dwFileAttributes
&(FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
)))
2781 /* filter looking at the file type */
2782 if ((filter_flags
&(TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
)) != (TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
))
2783 switch(get_file_type(entry
->data
.cFileName
)) {
2785 if (!(filter_flags
& TF_PROGRAMS
))
2790 if (!(filter_flags
& TF_DOCUMENTS
))
2794 default: /* TF_OTHERS */
2795 if (!(filter_flags
& TF_OTHERS
))
2802 ListBox_InsertItemData(pane
->hwnd
, idx
, entry
);
2804 if (pane
->treePane
&& entry
->expanded
)
2805 idx
= insert_entries(pane
, entry
->down
, pattern
, filter_flags
, idx
);
2808 ShowWindow(pane
->hwnd
, SW_SHOW
);
2814 static void format_bytes(LPTSTR buffer
, LONGLONG bytes
)
2816 const static TCHAR sFmtGB
[] = {'%', '.', '1', 'f', ' ', 'G', 'B', '\0'};
2817 const static TCHAR sFmtMB
[] = {'%', '.', '1', 'f', ' ', 'M', 'B', '\0'};
2818 const static TCHAR sFmtkB
[] = {'%', '.', '1', 'f', ' ', 'k', 'B', '\0'};
2820 float fBytes
= (float)bytes
;
2822 if (bytes
>= 1073741824) /* 1 GB */
2823 wsprintf(buffer
, sFmtGB
, fBytes
/1073741824.f
+.5f
);
2824 else if (bytes
>= 1048576) /* 1 MB */
2825 wsprintf(buffer
, sFmtMB
, fBytes
/1048576.f
+.5f
);
2826 else if (bytes
>= 1024) /* 1 kB */
2827 wsprintf(buffer
, sFmtkB
, fBytes
/1024.f
+.5f
);
2829 _stprintf(buffer
, sLongNumFmt
, bytes
);
2832 static void set_space_status(void)
2834 ULARGE_INTEGER ulFreeBytesToCaller
, ulTotalBytes
, ulFreeBytes
;
2835 TCHAR fmt
[64], b1
[64], b2
[64], buffer
[BUFFER_LEN
];
2837 if (GetDiskFreeSpaceEx(NULL
, &ulFreeBytesToCaller
, &ulTotalBytes
, &ulFreeBytes
)) {
2838 format_bytes(b1
, ulFreeBytesToCaller
.QuadPart
);
2839 format_bytes(b2
, ulTotalBytes
.QuadPart
);
2840 wsprintf(buffer
, RS(fmt
,IDS_FREE_SPACE_FMT
), b1
, b2
);
2842 lstrcpy(buffer
, sQMarks
);
2844 SendMessage(Globals
.hstatusbar
, SB_SETTEXT
, 0, (LPARAM
)buffer
);
2848 static WNDPROC g_orgTreeWndProc
;
2850 static void create_tree_window(HWND parent
, Pane
* pane
, int id
, int id_header
, LPCTSTR pattern
, int filter_flags
)
2852 const static TCHAR sListBox
[] = {'L','i','s','t','B','o','x','\0'};
2854 static int s_init
= 0;
2855 Entry
* entry
= pane
->root
;
2857 pane
->hwnd
= CreateWindow(sListBox
, sEmpty
, WS_CHILD
|WS_VISIBLE
|WS_HSCROLL
|WS_VSCROLL
|
2858 LBS_DISABLENOSCROLL
|LBS_NOINTEGRALHEIGHT
|LBS_OWNERDRAWFIXED
|LBS_NOTIFY
,
2859 0, 0, 0, 0, parent
, (HMENU
)id
, Globals
.hInstance
, 0);
2861 SetWindowLong(pane
->hwnd
, GWL_USERDATA
, (LPARAM
)pane
);
2862 g_orgTreeWndProc
= SubclassWindow(pane
->hwnd
, TreeWndProc
);
2864 SetWindowFont(pane
->hwnd
, Globals
.hfont
, FALSE
);
2866 /* insert entries into listbox */
2868 insert_entries(pane
, entry
, pattern
, filter_flags
, -1);
2870 /* calculate column widths */
2873 init_output(pane
->hwnd
);
2876 calc_widths(pane
, TRUE
);
2878 #ifndef _NO_EXTENSIONS
2879 pane
->hwndHeader
= create_header(parent
, pane
, id_header
);
2884 static void InitChildWindow(ChildWnd
* child
)
2886 create_tree_window(child
->hwnd
, &child
->left
, IDW_TREE_LEFT
, IDW_HEADER_LEFT
, NULL
, TF_ALL
);
2887 create_tree_window(child
->hwnd
, &child
->right
, IDW_TREE_RIGHT
, IDW_HEADER_RIGHT
, child
->filter_pattern
, child
->filter_flags
);
2891 static void format_date(const FILETIME
* ft
, TCHAR
* buffer
, int visible_cols
)
2897 *buffer
= TEXT('\0');
2899 if (!ft
->dwLowDateTime
&& !ft
->dwHighDateTime
)
2902 if (!FileTimeToLocalFileTime(ft
, &lft
))
2903 {err
: lstrcpy(buffer
,sQMarks
); return;}
2905 if (!FileTimeToSystemTime(&lft
, &systime
))
2908 if (visible_cols
& COL_DATE
) {
2909 len
= GetDateFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
, BUFFER_LEN
);
2914 if (visible_cols
& COL_TIME
) {
2916 buffer
[len
-1] = ' ';
2918 buffer
[len
++] = ' ';
2920 if (!GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
+len
, BUFFER_LEN
-len
))
2921 buffer
[len
] = TEXT('\0');
2926 static void calc_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2928 RECT rt
= {0, 0, 0, 0};
2930 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
2932 if (rt
.right
> pane
->widths
[col
])
2933 pane
->widths
[col
] = rt
.right
;
2936 static void calc_tabbed_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2938 RECT rt
= {0, 0, 0, 0};
2940 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2941 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2943 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2944 /*FIXME rt (0,0) ??? */
2946 if (rt
.right
> pane
->widths
[col
])
2947 pane
->widths
[col
] = rt
.right
;
2951 static void output_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
, DWORD flags
)
2953 int x
= dis
->rcItem
.left
;
2956 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2957 rt
.top
= dis
->rcItem
.top
;
2958 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2959 rt
.bottom
= dis
->rcItem
.bottom
;
2961 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_SINGLELINE
|DT_NOPREFIX
|flags
);
2964 static void output_tabbed_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2966 int x
= dis
->rcItem
.left
;
2969 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2970 rt
.top
= dis
->rcItem
.top
;
2971 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2972 rt
.bottom
= dis
->rcItem
.bottom
;
2974 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2975 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2977 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2980 static void output_number(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2982 int x
= dis
->rcItem
.left
;
2989 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2990 rt
.top
= dis
->rcItem
.top
;
2991 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2992 rt
.bottom
= dis
->rcItem
.bottom
;
2997 /* insert number separator characters */
2998 pos
= lstrlen(s
) % 3;
3004 *d
++ = Globals
.num_sep
;
3008 DrawText(dis
->hDC
, b
, d
-b
, &rt
, DT_RIGHT
|DT_SINGLELINE
|DT_NOPREFIX
|DT_END_ELLIPSIS
);
3012 static BOOL
is_exe_file(LPCTSTR ext
)
3014 static const TCHAR executable_extensions
[][4] = {
3019 #ifndef _NO_EXTENSIONS
3023 #endif /* _NO_EXTENSIONS */
3027 TCHAR ext_buffer
[_MAX_EXT
];
3028 const TCHAR (*p
)[4];
3032 for(s
=ext
+1,d
=ext_buffer
; (*d
=tolower(*s
)); s
++)
3035 for(p
=executable_extensions
; (*p
)[0]; p
++)
3036 if (!lstrcmpi(ext_buffer
, *p
))
3042 static BOOL
is_registered_type(LPCTSTR ext
)
3044 /* check if there exists a classname for this file extension in the registry */
3045 if (!RegQueryValue(HKEY_CLASSES_ROOT
, ext
, NULL
, NULL
))
3051 static enum FILE_TYPE
get_file_type(LPCTSTR filename
)
3053 LPCTSTR ext
= _tcsrchr(filename
, '.');
3057 if (is_exe_file(ext
))
3058 return FT_EXECUTABLE
;
3059 else if (is_registered_type(ext
))
3066 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
)
3068 TCHAR buffer
[BUFFER_LEN
];
3070 int visible_cols
= pane
->visible_cols
;
3071 COLORREF bkcolor
, textcolor
;
3072 RECT focusRect
= dis
->rcItem
;
3079 attrs
= entry
->data
.dwFileAttributes
;
3081 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) {
3082 if (entry
->data
.cFileName
[0]==TEXT('.') && entry
->data
.cFileName
[1]==TEXT('.')
3083 && entry
->data
.cFileName
[2]==TEXT('\0'))
3084 img
= IMG_FOLDER_UP
;
3085 #ifndef _NO_EXTENSIONS
3086 else if (entry
->data
.cFileName
[0]==TEXT('.') && entry
->data
.cFileName
[1]==TEXT('\0'))
3087 img
= IMG_FOLDER_CUR
;
3090 #ifdef _NO_EXTENSIONS
3093 (pane
->treePane
&& (dis
->itemState
&ODS_FOCUS
)))
3094 img
= IMG_OPEN_FOLDER
;
3098 switch(get_file_type(entry
->data
.cFileName
)) {
3099 case FT_EXECUTABLE
: img
= IMG_EXECUTABLE
; break;
3100 case FT_DOCUMENT
: img
= IMG_DOCUMENT
; break;
3101 default: img
= IMG_FILE
;
3109 if (pane
->treePane
) {
3111 img_pos
= dis
->rcItem
.left
+ entry
->level
*(IMAGE_WIDTH
+TREE_LINE_DX
);
3113 if (calcWidthCol
== -1) {
3115 int y
= dis
->rcItem
.top
+ IMAGE_HEIGHT
/2;
3118 HRGN hrgn_org
= CreateRectRgn(0, 0, 0, 0);
3121 rt_clip
.left
= dis
->rcItem
.left
;
3122 rt_clip
.top
= dis
->rcItem
.top
;
3123 rt_clip
.right
= dis
->rcItem
.left
+pane
->widths
[col
];
3124 rt_clip
.bottom
= dis
->rcItem
.bottom
;
3126 hrgn
= CreateRectRgnIndirect(&rt_clip
);
3128 if (!GetClipRgn(dis
->hDC
, hrgn_org
)) {
3129 DeleteObject(hrgn_org
);
3133 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
3134 ExtSelectClipRgn(dis
->hDC
, hrgn
, RGN_AND
);
3137 if ((up
=entry
->up
) != NULL
) {
3138 MoveToEx(dis
->hDC
, img_pos
-IMAGE_WIDTH
/2, y
, 0);
3139 LineTo(dis
->hDC
, img_pos
-2, y
);
3141 x
= img_pos
- IMAGE_WIDTH
/2;
3144 x
-= IMAGE_WIDTH
+TREE_LINE_DX
;
3148 && (up
->next
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
3151 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
3152 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
3154 } while((up
=up
->up
) != NULL
);
3157 x
= img_pos
- IMAGE_WIDTH
/2;
3159 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
3160 LineTo(dis
->hDC
, x
, y
);
3164 && (entry
->next
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
)
3167 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
3169 SelectClipRgn(dis
->hDC
, hrgn_org
);
3170 if (hrgn_org
) DeleteObject(hrgn_org
);
3171 /* SelectObject(dis->hDC, holdPen); */
3172 } else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
) {
3173 int right
= img_pos
+ IMAGE_WIDTH
- TREE_LINE_DX
;
3175 if (right
> pane
->widths
[col
])
3176 pane
->widths
[col
] = right
;
3179 img_pos
= dis
->rcItem
.left
;
3182 img_pos
= dis
->rcItem
.left
;
3184 if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3185 pane
->widths
[col
] = IMAGE_WIDTH
;
3188 if (calcWidthCol
== -1) {
3189 focusRect
.left
= img_pos
-2;
3191 #ifdef _NO_EXTENSIONS
3192 if (pane
->treePane
&& entry
) {
3195 DrawText(dis
->hDC
, entry
->data
.cFileName
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
3197 focusRect
.right
= dis
->rcItem
.left
+pane
->positions
[col
+1]+TREE_LINE_DX
+ rt
.right
+2;
3201 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
)
3202 textcolor
= COLOR_COMPRESSED
;
3204 #endif /* _NO_EXTENSIONS */
3205 textcolor
= RGB(0,0,0);
3207 if (dis
->itemState
& ODS_FOCUS
) {
3208 textcolor
= RGB(255,255,255);
3209 bkcolor
= COLOR_SELECTION
;
3211 bkcolor
= RGB(255,255,255);
3214 hbrush
= CreateSolidBrush(bkcolor
);
3215 FillRect(dis
->hDC
, &focusRect
, hbrush
);
3216 DeleteObject(hbrush
);
3218 SetBkMode(dis
->hDC
, TRANSPARENT
);
3219 SetTextColor(dis
->hDC
, textcolor
);
3221 cx
= pane
->widths
[col
];
3223 if (cx
&& img
!=IMG_NONE
) {
3224 if (cx
> IMAGE_WIDTH
)
3227 #ifdef _SHELL_FOLDERS
3228 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
3229 DrawIconEx(dis
->hDC
, img_pos
, dis
->rcItem
.top
, entry
->hicon
, cx
, GetSystemMetrics(SM_CYSMICON
), 0, 0, DI_NORMAL
);
3232 ImageList_DrawEx(Globals
.himl
, img
, dis
->hDC
,
3233 img_pos
, dis
->rcItem
.top
, cx
,
3234 IMAGE_HEIGHT
, bkcolor
, CLR_DEFAULT
, ILD_NORMAL
);
3241 #ifdef _NO_EXTENSIONS
3242 if (img
>= IMG_FOLDER_UP
)
3248 /* ouput file name */
3249 if (calcWidthCol
== -1)
3250 output_text(pane
, dis
, col
, entry
->data
.cFileName
, 0);
3251 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3252 calc_width(pane
, dis
, col
, entry
->data
.cFileName
);
3256 #ifdef _NO_EXTENSIONS
3257 if (!pane
->treePane
) {
3260 /* display file size */
3261 if (visible_cols
& COL_SIZE
) {
3262 #ifdef _NO_EXTENSIONS
3263 if (!(attrs
&FILE_ATTRIBUTE_DIRECTORY
))
3268 size
= ((ULONGLONG
)entry
->data
.nFileSizeHigh
<< 32) | entry
->data
.nFileSizeLow
;
3270 _stprintf(buffer
, sLongNumFmt
, size
);
3272 if (calcWidthCol
== -1)
3273 output_number(pane
, dis
, col
, buffer
);
3274 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3275 calc_width(pane
, dis
, col
, buffer
);/*TODO: not ever time enough */
3281 /* display file date */
3282 if (visible_cols
& (COL_DATE
|COL_TIME
)) {
3283 #ifndef _NO_EXTENSIONS
3284 format_date(&entry
->data
.ftCreationTime
, buffer
, visible_cols
);
3285 if (calcWidthCol
== -1)
3286 output_text(pane
, dis
, col
, buffer
, 0);
3287 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3288 calc_width(pane
, dis
, col
, buffer
);
3291 format_date(&entry
->data
.ftLastAccessTime
, buffer
, visible_cols
);
3292 if (calcWidthCol
== -1)
3293 output_text(pane
, dis
, col
, buffer
, 0);
3294 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3295 calc_width(pane
, dis
, col
, buffer
);
3297 #endif /* _NO_EXTENSIONS */
3299 format_date(&entry
->data
.ftLastWriteTime
, buffer
, visible_cols
);
3300 if (calcWidthCol
== -1)
3301 output_text(pane
, dis
, col
, buffer
, 0);
3302 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3303 calc_width(pane
, dis
, col
, buffer
);
3307 #ifndef _NO_EXTENSIONS
3308 if (entry
->bhfi_valid
) {
3309 ULONGLONG index
= ((ULONGLONG
)entry
->bhfi
.nFileIndexHigh
<< 32) | entry
->bhfi
.nFileIndexLow
;
3311 if (visible_cols
& COL_INDEX
) {
3312 _stprintf(buffer
, sLongHexFmt
, index
);
3314 if (calcWidthCol
== -1)
3315 output_text(pane
, dis
, col
, buffer
, DT_RIGHT
);
3316 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3317 calc_width(pane
, dis
, col
, buffer
);
3322 if (visible_cols
& COL_LINKS
) {
3323 wsprintf(buffer
, sNumFmt
, entry
->bhfi
.nNumberOfLinks
);
3325 if (calcWidthCol
== -1)
3326 output_text(pane
, dis
, col
, buffer
, DT_CENTER
);
3327 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3328 calc_width(pane
, dis
, col
, buffer
);
3334 #endif /* _NO_EXTENSIONS */
3336 /* show file attributes */
3337 if (visible_cols
& COL_ATTRIBUTES
) {
3338 #ifdef _NO_EXTENSIONS
3339 const static TCHAR s4Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3340 lstrcpy(buffer
, s4Tabs
);
3342 const static TCHAR s11Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3343 lstrcpy(buffer
, s11Tabs
);
3346 if (attrs
& FILE_ATTRIBUTE_NORMAL
) buffer
[ 0] = 'N';
3348 if (attrs
& FILE_ATTRIBUTE_READONLY
) buffer
[ 2] = 'R';
3349 if (attrs
& FILE_ATTRIBUTE_HIDDEN
) buffer
[ 4] = 'H';
3350 if (attrs
& FILE_ATTRIBUTE_SYSTEM
) buffer
[ 6] = 'S';
3351 if (attrs
& FILE_ATTRIBUTE_ARCHIVE
) buffer
[ 8] = 'A';
3352 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
) buffer
[10] = 'C';
3353 #ifndef _NO_EXTENSIONS
3354 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) buffer
[12] = 'D';
3355 if (attrs
& FILE_ATTRIBUTE_ENCRYPTED
) buffer
[14] = 'E';
3356 if (attrs
& FILE_ATTRIBUTE_TEMPORARY
) buffer
[16] = 'T';
3357 if (attrs
& FILE_ATTRIBUTE_SPARSE_FILE
) buffer
[18] = 'P';
3358 if (attrs
& FILE_ATTRIBUTE_REPARSE_POINT
) buffer
[20] = 'Q';
3359 if (attrs
& FILE_ATTRIBUTE_OFFLINE
) buffer
[22] = 'O';
3360 if (attrs
& FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
) buffer
[24] = 'X';
3361 #endif /* _NO_EXTENSIONS */
3364 if (calcWidthCol
== -1)
3365 output_tabbed_text(pane
, dis
, col
, buffer
);
3366 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3367 calc_tabbed_width(pane
, dis
, col
, buffer
);
3373 if (flags.security) {
3374 const static TCHAR sSecTabs[] = {
3375 ' ','\t',' ','\t',' ','\t',' ',
3377 ' ','\t',' ','\t',' ','\t',' ',
3379 ' ','\t',' ','\t',' ','\t',' ',
3383 DWORD rights = get_access_mask();
3385 lstrcpy(buffer, sSecTabs);
3387 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
3388 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
3389 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
3390 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
3391 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
3392 if (rights & FILE_EXECUTE) buffer[12] = 'X';
3393 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
3394 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
3395 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
3396 if (rights & WRITE_DAC) buffer[22] = 'C';
3397 if (rights & WRITE_OWNER) buffer[24] = 'O';
3398 if (rights & SYNCHRONIZE) buffer[26] = 'S';
3400 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
3403 if (flags.description) {
3404 get_description(buffer);
3405 output_text(dis, col++, buffer, 0, psize);
3409 #ifdef _NO_EXTENSIONS
3412 /* draw focus frame */
3413 if ((dis
->itemState
&ODS_FOCUS
) && calcWidthCol
==-1) {
3414 /* Currently [04/2000] Wine neither behaves exactly the same */
3415 /* way as WIN 95 nor like Windows NT... */
3420 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
3421 LOGBRUSH lb
= {PS_SOLID
, RGB(255,255,255)};
3422 hpen
= ExtCreatePen(PS_COSMETIC
|PS_ALTERNATE
, 1, &lb
, 0, 0);
3424 hpen
= CreatePen(PS_DOT
, 0, RGB(255,255,255));
3426 lastPen
= SelectPen(dis
->hDC
, hpen
);
3427 lastBrush
= SelectObject(dis
->hDC
, GetStockObject(HOLLOW_BRUSH
));
3428 SetROP2(dis
->hDC
, R2_XORPEN
);
3429 Rectangle(dis
->hDC
, focusRect
.left
, focusRect
.top
, focusRect
.right
, focusRect
.bottom
);
3430 SelectObject(dis
->hDC
, lastBrush
);
3431 SelectObject(dis
->hDC
, lastPen
);
3434 #endif /* _NO_EXTENSIONS */
3438 #ifdef _NO_EXTENSIONS
3440 static void draw_splitbar(HWND hwnd
, int x
)
3443 HDC hdc
= GetDC(hwnd
);
3445 GetClientRect(hwnd
, &rt
);
3447 rt
.left
= x
- SPLIT_WIDTH
/2;
3448 rt
.right
= x
+ SPLIT_WIDTH
/2+1;
3450 InvertRect(hdc
, &rt
);
3452 ReleaseDC(hwnd
, hdc
);
3455 #endif /* _NO_EXTENSIONS */
3458 #ifndef _NO_EXTENSIONS
3460 static void set_header(Pane
* pane
)
3463 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3466 item
.mask
= HDI_WIDTH
;
3469 for(; x
+pane
->widths
[i
]<scroll_pos
&& i
<COLUMNS
; i
++) {
3470 x
+= pane
->widths
[i
];
3471 Header_SetItem(pane
->hwndHeader
, i
, &item
);
3475 x
+= pane
->widths
[i
];
3476 item
.cxy
= x
- scroll_pos
;
3477 Header_SetItem(pane
->hwndHeader
, i
++, &item
);
3479 for(; i
<COLUMNS
; i
++) {
3480 item
.cxy
= pane
->widths
[i
];
3481 x
+= pane
->widths
[i
];
3482 Header_SetItem(pane
->hwndHeader
, i
, &item
);
3487 static LRESULT
pane_notify(Pane
* pane
, NMHDR
* pnmh
)
3489 switch(pnmh
->code
) {
3491 case HDN_ENDTRACK
: {
3492 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3493 int idx
= phdn
->iItem
;
3494 int dx
= phdn
->pitem
->cxy
- pane
->widths
[idx
];
3498 GetClientRect(pane
->hwnd
, &clnt
);
3500 /* move immediate to simulate HDS_FULLDRAG (for now [04/2000] not really needed with WINELIB) */
3501 Header_SetItem(pane
->hwndHeader
, idx
, phdn
->pitem
);
3503 pane
->widths
[idx
] += dx
;
3505 for(i
=idx
; ++i
<=COLUMNS
; )
3506 pane
->positions
[i
] += dx
;
3509 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3513 rt_scr
.left
= pane
->positions
[idx
+1]-scroll_pos
;
3515 rt_scr
.right
= clnt
.right
;
3516 rt_scr
.bottom
= clnt
.bottom
;
3518 rt_clip
.left
= pane
->positions
[idx
]-scroll_pos
;
3520 rt_clip
.right
= clnt
.right
;
3521 rt_clip
.bottom
= clnt
.bottom
;
3523 if (rt_scr
.left
< 0) rt_scr
.left
= 0;
3524 if (rt_clip
.left
< 0) rt_clip
.left
= 0;
3526 ScrollWindowEx(pane
->hwnd
, dx
, 0, &rt_scr
, &rt_clip
, 0, 0, SW_INVALIDATE
);
3528 rt_clip
.right
= pane
->positions
[idx
+1];
3529 RedrawWindow(pane
->hwnd
, &rt_clip
, 0, RDW_INVALIDATE
|RDW_UPDATENOW
);
3531 if (pnmh
->code
== HDN_ENDTRACK
) {
3532 ListBox_SetHorizontalExtent(pane
->hwnd
, pane
->positions
[COLUMNS
]);
3534 if (GetScrollPos(pane
->hwnd
, SB_HORZ
) != scroll_pos
)
3542 case HDN_DIVIDERDBLCLICK
: {
3543 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3546 calc_single_width(pane
, phdn
->iItem
);
3547 item
.mask
= HDI_WIDTH
;
3548 item
.cxy
= pane
->widths
[phdn
->iItem
];
3550 Header_SetItem(pane
->hwndHeader
, phdn
->iItem
, &item
);
3551 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3558 #endif /* _NO_EXTENSIONS */
3561 static void scan_entry(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3563 TCHAR path
[MAX_PATH
];
3564 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
3566 /* delete sub entries in left pane */
3568 LRESULT res
= ListBox_GetItemData(child
->left
.hwnd
, idx
+1);
3569 Entry
* sub
= (Entry
*) res
;
3571 if (res
==LB_ERR
|| !sub
|| sub
->level
<=entry
->level
)
3574 ListBox_DeleteString(child
->left
.hwnd
, idx
+1);
3577 /* empty right pane */
3578 ListBox_ResetContent(child
->right
.hwnd
);
3580 /* release memory */
3581 free_entries(entry
);
3583 /* read contents from disk */
3584 #ifdef _SHELL_FOLDERS
3585 if (entry
->etype
== ET_SHELL
)
3587 read_directory(entry
, NULL
, child
->sortOrder
, hwnd
);
3592 get_path(entry
, path
);
3593 read_directory(entry
, path
, child
->sortOrder
, hwnd
);
3596 /* insert found entries in right pane */
3597 insert_entries(&child
->right
, entry
->down
, child
->filter_pattern
, child
->filter_flags
, -1);
3598 calc_widths(&child
->right
, FALSE
);
3599 #ifndef _NO_EXTENSIONS
3600 set_header(&child
->right
);
3603 child
->header_wdths_ok
= FALSE
;
3605 SetCursor(old_cursor
);
3609 /* expand a directory entry */
3611 static BOOL
expand_entry(ChildWnd
* child
, Entry
* dir
)
3616 if (!dir
|| dir
->expanded
|| !dir
->down
)
3621 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='\0' && p
->next
) {
3624 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='.' &&
3625 p
->data
.cFileName
[2]=='\0' && p
->next
)
3629 /* no subdirectories ? */
3630 if (!(p
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
3633 idx
= ListBox_FindItemData(child
->left
.hwnd
, 0, dir
);
3635 dir
->expanded
= TRUE
;
3637 /* insert entries in left pane */
3638 insert_entries(&child
->left
, p
, NULL
, TF_ALL
, idx
);
3640 if (!child
->header_wdths_ok
) {
3641 if (calc_widths(&child
->left
, FALSE
)) {
3642 #ifndef _NO_EXTENSIONS
3643 set_header(&child
->left
);
3646 child
->header_wdths_ok
= TRUE
;
3654 static void collapse_entry(Pane
* pane
, Entry
* dir
)
3656 int idx
= ListBox_FindItemData(pane
->hwnd
, 0, dir
);
3658 ShowWindow(pane
->hwnd
, SW_HIDE
);
3660 /* hide sub entries */
3662 LRESULT res
= ListBox_GetItemData(pane
->hwnd
, idx
+1);
3663 Entry
* sub
= (Entry
*) res
;
3665 if (res
==LB_ERR
|| !sub
|| sub
->level
<=dir
->level
)
3668 ListBox_DeleteString(pane
->hwnd
, idx
+1);
3671 dir
->expanded
= FALSE
;
3673 ShowWindow(pane
->hwnd
, SW_SHOW
);
3677 static void refresh_right_pane(ChildWnd
* child
)
3679 ListBox_ResetContent(child
->right
.hwnd
);
3680 insert_entries(&child
->right
, child
->right
.root
, child
->filter_pattern
, child
->filter_flags
, -1);
3681 calc_widths(&child
->right
, FALSE
);
3683 #ifndef _NO_EXTENSIONS
3684 set_header(&child
->right
);
3688 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3690 TCHAR path
[MAX_PATH
];
3697 child
->left
.cur
= entry
;
3699 child
->right
.root
= entry
->down
? entry
->down
: entry
;
3700 child
->right
.cur
= entry
;
3702 if (!entry
->scanned
)
3703 scan_entry(child
, entry
, idx
, hwnd
);
3705 refresh_right_pane(child
);
3707 get_path(entry
, path
);
3708 lstrcpy(child
->path
, path
);
3710 if (child
->hwnd
) /* only change window title, if the window already exists */
3711 SetWindowText(child
->hwnd
, path
);
3714 if (SetCurrentDirectory(path
))
3719 static void refresh_child(ChildWnd
* child
)
3721 TCHAR path
[MAX_PATH
], drv
[_MAX_DRIVE
+1];
3725 get_path(child
->left
.cur
, path
);
3726 _tsplitpath(path
, drv
, NULL
, NULL
, NULL
);
3728 child
->right
.root
= NULL
;
3730 scan_entry(child
, &child
->root
.entry
, 0, child
->hwnd
);
3732 entry
= read_tree(&child
->root
, path
, NULL
, drv
, child
->sortOrder
, child
->hwnd
);
3734 insert_entries(&child
->left
, child
->root
.entry
.down
, NULL
, TF_ALL
, 0);
3736 set_curdir(child
, entry
, 0, child
->hwnd
);
3738 idx
= ListBox_FindItemData(child
->left
.hwnd
, 0, child
->left
.cur
);
3739 ListBox_SetCurSel(child
->left
.hwnd
, idx
);
3743 static void create_drive_bar(void)
3745 TBBUTTON drivebarBtn
= {0, 0, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0};
3746 #ifndef _NO_EXTENSIONS
3747 TCHAR b1
[BUFFER_LEN
];
3752 GetLogicalDriveStrings(BUFFER_LEN
, Globals
.drives
);
3754 Globals
.hdrivebar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
,
3755 IDW_DRIVEBAR
, 2, Globals
.hInstance
, IDB_DRIVEBAR
, &drivebarBtn
,
3756 0, 16, 13, 16, 13, sizeof(TBBUTTON
));
3758 #ifndef _NO_EXTENSIONS
3760 /* insert unix file system button */
3764 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
3766 drivebarBtn
.idCommand
= ID_DRIVE_UNIX_FS
;
3767 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3768 drivebarBtn
.iString
++;
3770 #ifdef _SHELL_FOLDERS
3771 /* insert shell namespace button */
3772 load_string(b1
, IDS_SHELL
);
3773 b1
[lstrlen(b1
)+1] = '\0';
3774 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
3776 drivebarBtn
.idCommand
= ID_DRIVE_SHELL_NS
;
3777 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3778 drivebarBtn
.iString
++;
3781 /* register windows drive root strings */
3782 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)Globals
.drives
);
3785 drivebarBtn
.idCommand
= ID_DRIVE_FIRST
;
3787 for(p
=Globals
.drives
; *p
; ) {
3788 #ifdef _NO_EXTENSIONS
3789 /* insert drive letter */
3790 TCHAR b
[3] = {tolower(*p
)};
3791 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b
);
3793 switch(GetDriveType(p
)) {
3794 case DRIVE_REMOVABLE
: drivebarBtn
.iBitmap
= 1; break;
3795 case DRIVE_CDROM
: drivebarBtn
.iBitmap
= 3; break;
3796 case DRIVE_REMOTE
: drivebarBtn
.iBitmap
= 4; break;
3797 case DRIVE_RAMDISK
: drivebarBtn
.iBitmap
= 5; break;
3798 default:/*DRIVE_FIXED*/ drivebarBtn
.iBitmap
= 2;
3801 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3802 drivebarBtn
.idCommand
++;
3803 drivebarBtn
.iString
++;
3809 static void refresh_drives(void)
3813 /* destroy drive bar */
3814 DestroyWindow(Globals
.hdrivebar
);
3815 Globals
.hdrivebar
= 0;
3817 /* re-create drive bar */
3820 /* update window layout */
3821 GetClientRect(Globals
.hMainWnd
, &rect
);
3822 SendMessage(Globals
.hMainWnd
, WM_SIZE
, 0, MAKELONG(rect
.right
, rect
.bottom
));
3826 static BOOL
launch_file(HWND hwnd
, LPCTSTR cmd
, UINT nCmdShow
)
3828 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3830 if ((int)hinst
<= 32) {
3831 display_error(hwnd
, GetLastError());
3839 static BOOL
launch_entry(Entry
* entry
, HWND hwnd
, UINT nCmdShow
)
3841 TCHAR cmd
[MAX_PATH
];
3843 #ifdef _SHELL_FOLDERS
3844 if (entry
->etype
== ET_SHELL
) {
3847 SHELLEXECUTEINFO shexinfo
;
3849 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFO
);
3850 shexinfo
.fMask
= SEE_MASK_IDLIST
;
3851 shexinfo
.hwnd
= hwnd
;
3852 shexinfo
.lpVerb
= NULL
;
3853 shexinfo
.lpFile
= NULL
;
3854 shexinfo
.lpParameters
= NULL
;
3855 shexinfo
.lpDirectory
= NULL
;
3856 shexinfo
.nShow
= nCmdShow
;
3857 shexinfo
.lpIDList
= get_to_absolute_pidl(entry
, hwnd
);
3859 if (!ShellExecuteEx(&shexinfo
)) {
3860 display_error(hwnd
, GetLastError());
3864 if (shexinfo
.lpIDList
!= entry
->pidl
)
3865 (*Globals
.iMalloc
->lpVtbl
->Free
)(Globals
.iMalloc
, shexinfo
.lpIDList
);
3871 get_path(entry
, cmd
);
3873 /* start program, open document... */
3874 return launch_file(hwnd
, cmd
, nCmdShow
);
3878 static void activate_entry(ChildWnd
* child
, Pane
* pane
, HWND hwnd
)
3880 Entry
* entry
= pane
->cur
;
3885 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
3886 int scanned_old
= entry
->scanned
;
3889 scan_entry(child
, entry
, ListBox_GetCurSel(child
->left
.hwnd
), hwnd
);
3891 #ifndef _NO_EXTENSIONS
3892 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='\0')
3896 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='.' && entry
->data
.cFileName
[2]=='\0') {
3897 entry
= child
->left
.cur
->up
;
3898 collapse_entry(&child
->left
, entry
);
3900 } else if (entry
->expanded
)
3901 collapse_entry(pane
, child
->left
.cur
);
3903 expand_entry(child
, child
->left
.cur
);
3905 if (!pane
->treePane
) focus_entry
: {
3906 int idx
= ListBox_FindItemData(child
->left
.hwnd
, ListBox_GetCurSel(child
->left
.hwnd
), entry
);
3907 ListBox_SetCurSel(child
->left
.hwnd
, idx
);
3908 set_curdir(child
, entry
, idx
, hwnd
);
3913 calc_widths(pane
, FALSE
);
3915 #ifndef _NO_EXTENSIONS
3920 if (GetKeyState(VK_MENU
) < 0)
3921 show_properties_dlg(entry
, child
->hwnd
);
3923 launch_entry(entry
, child
->hwnd
, SW_SHOWNORMAL
);
3928 static BOOL
pane_command(Pane
* pane
, UINT cmd
)
3932 if (pane
->visible_cols
) {
3933 pane
->visible_cols
= 0;
3934 calc_widths(pane
, TRUE
);
3935 #ifndef _NO_EXTENSIONS
3938 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3939 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
|MF_CHECKED
);
3940 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
);
3941 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
3945 case ID_VIEW_ALL_ATTRIBUTES
:
3946 if (pane
->visible_cols
!= COL_ALL
) {
3947 pane
->visible_cols
= COL_ALL
;
3948 calc_widths(pane
, TRUE
);
3949 #ifndef _NO_EXTENSIONS
3952 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3953 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
);
3954 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
|MF_CHECKED
);
3955 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
3959 #ifndef _NO_EXTENSIONS
3960 case ID_PREFERRED_SIZES
: {
3961 calc_widths(pane
, TRUE
);
3963 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3967 /* TODO: more command ids... */
3977 static void set_sort_order(ChildWnd
* child
, SORT_ORDER sortOrder
)
3979 if (child
->sortOrder
!= sortOrder
) {
3980 child
->sortOrder
= sortOrder
;
3981 refresh_child(child
);
3985 static void update_view_menu(ChildWnd
* child
)
3987 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_NAME
, child
->sortOrder
==SORT_NAME
? MF_CHECKED
: MF_UNCHECKED
);
3988 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_TYPE
, child
->sortOrder
==SORT_EXT
? MF_CHECKED
: MF_UNCHECKED
);
3989 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_SIZE
, child
->sortOrder
==SORT_SIZE
? MF_CHECKED
: MF_UNCHECKED
);
3990 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_DATE
, child
->sortOrder
==SORT_DATE
? MF_CHECKED
: MF_UNCHECKED
);
3994 static BOOL
is_directory(LPCTSTR target
)
3996 /*TODO correctly handle UNIX paths */
3997 DWORD target_attr
= GetFileAttributes(target
);
3999 if (target_attr
== INVALID_FILE_ATTRIBUTES
)
4002 return target_attr
&FILE_ATTRIBUTE_DIRECTORY
? TRUE
: FALSE
;
4005 static BOOL
prompt_target(Pane
* pane
, LPTSTR source
, LPTSTR target
)
4007 TCHAR path
[MAX_PATH
];
4010 get_path(pane
->cur
, path
);
4012 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_SELECT_DESTINATION
), pane
->hwnd
, DestinationDlgProc
, (LPARAM
)path
) != IDOK
)
4015 get_path(pane
->cur
, source
);
4017 /* convert relative targets to absolute paths */
4018 if (path
[0]!='/' && path
[1]!=':') {
4019 get_path(pane
->cur
->up
, target
);
4020 len
= lstrlen(target
);
4022 if (target
[len
-1]!='\\' && target
[len
-1]!='/')
4023 target
[len
++] = '/';
4025 lstrcpy(target
+len
, path
);
4027 lstrcpy(target
, path
);
4029 /* If the target already exists as directory, create a new target below this. */
4030 if (is_directory(path
)) {
4031 TCHAR fname
[_MAX_FNAME
], ext
[_MAX_EXT
];
4032 const static TCHAR sAppend
[] = {'%','s','/','%','s','%','s','\0'};
4034 _tsplitpath(source
, NULL
, NULL
, fname
, ext
);
4036 wsprintf(target
, sAppend
, path
, fname
, ext
);
4043 static IContextMenu2
* s_pctxmenu2
= NULL
;
4044 static IContextMenu3
* s_pctxmenu3
= NULL
;
4046 static void CtxMenu_reset(void)
4052 static IContextMenu
* CtxMenu_query_interfaces(IContextMenu
* pcm1
)
4054 IContextMenu
* pcm
= NULL
;
4058 if ((*pcm1
->lpVtbl
->QueryInterface
)(pcm1
, &IID_IContextMenu3
, (void**)&pcm
) == NOERROR
)
4059 s_pctxmenu3
= (LPCONTEXTMENU3
)pcm
;
4060 else if ((*pcm1
->lpVtbl
->QueryInterface
)(pcm1
, &IID_IContextMenu2
, (void**)&pcm
) == NOERROR
)
4061 s_pctxmenu2
= (LPCONTEXTMENU2
)pcm
;
4064 (*pcm1
->lpVtbl
->Release
)(pcm1
);
4070 static BOOL
CtxMenu_HandleMenuMsg(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4073 if (SUCCEEDED((*s_pctxmenu3
->lpVtbl
->HandleMenuMsg
)(s_pctxmenu3
, nmsg
, wparam
, lparam
)))
4078 if (SUCCEEDED((*s_pctxmenu2
->lpVtbl
->HandleMenuMsg
)(s_pctxmenu2
, nmsg
, wparam
, lparam
)))
4085 static HRESULT
ShellFolderContextMenu(IShellFolder
* shell_folder
, HWND hwndParent
, int cidl
, LPCITEMIDLIST
* apidl
, int x
, int y
)
4088 BOOL executed
= FALSE
;
4090 HRESULT hr
= (*shell_folder
->lpVtbl
->GetUIObjectOf
)(shell_folder
, hwndParent
, cidl
, apidl
, &IID_IContextMenu
, NULL
, (LPVOID
*)&pcm
);
4091 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
4093 if (SUCCEEDED(hr
)) {
4094 HMENU hmenu
= CreatePopupMenu();
4096 pcm
= CtxMenu_query_interfaces(pcm
);
4099 hr
= (*pcm
->lpVtbl
->QueryContextMenu
)(pcm
, hmenu
, 0, FCIDM_SHVIEWFIRST
, FCIDM_SHVIEWLAST
, CMF_NORMAL
);
4101 if (SUCCEEDED(hr
)) {
4102 UINT idCmd
= TrackPopupMenu(hmenu
, TPM_LEFTALIGN
|TPM_RETURNCMD
|TPM_RIGHTBUTTON
, x
, y
, 0, hwndParent
, NULL
);
4107 CMINVOKECOMMANDINFO cmi
;
4109 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFO
);
4111 cmi
.hwnd
= hwndParent
;
4112 cmi
.lpVerb
= (LPCSTR
)(INT_PTR
)(idCmd
- FCIDM_SHVIEWFIRST
);
4113 cmi
.lpParameters
= NULL
;
4114 cmi
.lpDirectory
= NULL
;
4115 cmi
.nShow
= SW_SHOWNORMAL
;
4119 hr
= (*pcm
->lpVtbl
->InvokeCommand
)(pcm
, &cmi
);
4126 (*pcm
->lpVtbl
->Release
)(pcm
);
4129 return FAILED(hr
)? hr
: executed
? S_OK
: S_FALSE
;
4133 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4135 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(hwnd
, GWL_USERDATA
);
4140 LPDRAWITEMSTRUCT dis
= (LPDRAWITEMSTRUCT
)lparam
;
4141 Entry
* entry
= (Entry
*) dis
->itemData
;
4143 if (dis
->CtlID
== IDW_TREE_LEFT
)
4144 draw_item(&child
->left
, dis
, entry
, -1);
4145 else if (dis
->CtlID
== IDW_TREE_RIGHT
)
4146 draw_item(&child
->right
, dis
, entry
, -1);
4148 goto draw_menu_item
;
4153 InitChildWindow(child
);
4157 free_child_window(child
);
4158 SetWindowLong(hwnd
, GWL_USERDATA
, 0);
4165 GetClientRect(hwnd
, &rt
);
4166 BeginPaint(hwnd
, &ps
);
4167 rt
.left
= child
->split_pos
-SPLIT_WIDTH
/2;
4168 rt
.right
= child
->split_pos
+SPLIT_WIDTH
/2+1;
4169 lastBrush
= SelectBrush(ps
.hdc
, (HBRUSH
)GetStockObject(COLOR_SPLITBAR
));
4170 Rectangle(ps
.hdc
, rt
.left
, rt
.top
-1, rt
.right
, rt
.bottom
+1);
4171 SelectObject(ps
.hdc
, lastBrush
);
4172 #ifdef _NO_EXTENSIONS
4173 rt
.top
= rt
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
4174 FillRect(ps
.hdc
, &rt
, GetStockObject(BLACK_BRUSH
));
4176 EndPaint(hwnd
, &ps
);
4180 if (LOWORD(lparam
) == HTCLIENT
) {
4183 ScreenToClient(hwnd
, &pt
);
4185 if (pt
.x
>=child
->split_pos
-SPLIT_WIDTH
/2 && pt
.x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
4186 SetCursor(LoadCursor(0, IDC_SIZEWE
));
4192 case WM_LBUTTONDOWN
: {
4194 int x
= GET_X_LPARAM(lparam
);
4196 GetClientRect(hwnd
, &rt
);
4198 if (x
>=child
->split_pos
-SPLIT_WIDTH
/2 && x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
4199 last_split
= child
->split_pos
;
4200 #ifdef _NO_EXTENSIONS
4201 draw_splitbar(hwnd
, last_split
);
4209 if (GetCapture() == hwnd
) {
4210 #ifdef _NO_EXTENSIONS
4212 int x
= LOWORD(lparam
);
4213 draw_splitbar(hwnd
, last_split
);
4215 GetClientRect(hwnd
, &rt
);
4216 child
->split_pos
= x
;
4217 resize_tree(child
, rt
.right
, rt
.bottom
);
4223 #ifdef _NO_EXTENSIONS
4224 case WM_CAPTURECHANGED
:
4225 if (GetCapture()==hwnd
&& last_split
>=0)
4226 draw_splitbar(hwnd
, last_split
);
4231 if (wparam
== VK_ESCAPE
)
4232 if (GetCapture() == hwnd
) {
4234 #ifdef _NO_EXTENSIONS
4235 draw_splitbar(hwnd
, last_split
);
4237 child
->split_pos
= last_split
;
4239 GetClientRect(hwnd
, &rt
);
4240 resize_tree(child
, rt
.right
, rt
.bottom
);
4243 SetCursor(LoadCursor(0, IDC_ARROW
));
4248 if (GetCapture() == hwnd
) {
4250 int x
= LOWORD(lparam
);
4252 #ifdef _NO_EXTENSIONS
4253 HDC hdc
= GetDC(hwnd
);
4254 GetClientRect(hwnd
, &rt
);
4256 rt
.left
= last_split
-SPLIT_WIDTH
/2;
4257 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
4258 InvertRect(hdc
, &rt
);
4261 rt
.left
= x
-SPLIT_WIDTH
/2;
4262 rt
.right
= x
+SPLIT_WIDTH
/2+1;
4263 InvertRect(hdc
, &rt
);
4265 ReleaseDC(hwnd
, hdc
);
4267 GetClientRect(hwnd
, &rt
);
4269 if (x
>=0 && x
<rt
.right
) {
4270 child
->split_pos
= x
;
4271 resize_tree(child
, rt
.right
, rt
.bottom
);
4272 rt
.left
= x
-SPLIT_WIDTH
/2;
4273 rt
.right
= x
+SPLIT_WIDTH
/2+1;
4274 InvalidateRect(hwnd
, &rt
, FALSE
);
4275 UpdateWindow(child
->left
.hwnd
);
4277 UpdateWindow(child
->right
.hwnd
);
4283 #ifndef _NO_EXTENSIONS
4284 case WM_GETMINMAXINFO
:
4285 DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
4287 {LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
4289 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
4290 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
4292 #endif /* _NO_EXTENSIONS */
4295 if (SetCurrentDirectory(child
->path
))
4297 SetFocus(child
->focus_pane
? child
->right
.hwnd
: child
->left
.hwnd
);
4300 case WM_DISPATCH_COMMAND
: {
4301 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4303 switch(LOWORD(wparam
)) {
4304 case ID_WINDOW_NEW
: {
4305 ChildWnd
* new_child
= alloc_child_window(child
->path
, NULL
, hwnd
);
4307 if (!create_child_window(new_child
))
4314 refresh_child(child
);
4318 activate_entry(child
, pane
, hwnd
);
4321 case ID_FILE_MOVE
: {
4322 TCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
4324 if (prompt_target(pane
, source
, target
)) {
4325 SHFILEOPSTRUCT shfo
= {hwnd
, FO_MOVE
, source
, target
};
4327 source
[lstrlen(source
)+1] = '\0';
4328 target
[lstrlen(target
)+1] = '\0';
4330 if (!SHFileOperation(&shfo
))
4331 refresh_child(child
);
4335 case ID_FILE_COPY
: {
4336 TCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
4338 if (prompt_target(pane
, source
, target
)) {
4339 SHFILEOPSTRUCT shfo
= {hwnd
, FO_COPY
, source
, target
};
4341 source
[lstrlen(source
)+1] = '\0';
4342 target
[lstrlen(target
)+1] = '\0';
4344 if (!SHFileOperation(&shfo
))
4345 refresh_child(child
);
4349 case ID_FILE_DELETE
: {
4350 TCHAR path
[BUFFER_LEN
];
4351 SHFILEOPSTRUCT shfo
= {hwnd
, FO_DELETE
, path
};
4353 get_path(pane
->cur
, path
);
4355 path
[lstrlen(path
)+1] = '\0';
4357 if (!SHFileOperation(&shfo
))
4358 refresh_child(child
);
4361 case ID_VIEW_SORT_NAME
:
4362 set_sort_order(child
, SORT_NAME
);
4365 case ID_VIEW_SORT_TYPE
:
4366 set_sort_order(child
, SORT_EXT
);
4369 case ID_VIEW_SORT_SIZE
:
4370 set_sort_order(child
, SORT_SIZE
);
4373 case ID_VIEW_SORT_DATE
:
4374 set_sort_order(child
, SORT_DATE
);
4377 case ID_VIEW_FILTER
: {
4378 struct FilterDialog dlg
;
4380 memset(&dlg
, 0, sizeof(struct FilterDialog
));
4381 lstrcpy(dlg
.pattern
, child
->filter_pattern
);
4382 dlg
.flags
= child
->filter_flags
;
4384 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE
), hwnd
, FilterDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
4385 lstrcpy(child
->filter_pattern
, dlg
.pattern
);
4386 child
->filter_flags
= dlg
.flags
;
4387 refresh_right_pane(child
);
4391 case ID_VIEW_SPLIT
: {
4392 last_split
= child
->split_pos
;
4393 #ifdef _NO_EXTENSIONS
4394 draw_splitbar(hwnd
, last_split
);
4399 case ID_EDIT_PROPERTIES
:
4400 show_properties_dlg(pane
->cur
, child
->hwnd
);
4404 return pane_command(pane
, LOWORD(wparam
));
4410 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4412 switch(HIWORD(wparam
)) {
4413 case LBN_SELCHANGE
: {
4414 int idx
= ListBox_GetCurSel(pane
->hwnd
);
4415 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, idx
);
4417 if (pane
== &child
->left
)
4418 set_curdir(child
, entry
, idx
, hwnd
);
4424 activate_entry(child
, pane
, hwnd
);
4429 #ifndef _NO_EXTENSIONS
4431 NMHDR
* pnmh
= (NMHDR
*) lparam
;
4432 return pane_notify(pnmh
->idFrom
==IDW_HEADER_LEFT
? &child
->left
: &child
->right
, pnmh
);}
4435 #ifdef _SHELL_FOLDERS
4436 case WM_CONTEXTMENU
: {
4441 /* first select the current item in the listbox */
4442 HWND hpanel
= (HWND
) wparam
;
4443 pt_clnt
.x
= pt
.x
= (short)LOWORD(lparam
);
4444 pt_clnt
.y
= pt
.y
= (short)HIWORD(lparam
);
4445 ScreenToClient(hpanel
, &pt_clnt
);
4446 SendMessage(hpanel
, WM_LBUTTONDOWN
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4447 SendMessage(hpanel
, WM_LBUTTONUP
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4449 /* now create the popup menu using shell namespace and IContextMenu */
4450 pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4451 idx
= ListBox_GetCurSel(pane
->hwnd
);
4454 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, idx
);
4456 LPITEMIDLIST pidl_abs
= get_to_absolute_pidl(entry
, hwnd
);
4459 IShellFolder
* parentFolder
;
4460 LPCITEMIDLIST pidlLast
;
4462 /* get and use the parent folder to display correct context menu in all cases */
4463 if (SUCCEEDED(SHBindToParent(pidl_abs
, &IID_IShellFolder
, (LPVOID
*)&parentFolder
, &pidlLast
))) {
4464 if (ShellFolderContextMenu(parentFolder
, hwnd
, 1, &pidlLast
, pt
.x
, pt
.y
) == S_OK
)
4465 refresh_child(child
);
4467 (*parentFolder
->lpVtbl
->Release
)(parentFolder
);
4470 (*Globals
.iMalloc
->lpVtbl
->Free
)(Globals
.iMalloc
, pidl_abs
);
4476 case WM_MEASUREITEM
:
4478 if (!wparam
) /* Is the message menu-related? */
4479 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4484 case WM_INITMENUPOPUP
:
4485 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4488 update_view_menu(child
);
4491 case WM_MENUCHAR
: /* only supported by IContextMenu3 */
4493 LRESULT lResult
= 0;
4495 (*s_pctxmenu3
->lpVtbl
->HandleMenuMsg2
)(s_pctxmenu3
, nmsg
, wparam
, lparam
, &lResult
);
4503 if (wparam
!= SIZE_MINIMIZED
)
4504 resize_tree(child
, LOWORD(lparam
), HIWORD(lparam
));
4508 return DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
4515 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4517 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(GetParent(hwnd
), GWL_USERDATA
);
4518 Pane
* pane
= (Pane
*) GetWindowLong(hwnd
, GWL_USERDATA
);
4522 #ifndef _NO_EXTENSIONS
4529 child
->focus_pane
= pane
==&child
->right
? 1: 0;
4530 ListBox_SetSel(hwnd
, TRUE
, 1);
4531 /*TODO: check menu items */
4535 if (wparam
== VK_TAB
) {
4536 /*TODO: SetFocus(Globals.hdrivebar) */
4537 SetFocus(child
->focus_pane
? child
->left
.hwnd
: child
->right
.hwnd
);
4541 return CallWindowProc(g_orgTreeWndProc
, hwnd
, nmsg
, wparam
, lparam
);
4545 static void InitInstance(HINSTANCE hinstance
)
4547 const static TCHAR sFont
[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4554 INITCOMMONCONTROLSEX icc
= {
4555 sizeof(INITCOMMONCONTROLSEX
),
4561 setlocale(LC_COLLATE
, ""); /* set collating rules to local settings for compareName */
4563 InitCommonControlsEx(&icc
);
4566 /* register frame window class */
4568 wcFrame
.cbSize
= sizeof(WNDCLASSEX
);
4570 wcFrame
.lpfnWndProc
= FrameWndProc
;
4571 wcFrame
.cbClsExtra
= 0;
4572 wcFrame
.cbWndExtra
= 0;
4573 wcFrame
.hInstance
= hinstance
;
4574 wcFrame
.hIcon
= LoadIcon(hinstance
, MAKEINTRESOURCE(IDI_WINEFILE
));
4575 wcFrame
.hCursor
= LoadCursor(0, IDC_ARROW
);
4576 wcFrame
.hbrBackground
= 0;
4577 wcFrame
.lpszMenuName
= 0;
4578 wcFrame
.lpszClassName
= sWINEFILEFRAME
;
4579 wcFrame
.hIconSm
= (HICON
)LoadImage(hinstance
,
4580 MAKEINTRESOURCE(IDI_WINEFILE
),
4582 GetSystemMetrics(SM_CXSMICON
),
4583 GetSystemMetrics(SM_CYSMICON
),
4586 Globals
.hframeClass
= RegisterClassEx(&wcFrame
);
4589 /* register tree windows class */
4591 wcChild
.style
= CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
;
4592 wcChild
.lpfnWndProc
= ChildWndProc
;
4593 wcChild
.cbClsExtra
= 0;
4594 wcChild
.cbWndExtra
= 0;
4595 wcChild
.hInstance
= hinstance
;
4597 wcChild
.hCursor
= LoadCursor(0, IDC_ARROW
);
4598 wcChild
.hbrBackground
= 0;
4599 wcChild
.lpszMenuName
= 0;
4600 wcChild
.lpszClassName
= sWINEFILETREE
;
4602 hChildClass
= RegisterClass(&wcChild
);
4605 Globals
.haccel
= LoadAccelerators(hinstance
, MAKEINTRESOURCE(IDA_WINEFILE
));
4607 Globals
.hfont
= CreateFont(-MulDiv(8,GetDeviceCaps(hdc
,LOGPIXELSY
),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont
);
4611 Globals
.hInstance
= hinstance
;
4613 #ifdef _SHELL_FOLDERS
4615 CoGetMalloc(MEMCTX_TASK
, &Globals
.iMalloc
);
4616 SHGetDesktopFolder(&Globals
.iDesktop
);
4618 Globals
.cfStrFName
= RegisterClipboardFormatA(CFSTR_FILENAME
);
4620 Globals
.cfStrFName
= RegisterClipboardFormat(CFSTR_FILENAME
);
4624 /* load column strings */
4627 load_string(g_pos_names
[col
++], IDS_COL_NAME
);
4628 load_string(g_pos_names
[col
++], IDS_COL_SIZE
);
4629 load_string(g_pos_names
[col
++], IDS_COL_CDATE
);
4630 #ifndef _NO_EXTENSIONS
4631 load_string(g_pos_names
[col
++], IDS_COL_ADATE
);
4632 load_string(g_pos_names
[col
++], IDS_COL_MDATE
);
4633 load_string(g_pos_names
[col
++], IDS_COL_IDX
);
4634 load_string(g_pos_names
[col
++], IDS_COL_LINKS
);
4636 load_string(g_pos_names
[col
++], IDS_COL_ATTR
);
4637 #ifndef _NO_EXTENSIONS
4638 load_string(g_pos_names
[col
++], IDS_COL_SEC
);
4643 static void show_frame(HWND hwndParent
, int cmdshow
)
4645 const static TCHAR sMDICLIENT
[] = {'M','D','I','C','L','I','E','N','T','\0'};
4647 TCHAR path
[MAX_PATH
], b1
[BUFFER_LEN
];
4649 HMENU hMenuFrame
, hMenuWindow
;
4651 CLIENTCREATESTRUCT ccs
;
4653 if (Globals
.hMainWnd
)
4656 Globals
.hwndParent
= hwndParent
;
4658 hMenuFrame
= LoadMenu(Globals
.hInstance
, MAKEINTRESOURCE(IDM_WINEFILE
));
4659 hMenuWindow
= GetSubMenu(hMenuFrame
, GetMenuItemCount(hMenuFrame
)-2);
4661 Globals
.hMenuFrame
= hMenuFrame
;
4662 Globals
.hMenuView
= GetSubMenu(hMenuFrame
, 3);
4663 Globals
.hMenuOptions
= GetSubMenu(hMenuFrame
, 4);
4665 ccs
.hWindowMenu
= hMenuWindow
;
4666 ccs
.idFirstChild
= IDW_FIRST_CHILD
;
4669 /* create main window */
4670 Globals
.hMainWnd
= CreateWindowEx(0, (LPCTSTR
)(int)Globals
.hframeClass
, RS(b1
,IDS_WINE_FILE
), WS_OVERLAPPEDWINDOW
,
4671 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
4672 hwndParent
, Globals
.hMenuFrame
, Globals
.hInstance
, 0/*lpParam*/);
4675 Globals
.hmdiclient
= CreateWindowEx(0, sMDICLIENT
, NULL
,
4676 WS_CHILD
|WS_CLIPCHILDREN
|WS_VSCROLL
|WS_HSCROLL
|WS_VISIBLE
|WS_BORDER
,
4678 Globals
.hMainWnd
, 0, Globals
.hInstance
, &ccs
);
4681 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_DRIVE_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4686 TBBUTTON toolbarBtns
[] = {
4687 {0, 0, 0, BTNS_SEP
, {0, 0}, 0, 0},
4688 {0, ID_WINDOW_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4689 {1, ID_WINDOW_CASCADE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4690 {2, ID_WINDOW_TILE_HORZ
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4691 {3, ID_WINDOW_TILE_VERT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4693 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4694 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4697 Globals
.htoolbar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
,
4698 IDW_TOOLBAR
, 2, Globals
.hInstance
, IDB_TOOLBAR
, toolbarBtns
,
4699 sizeof(toolbarBtns
)/sizeof(TBBUTTON
), 16, 15, 16, 15, sizeof(TBBUTTON
));
4700 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_TOOL_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4703 Globals
.hstatusbar
= CreateStatusWindow(WS_CHILD
|WS_VISIBLE
, 0, Globals
.hMainWnd
, IDW_STATUSBAR
);
4704 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
4706 /* CreateStatusWindow does not accept WS_BORDER
4707 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
4708 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
4709 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
4711 /*TODO: read paths and window placements from registry */
4712 GetCurrentDirectory(MAX_PATH
, path
);
4714 ShowWindow(Globals
.hMainWnd
, cmdshow
);
4716 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4717 /* Shell Namespace as default: */
4718 child
= alloc_child_window(path
, get_path_pidl(path
,Globals
.hMainWnd
), Globals
.hMainWnd
);
4720 child
= alloc_child_window(path
, NULL
, Globals
.hMainWnd
);
4723 child
->pos
.showCmd
= SW_SHOWMAXIMIZED
;
4724 child
->pos
.rcNormalPosition
.left
= 0;
4725 child
->pos
.rcNormalPosition
.top
= 0;
4726 child
->pos
.rcNormalPosition
.right
= 320;
4727 child
->pos
.rcNormalPosition
.bottom
= 280;
4729 if (!create_child_window(child
))
4732 SetWindowPlacement(child
->hwnd
, &child
->pos
);
4734 Globals
.himl
= ImageList_LoadBitmap(Globals
.hInstance
, MAKEINTRESOURCE(IDB_IMAGES
), 16, 0, RGB(0,255,0));
4736 Globals
.prescan_node
= FALSE
;
4738 UpdateWindow(Globals
.hMainWnd
);
4741 static void ExitInstance(void)
4743 #ifdef _SHELL_FOLDERS
4744 (*Globals
.iDesktop
->lpVtbl
->Release
)(Globals
.iDesktop
);
4745 (*Globals
.iMalloc
->lpVtbl
->Release
)(Globals
.iMalloc
);
4749 ImageList_Destroy(Globals
.himl
);
4752 #ifdef _NO_EXTENSIONS
4754 /* search for already running win[e]files */
4756 static int g_foundPrevInstance
= 0;
4758 static BOOL CALLBACK
EnumWndProc(HWND hwnd
, LPARAM lparam
)
4762 GetClassName(hwnd
, cls
, 128);
4764 if (!lstrcmp(cls
, (LPCTSTR
)lparam
)) {
4765 g_foundPrevInstance
++;
4772 /* search for window of given class name to allow only one running instance */
4773 static int find_window_class(LPCTSTR classname
)
4775 EnumWindows(EnumWndProc
, (LPARAM
)classname
);
4777 if (g_foundPrevInstance
)
4785 static int winefile_main(HINSTANCE hinstance
, HWND hwndParent
, int cmdshow
)
4789 InitInstance(hinstance
);
4791 if (cmdshow
== SW_SHOWNORMAL
)
4792 /*TODO: read window placement from registry */
4793 cmdshow
= SW_MAXIMIZE
;
4795 show_frame(hwndParent
, cmdshow
);
4797 while(GetMessage(&msg
, 0, 0, 0)) {
4798 if (Globals
.hmdiclient
&& TranslateMDISysAccel(Globals
.hmdiclient
, &msg
))
4801 if (Globals
.hMainWnd
&& TranslateAccelerator(Globals
.hMainWnd
, Globals
.haccel
, &msg
))
4804 TranslateMessage(&msg
);
4805 DispatchMessage(&msg
);
4814 int APIENTRY
WinMain(HINSTANCE hinstance
,
4815 HINSTANCE previnstance
,
4819 #ifdef _NO_EXTENSIONS
4820 if (find_window_class(sWINEFILEFRAME
))
4824 winefile_main(hinstance
, 0, cmdshow
);