4 * Copyright 2000, 2003, 2004, 2005 Martin Fuchs
5 * Copyright 2006 Jason Green
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
26 /* for unix filesystem function calls */
28 #include <sys/types.h>
43 #define _MAX_FNAME 256
44 #define _MAX_DIR _MAX_FNAME
45 #define _MAX_EXT _MAX_FNAME
49 #ifdef NONAMELESSUNION
50 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
52 #define UNION_MEMBER(x) x
57 #define DEFAULT_SPLIT_POS 300
59 #define DEFAULT_SPLIT_POS 200
62 static const WCHAR registry_key
[] = { 'S','o','f','t','w','a','r','e','\\',
64 'W','i','n','e','F','i','l','e','\0'};
65 static const WCHAR reg_start_x
[] = { 's','t','a','r','t','X','\0'};
66 static const WCHAR reg_start_y
[] = { 's','t','a','r','t','Y','\0'};
67 static const WCHAR reg_width
[] = { 'w','i','d','t','h','\0'};
68 static const WCHAR reg_height
[] = { 'h','e','i','g','h','t','\0'};
78 typedef struct _Entry
{
89 #ifndef _NO_EXTENSIONS
90 BY_HANDLE_FILE_INFORMATION bhfi
;
92 enum ENTRY_TYPE etype
;
103 TCHAR path
[MAX_PATH
];
104 TCHAR volname
[_MAX_FNAME
];
114 COL_ATTRIBUTES
= 0x08,
116 #ifdef _NO_EXTENSIONS
117 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
121 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
|COL_INDEX
|COL_LINKS
134 #ifndef _NO_EXTENSIONS
138 #ifndef _NO_EXTENSIONS
144 int positions
[COLUMNS
+1];
156 int focus_pane
; /* 0: left 1: right */
159 BOOL header_wdths_ok
;
161 TCHAR path
[MAX_PATH
];
162 TCHAR filter_pattern
[MAX_PATH
];
166 SORT_ORDER sortOrder
;
171 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
);
172 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
);
173 static void refresh_child(ChildWnd
* child
);
174 static void refresh_drives(void);
175 static void get_path(Entry
* dir
, PTSTR path
);
176 static void format_date(const FILETIME
* ft
, TCHAR
* buffer
, int visible_cols
);
178 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
179 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
180 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
184 WINEFILE_GLOBALS Globals
;
186 static int last_split
;
188 /* some common string constants */
189 static const TCHAR sEmpty
[] = {'\0'};
190 static const TCHAR sSpace
[] = {' ', '\0'};
191 static const TCHAR sNumFmt
[] = {'%','d','\0'};
192 static const TCHAR sQMarks
[] = {'?','?','?','\0'};
194 /* window class names */
195 static const TCHAR sWINEFILEFRAME
[] = {'W','F','S','_','F','r','a','m','e','\0'};
196 static const TCHAR sWINEFILETREE
[] = {'W','F','S','_','T','r','e','e','\0'};
199 /* #define LONGLONGARG _T("I64") */
200 static const TCHAR sLongHexFmt
[] = {'%','I','6','4','X','\0'};
201 static const TCHAR sLongNumFmt
[] = {'%','I','6','4','d','\0'};
203 /* #define LONGLONGARG _T("L") */
204 static const TCHAR sLongHexFmt
[] = {'%','L','X','\0'};
205 static const TCHAR sLongNumFmt
[] = {'%','L','d','\0'};
209 /* load resource string */
210 static LPTSTR
load_string(LPTSTR buffer
, UINT id
)
212 LoadString(Globals
.hInstance
, id
, buffer
, BUFFER_LEN
);
217 #define RS(b, i) load_string(b, i)
220 /* display error message for the specified WIN32 error code */
221 static void display_error(HWND hwnd
, DWORD error
)
223 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
226 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_FROM_SYSTEM
,
227 0, error
, MAKELANGID(LANG_NEUTRAL
,SUBLANG_DEFAULT
), (PTSTR
)&msg
, 0, NULL
))
228 MessageBox(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
230 MessageBox(hwnd
, RS(b1
,IDS_ERROR
), RS(b2
,IDS_WINEFILE
), MB_OK
);
236 /* display network error message using WNetGetLastError() */
237 static void display_network_error(HWND hwnd
)
239 TCHAR msg
[BUFFER_LEN
], provider
[BUFFER_LEN
], b2
[BUFFER_LEN
];
242 if (WNetGetLastError(&error
, msg
, BUFFER_LEN
, provider
, BUFFER_LEN
) == NO_ERROR
)
243 MessageBox(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
246 static VOID
WineLicense(HWND Wnd
)
248 TCHAR cap
[20], text
[1024];
249 LoadString(Globals
.hInstance
, IDS_LICENSE
, text
, 1024);
250 LoadString(Globals
.hInstance
, IDS_LICENSE_CAPTION
, cap
, 20);
251 MessageBox(Wnd
, text
, cap
, MB_ICONINFORMATION
| MB_OK
);
254 static VOID
WineWarranty(HWND Wnd
)
256 TCHAR cap
[20], text
[1024];
257 LoadString(Globals
.hInstance
, IDS_WARRANTY
, text
, 1024);
258 LoadString(Globals
.hInstance
, IDS_WARRANTY_CAPTION
, cap
, 20);
259 MessageBox(Wnd
, text
, cap
, MB_ICONEXCLAMATION
| MB_OK
);
262 static inline BOOL
get_check(HWND hwnd
, INT id
)
264 return BST_CHECKED
&SendMessage(GetDlgItem(hwnd
, id
), BM_GETSTATE
, 0, 0);
267 static inline INT
set_check(HWND hwnd
, INT id
, BOOL on
)
269 return SendMessage(GetDlgItem(hwnd
, id
), BM_SETCHECK
, on
?BST_CHECKED
:BST_UNCHECKED
, 0);
276 /* call vswprintf() in msvcrt.dll */
277 /*TODO: fix swprintf() in non-msvcrt mode, so that this dynamic linking function can be removed */
278 static int msvcrt_swprintf(WCHAR
* buffer
, const WCHAR
* fmt
, ...)
280 static int (__cdecl
*pvswprintf
)(WCHAR
*, const WCHAR
*, va_list) = NULL
;
285 HMODULE hModMsvcrt
= LoadLibraryA("msvcrt");
286 pvswprintf
= (int(__cdecl
*)(WCHAR
*,const WCHAR
*,va_list)) GetProcAddress(hModMsvcrt
, "vswprintf");
290 ret
= (*pvswprintf
)(buffer
, fmt
, ap
);
296 static LPCWSTR
my_wcsrchr(LPCWSTR str
, WCHAR c
)
311 #define _tcsrchr my_wcsrchr
313 #define _tcsrchr strrchr
316 #endif /* __WINE__ */
319 /* allocate and initialise a directory entry */
320 static Entry
* alloc_entry(void)
322 Entry
* entry
= (Entry
*) malloc(sizeof(Entry
));
324 #ifdef _SHELL_FOLDERS
326 entry
->folder
= NULL
;
333 /* free a directory entry */
334 static void free_entry(Entry
* entry
)
336 #ifdef _SHELL_FOLDERS
337 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
338 DestroyIcon(entry
->hicon
);
340 if (entry
->folder
&& entry
->folder
!=Globals
.iDesktop
)
341 IShellFolder_Release(entry
->folder
);
344 IMalloc_Free(Globals
.iMalloc
, entry
->pidl
);
350 /* recursively free all child entries */
351 static void free_entries(Entry
* dir
)
353 Entry
*entry
, *next
=dir
->down
;
369 static void read_directory_win(Entry
* dir
, LPCTSTR path
)
371 Entry
* first_entry
= NULL
;
375 int level
= dir
->level
+ 1;
376 WIN32_FIND_DATA w32fd
;
378 #ifndef _NO_EXTENSIONS
382 TCHAR buffer
[MAX_PATH
], *p
;
383 for(p
=buffer
; *path
; )
390 hFind
= FindFirstFile(buffer
, &w32fd
);
392 if (hFind
!= INVALID_HANDLE_VALUE
) {
394 #ifdef _NO_EXTENSIONS
395 /* hide directory entry "." */
396 if (w32fd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
397 LPCTSTR name
= w32fd
.cFileName
;
399 if (name
[0]=='.' && name
[1]=='\0')
403 entry
= alloc_entry();
411 memcpy(&entry
->data
, &w32fd
, sizeof(WIN32_FIND_DATA
));
414 entry
->expanded
= FALSE
;
415 entry
->scanned
= FALSE
;
416 entry
->level
= level
;
418 #ifndef _NO_EXTENSIONS
419 entry
->etype
= ET_WINDOWS
;
420 entry
->bhfi_valid
= FALSE
;
422 lstrcpy(p
, entry
->data
.cFileName
);
424 hFile
= CreateFile(buffer
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
425 0, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0);
427 if (hFile
!= INVALID_HANDLE_VALUE
) {
428 if (GetFileInformationByHandle(hFile
, &entry
->bhfi
))
429 entry
->bhfi_valid
= TRUE
;
436 } while(FindNextFile(hFind
, &w32fd
));
444 dir
->down
= first_entry
;
449 static Entry
* find_entry_win(Entry
* dir
, LPCTSTR name
)
453 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
455 LPCTSTR q
= entry
->data
.cFileName
;
458 if (!*p
|| *p
==TEXT('\\') || *p
==TEXT('/'))
460 } while(tolower(*p
++) == tolower(*q
++));
463 q
= entry
->data
.cAlternateFileName
;
466 if (!*p
|| *p
==TEXT('\\') || *p
==TEXT('/'))
468 } while(tolower(*p
++) == tolower(*q
++));
475 static Entry
* read_tree_win(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
477 TCHAR buffer
[MAX_PATH
];
478 Entry
* entry
= &root
->entry
;
482 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
484 #ifndef _NO_EXTENSIONS
485 entry
->etype
= ET_WINDOWS
;
489 while(*s
&& *s
!=TEXT('\\') && *s
!=TEXT('/'))
492 while(*s
==TEXT('\\') || *s
==TEXT('/'))
498 read_directory(entry
, buffer
, sortOrder
, hwnd
);
501 entry
->expanded
= TRUE
;
506 entry
= find_entry_win(entry
, s
);
509 SetCursor(old_cursor
);
515 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
517 static BOOL
time_to_filetime(const time_t* t
, FILETIME
* ftime
)
519 struct tm
* tm
= gmtime(t
);
525 stime
.wYear
= tm
->tm_year
+1900;
526 stime
.wMonth
= tm
->tm_mon
+1;
527 /* stime.wDayOfWeek */
528 stime
.wDay
= tm
->tm_mday
;
529 stime
.wHour
= tm
->tm_hour
;
530 stime
.wMinute
= tm
->tm_min
;
531 stime
.wSecond
= tm
->tm_sec
;
533 return SystemTimeToFileTime(&stime
, ftime
);
536 static void read_directory_unix(Entry
* dir
, LPCTSTR path
)
538 Entry
* first_entry
= NULL
;
543 int level
= dir
->level
+ 1;
545 char cpath
[MAX_PATH
];
547 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, cpath
, MAX_PATH
, NULL
, NULL
);
549 const char* cpath
= path
;
552 pdir
= opendir(cpath
);
557 char buffer
[MAX_PATH
], *p
;
560 for(p
=buffer
,s
=cpath
; *s
; )
563 if (p
==buffer
|| p
[-1]!='/')
566 while((ent
=readdir(pdir
))) {
567 entry
= alloc_entry();
575 entry
->etype
= ET_UNIX
;
577 strcpy(p
, ent
->d_name
);
579 MultiByteToWideChar(CP_UNIXCP
, 0, p
, -1, entry
->data
.cFileName
, MAX_PATH
);
581 lstrcpy(entry
->data
.cFileName
, p
);
584 if (!stat(buffer
, &st
)) {
585 entry
->data
.dwFileAttributes
= p
[0]=='.'? FILE_ATTRIBUTE_HIDDEN
: 0;
587 if (S_ISDIR(st
.st_mode
))
588 entry
->data
.dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
590 entry
->data
.nFileSizeLow
= st
.st_size
& 0xFFFFFFFF;
591 entry
->data
.nFileSizeHigh
= st
.st_size
>> 32;
593 memset(&entry
->data
.ftCreationTime
, 0, sizeof(FILETIME
));
594 time_to_filetime(&st
.st_atime
, &entry
->data
.ftLastAccessTime
);
595 time_to_filetime(&st
.st_mtime
, &entry
->data
.ftLastWriteTime
);
597 entry
->bhfi
.nFileIndexLow
= ent
->d_ino
;
598 entry
->bhfi
.nFileIndexHigh
= 0;
600 entry
->bhfi
.nNumberOfLinks
= st
.st_nlink
;
602 entry
->bhfi_valid
= TRUE
;
604 entry
->data
.nFileSizeLow
= 0;
605 entry
->data
.nFileSizeHigh
= 0;
606 entry
->bhfi_valid
= FALSE
;
611 entry
->expanded
= FALSE
;
612 entry
->scanned
= FALSE
;
613 entry
->level
= level
;
624 dir
->down
= first_entry
;
628 static Entry
* find_entry_unix(Entry
* dir
, LPCTSTR name
)
632 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
634 LPCTSTR q
= entry
->data
.cFileName
;
637 if (!*p
|| *p
==TEXT('/'))
639 } while(*p
++ == *q
++);
645 static Entry
* read_tree_unix(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
647 TCHAR buffer
[MAX_PATH
];
648 Entry
* entry
= &root
->entry
;
652 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
654 entry
->etype
= ET_UNIX
;
657 while(*s
&& *s
!=TEXT('/'))
660 while(*s
== TEXT('/'))
666 read_directory(entry
, buffer
, sortOrder
, hwnd
);
669 entry
->expanded
= TRUE
;
674 entry
= find_entry_unix(entry
, s
);
677 SetCursor(old_cursor
);
682 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
685 #ifdef _SHELL_FOLDERS
688 #define get_strret get_strretW
689 #define path_from_pidl path_from_pidlW
691 #define get_strret get_strretA
692 #define path_from_pidl path_from_pidlA
696 static void free_strret(STRRET
* str
)
698 if (str
->uType
== STRRET_WSTR
)
699 IMalloc_Free(Globals
.iMalloc
, str
->UNION_MEMBER(pOleStr
));
705 static LPSTR
strcpyn(LPSTR dest
, LPCSTR source
, size_t count
)
710 for(s
=source
; count
&&(*d
++=*s
++); )
716 static void get_strretA(STRRET
* str
, const SHITEMID
* shiid
, LPSTR buffer
, int len
)
720 WideCharToMultiByte(CP_ACP
, 0, str
->UNION_MEMBER(pOleStr
), -1, buffer
, len
, NULL
, NULL
);
724 strcpyn(buffer
, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), len
);
728 strcpyn(buffer
, str
->UNION_MEMBER(cStr
), len
);
732 static HRESULT
path_from_pidlA(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPSTR buffer
, int len
)
736 /* SHGDN_FORPARSING: get full path of id list */
737 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, SHGDN_FORPARSING
, &str
);
740 get_strretA(&str
, &pidl
->mkid
, buffer
, len
);
750 static LPWSTR
wcscpyn(LPWSTR dest
, LPCWSTR source
, size_t count
)
755 for(s
=source
; count
&&(*d
++=*s
++); )
761 static void get_strretW(STRRET
* str
, const SHITEMID
* shiid
, LPWSTR buffer
, int len
)
765 wcscpyn(buffer
, str
->UNION_MEMBER(pOleStr
), len
);
769 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), -1, buffer
, len
);
773 MultiByteToWideChar(CP_ACP
, 0, str
->UNION_MEMBER(cStr
), -1, buffer
, len
);
778 static HRESULT
name_from_pidl(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPTSTR buffer
, int len
, SHGDNF flags
)
782 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, flags
, &str
);
785 get_strret(&str
, &pidl
->mkid
, buffer
, len
);
794 static HRESULT
path_from_pidlW(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPWSTR buffer
, int len
)
798 /* SHGDN_FORPARSING: get full path of id list */
799 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, SHGDN_FORPARSING
, &str
);
802 get_strretW(&str
, &pidl
->mkid
, buffer
, len
);
811 /* create an item id list from a file system path */
813 static LPITEMIDLIST
get_path_pidl(LPTSTR path
, HWND hwnd
)
820 LPWSTR buffer
= path
;
822 WCHAR buffer
[MAX_PATH
];
823 MultiByteToWideChar(CP_ACP
, 0, path
, -1, buffer
, MAX_PATH
);
826 hr
= IShellFolder_ParseDisplayName(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
834 /* convert an item id list from relative to absolute (=relative to the desktop) format */
836 static LPITEMIDLIST
get_to_absolute_pidl(Entry
* entry
, HWND hwnd
)
838 if (entry
->up
&& entry
->up
->etype
==ET_SHELL
) {
839 IShellFolder
* folder
= entry
->up
->folder
;
840 WCHAR buffer
[MAX_PATH
];
842 HRESULT hr
= path_from_pidlW(folder
, entry
->pidl
, buffer
, MAX_PATH
);
848 hr
= IShellFolder_ParseDisplayName(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
853 } else if (entry
->etype
== ET_WINDOWS
) {
854 TCHAR path
[MAX_PATH
];
856 get_path(entry
, path
);
858 return get_path_pidl(path
, hwnd
);
859 } else if (entry
->pidl
)
860 return ILClone(entry
->pidl
);
866 static HICON
extract_icon(IShellFolder
* folder
, LPCITEMIDLIST pidl
)
868 IExtractIcon
* pExtract
;
870 if (SUCCEEDED(IShellFolder_GetUIObjectOf(folder
, 0, 1, (LPCITEMIDLIST
*)&pidl
, &IID_IExtractIcon
, 0, (LPVOID
*)&pExtract
))) {
871 TCHAR path
[_MAX_PATH
];
876 if (SUCCEEDED(IExtractIconW_GetIconLocation(pExtract
, GIL_FORSHELL
, path
, _MAX_PATH
, &idx
, &flags
))) {
877 if (!(flags
& GIL_NOTFILENAME
)) {
879 idx
= 0; /* special case for some control panel applications */
881 if ((int)ExtractIconEx(path
, idx
, 0, &hicon
, 1) > 0)
882 flags
&= ~GIL_DONTCACHE
;
884 HICON hIconLarge
= 0;
886 HRESULT hr
= IExtractIconW_Extract(pExtract
, path
, idx
, &hIconLarge
, &hicon
, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON
)));
889 DestroyIcon(hIconLarge
);
900 static Entry
* find_entry_shell(Entry
* dir
, LPCITEMIDLIST pidl
)
904 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
905 if (entry
->pidl
->mkid
.cb
== pidl
->mkid
.cb
&&
906 !memcmp(entry
->pidl
, pidl
, entry
->pidl
->mkid
.cb
))
913 static Entry
* read_tree_shell(Root
* root
, LPITEMIDLIST pidl
, SORT_ORDER sortOrder
, HWND hwnd
)
915 Entry
* entry
= &root
->entry
;
917 LPITEMIDLIST next_pidl
= pidl
;
918 IShellFolder
* folder
;
919 IShellFolder
* child
= NULL
;
922 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
924 #ifndef _NO_EXTENSIONS
925 entry
->etype
= ET_SHELL
;
928 folder
= Globals
.iDesktop
;
931 entry
->pidl
= next_pidl
;
932 entry
->folder
= folder
;
937 /* copy first element of item idlist */
938 next_pidl
= IMalloc_Alloc(Globals
.iMalloc
, pidl
->mkid
.cb
+sizeof(USHORT
));
939 memcpy(next_pidl
, pidl
, pidl
->mkid
.cb
);
940 ((LPITEMIDLIST
)((LPBYTE
)next_pidl
+pidl
->mkid
.cb
))->mkid
.cb
= 0;
942 hr
= IShellFolder_BindToObject(folder
, next_pidl
, 0, &IID_IShellFolder
, (void**)&child
);
946 read_directory(entry
, NULL
, sortOrder
, hwnd
);
949 entry
->expanded
= TRUE
;
951 next
= find_entry_shell(entry
, next_pidl
);
958 /* go to next element */
959 pidl
= (LPITEMIDLIST
) ((LPBYTE
)pidl
+pidl
->mkid
.cb
);
962 SetCursor(old_cursor
);
968 static void fill_w32fdata_shell(IShellFolder
* folder
, LPCITEMIDLIST pidl
, SFGAOF attribs
, WIN32_FIND_DATA
* w32fdata
)
970 if (!(attribs
& SFGAO_FILESYSTEM
) ||
971 FAILED(SHGetDataFromIDList(folder
, pidl
, SHGDFIL_FINDDATA
, w32fdata
, sizeof(WIN32_FIND_DATA
)))) {
972 WIN32_FILE_ATTRIBUTE_DATA fad
;
973 IDataObject
* pDataObj
;
975 STGMEDIUM medium
= {0, {0}, 0};
976 FORMATETC fmt
= {Globals
.cfStrFName
, 0, DVASPECT_CONTENT
, -1, TYMED_HGLOBAL
};
978 HRESULT hr
= IShellFolder_GetUIObjectOf(folder
, 0, 1, &pidl
, &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
981 hr
= IDataObject_GetData(pDataObj
, &fmt
, &medium
);
983 IDataObject_Release(pDataObj
);
986 LPCTSTR path
= (LPCTSTR
)GlobalLock(medium
.UNION_MEMBER(hGlobal
));
987 UINT sem_org
= SetErrorMode(SEM_FAILCRITICALERRORS
);
989 if (GetFileAttributesEx(path
, GetFileExInfoStandard
, &fad
)) {
990 w32fdata
->dwFileAttributes
= fad
.dwFileAttributes
;
991 w32fdata
->ftCreationTime
= fad
.ftCreationTime
;
992 w32fdata
->ftLastAccessTime
= fad
.ftLastAccessTime
;
993 w32fdata
->ftLastWriteTime
= fad
.ftLastWriteTime
;
995 if (!(fad
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)) {
996 w32fdata
->nFileSizeLow
= fad
.nFileSizeLow
;
997 w32fdata
->nFileSizeHigh
= fad
.nFileSizeHigh
;
1001 SetErrorMode(sem_org
);
1003 GlobalUnlock(medium
.UNION_MEMBER(hGlobal
));
1004 GlobalFree(medium
.UNION_MEMBER(hGlobal
));
1009 if (attribs
& (SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
))
1010 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
1012 if (attribs
& SFGAO_READONLY
)
1013 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_READONLY
;
1015 if (attribs
& SFGAO_COMPRESSED
)
1016 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_COMPRESSED
;
1020 static void read_directory_shell(Entry
* dir
, HWND hwnd
)
1022 IShellFolder
* folder
= dir
->folder
;
1023 int level
= dir
->level
+ 1;
1026 IShellFolder
* child
;
1027 IEnumIDList
* idlist
;
1029 Entry
* first_entry
= NULL
;
1036 hr
= IShellFolder_EnumObjects(folder
, hwnd
, SHCONTF_FOLDERS
|SHCONTF_NONFOLDERS
|SHCONTF_INCLUDEHIDDEN
|SHCONTF_SHAREABLE
|SHCONTF_STORAGE
, &idlist
);
1038 if (SUCCEEDED(hr
)) {
1040 #define FETCH_ITEM_COUNT 32
1041 LPITEMIDLIST pidls
[FETCH_ITEM_COUNT
];
1046 memset(pidls
, 0, sizeof(pidls
));
1048 hr
= IEnumIDList_Next(idlist
, FETCH_ITEM_COUNT
, pidls
, &cnt
);
1055 for(n
=0; n
<cnt
; ++n
) {
1056 entry
= alloc_entry();
1059 first_entry
= entry
;
1064 memset(&entry
->data
, 0, sizeof(WIN32_FIND_DATA
));
1065 entry
->bhfi_valid
= FALSE
;
1067 attribs
= ~SFGAO_FILESYSTEM
; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
1069 hr
= IShellFolder_GetAttributesOf(folder
, 1, (LPCITEMIDLIST
*)&pidls
[n
], &attribs
);
1071 if (SUCCEEDED(hr
)) {
1072 if (attribs
!= (SFGAOF
)~SFGAO_FILESYSTEM
) {
1073 fill_w32fdata_shell(folder
, pidls
[n
], attribs
, &entry
->data
);
1075 entry
->bhfi_valid
= TRUE
;
1081 entry
->pidl
= pidls
[n
];
1083 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1084 hr
= IShellFolder_BindToObject(folder
, pidls
[n
], 0, &IID_IShellFolder
, (void**)&child
);
1087 entry
->folder
= child
;
1089 entry
->folder
= NULL
;
1092 entry
->folder
= NULL
;
1094 if (!entry
->data
.cFileName
[0])
1095 /*hr = */name_from_pidl(folder
, pidls
[n
], entry
->data
.cFileName
, MAX_PATH
, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1097 /* get display icons for files and virtual objects */
1098 if (!(entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ||
1099 !(attribs
& SFGAO_FILESYSTEM
)) {
1100 entry
->hicon
= extract_icon(folder
, pidls
[n
]);
1103 entry
->hicon
= (HICON
)-1; /* don't try again later */
1108 entry
->expanded
= FALSE
;
1109 entry
->scanned
= FALSE
;
1110 entry
->level
= level
;
1112 #ifndef _NO_EXTENSIONS
1113 entry
->etype
= ET_SHELL
;
1114 entry
->bhfi_valid
= FALSE
;
1121 IEnumIDList_Release(idlist
);
1127 dir
->down
= first_entry
;
1128 dir
->scanned
= TRUE
;
1131 #endif /* _SHELL_FOLDERS */
1134 /* sort order for different directory/file types */
1143 /* distinguish between ".", ".." and any other directory names */
1144 static int TypeOrderFromDirname(LPCTSTR name
)
1146 if (name
[0] == '.') {
1147 if (name
[1] == '\0')
1148 return TO_DOT
; /* "." */
1150 if (name
[1]=='.' && name
[2]=='\0')
1151 return TO_DOTDOT
; /* ".." */
1154 return TO_OTHER_DIR
; /* anything else */
1157 /* directories first... */
1158 static int compareType(const WIN32_FIND_DATA
* fd1
, const WIN32_FIND_DATA
* fd2
)
1160 int order1
= fd1
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1161 int order2
= fd2
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1163 /* Handle "." and ".." as special case and move them at the very first beginning. */
1164 if (order1
==TO_DIR
&& order2
==TO_DIR
) {
1165 order1
= TypeOrderFromDirname(fd1
->cFileName
);
1166 order2
= TypeOrderFromDirname(fd2
->cFileName
);
1169 return order2
==order1
? 0: order1
<order2
? -1: 1;
1173 static int compareName(const void* arg1
, const void* arg2
)
1175 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1176 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1178 int cmp
= compareType(fd1
, fd2
);
1182 return lstrcmpi(fd1
->cFileName
, fd2
->cFileName
);
1185 static int compareExt(const void* arg1
, const void* arg2
)
1187 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1188 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1189 const TCHAR
*name1
, *name2
, *ext1
, *ext2
;
1191 int cmp
= compareType(fd1
, fd2
);
1195 name1
= fd1
->cFileName
;
1196 name2
= fd2
->cFileName
;
1198 ext1
= _tcsrchr(name1
, TEXT('.'));
1199 ext2
= _tcsrchr(name2
, TEXT('.'));
1211 cmp
= lstrcmpi(ext1
, ext2
);
1215 return lstrcmpi(name1
, name2
);
1218 static int compareSize(const void* arg1
, const void* arg2
)
1220 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1221 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1223 int cmp
= compareType(fd1
, fd2
);
1227 cmp
= fd2
->nFileSizeHigh
- fd1
->nFileSizeHigh
;
1234 cmp
= fd2
->nFileSizeLow
- fd1
->nFileSizeLow
;
1236 return cmp
<0? -1: cmp
>0? 1: 0;
1239 static int compareDate(const void* arg1
, const void* arg2
)
1241 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1242 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1244 int cmp
= compareType(fd1
, fd2
);
1248 return CompareFileTime(&fd2
->ftLastWriteTime
, &fd1
->ftLastWriteTime
);
1252 static int (*sortFunctions
[])(const void* arg1
, const void* arg2
) = {
1253 compareName
, /* SORT_NAME */
1254 compareExt
, /* SORT_EXT */
1255 compareSize
, /* SORT_SIZE */
1256 compareDate
/* SORT_DATE */
1260 static void SortDirectory(Entry
* dir
, SORT_ORDER sortOrder
)
1262 Entry
* entry
= dir
->down
;
1267 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1271 array
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(Entry
*));
1274 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1277 /* call qsort with the appropriate compare function */
1278 qsort(array
, len
, sizeof(array
[0]), sortFunctions
[sortOrder
]);
1280 dir
->down
= array
[0];
1282 for(p
=array
; --len
; p
++)
1287 HeapFree(GetProcessHeap(), 0, array
);
1292 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
1294 TCHAR buffer
[MAX_PATH
];
1299 #ifdef _SHELL_FOLDERS
1300 if (dir
->etype
== ET_SHELL
)
1302 read_directory_shell(dir
, hwnd
);
1304 if (Globals
.prescan_node
) {
1313 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1314 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1315 read_directory_shell(entry
, hwnd
);
1316 SortDirectory(entry
, sortOrder
);
1322 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1323 if (dir
->etype
== ET_UNIX
)
1325 read_directory_unix(dir
, path
);
1327 if (Globals
.prescan_node
) {
1336 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1337 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1338 lstrcpy(d
, entry
->data
.cFileName
);
1339 read_directory_unix(entry
, buffer
);
1340 SortDirectory(entry
, sortOrder
);
1347 read_directory_win(dir
, path
);
1349 if (Globals
.prescan_node
) {
1358 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1359 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1360 lstrcpy(d
, entry
->data
.cFileName
);
1361 read_directory_win(entry
, buffer
);
1362 SortDirectory(entry
, sortOrder
);
1367 SortDirectory(dir
, sortOrder
);
1371 static Entry
* read_tree(Root
* root
, LPCTSTR path
, LPITEMIDLIST pidl
, LPTSTR drv
, SORT_ORDER sortOrder
, HWND hwnd
)
1373 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1374 static const TCHAR sSlash
[] = {'/', '\0'};
1376 static const TCHAR sBackslash
[] = {'\\', '\0'};
1378 #ifdef _SHELL_FOLDERS
1381 /* read shell namespace tree */
1382 root
->drive_type
= DRIVE_UNKNOWN
;
1385 load_string(root
->volname
, IDS_DESKTOP
);
1387 load_string(root
->fs
, IDS_SHELL
);
1389 return read_tree_shell(root
, pidl
, sortOrder
, hwnd
);
1393 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1396 /* read unix file system tree */
1397 root
->drive_type
= GetDriveType(path
);
1399 lstrcat(drv
, sSlash
);
1400 load_string(root
->volname
, IDS_ROOT_FS
);
1402 load_string(root
->fs
, IDS_UNIXFS
);
1404 lstrcpy(root
->path
, sSlash
);
1406 return read_tree_unix(root
, path
, sortOrder
, hwnd
);
1410 /* read WIN32 file system tree */
1411 root
->drive_type
= GetDriveType(path
);
1413 lstrcat(drv
, sBackslash
);
1414 GetVolumeInformation(drv
, root
->volname
, _MAX_FNAME
, 0, 0, &root
->fs_flags
, root
->fs
, _MAX_DIR
);
1416 lstrcpy(root
->path
, drv
);
1418 return read_tree_win(root
, path
, sortOrder
, hwnd
);
1422 /* flags to filter different file types */
1424 TF_DIRECTORIES
= 0x01,
1426 TF_DOCUMENTS
= 0x04,
1433 static ChildWnd
* alloc_child_window(LPCTSTR path
, LPITEMIDLIST pidl
, HWND hwnd
)
1435 TCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
1436 TCHAR dir_path
[MAX_PATH
];
1437 TCHAR b1
[BUFFER_LEN
];
1438 static const TCHAR sAsterics
[] = {'*', '\0'};
1440 ChildWnd
* child
= (ChildWnd
*) malloc(sizeof(ChildWnd
));
1441 Root
* root
= &child
->root
;
1444 memset(child
, 0, sizeof(ChildWnd
));
1446 child
->left
.treePane
= TRUE
;
1447 child
->left
.visible_cols
= 0;
1449 child
->right
.treePane
= FALSE
;
1450 #ifndef _NO_EXTENSIONS
1451 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_INDEX
|COL_LINKS
;
1453 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
;
1456 child
->pos
.length
= sizeof(WINDOWPLACEMENT
);
1457 child
->pos
.flags
= 0;
1458 child
->pos
.showCmd
= SW_SHOWNORMAL
;
1459 child
->pos
.rcNormalPosition
.left
= CW_USEDEFAULT
;
1460 child
->pos
.rcNormalPosition
.top
= CW_USEDEFAULT
;
1461 child
->pos
.rcNormalPosition
.right
= CW_USEDEFAULT
;
1462 child
->pos
.rcNormalPosition
.bottom
= CW_USEDEFAULT
;
1464 child
->focus_pane
= 0;
1465 child
->split_pos
= DEFAULT_SPLIT_POS
;
1466 child
->sortOrder
= SORT_NAME
;
1467 child
->header_wdths_ok
= FALSE
;
1471 lstrcpy(child
->path
, path
);
1473 _tsplitpath(path
, drv
, dir
, name
, ext
);
1476 lstrcpy(child
->filter_pattern
, sAsterics
);
1477 child
->filter_flags
= TF_ALL
;
1479 root
->entry
.level
= 0;
1481 lstrcpy(dir_path
, drv
);
1482 lstrcat(dir_path
, dir
);
1483 entry
= read_tree(root
, dir_path
, pidl
, drv
, child
->sortOrder
, hwnd
);
1485 #ifdef _SHELL_FOLDERS
1486 if (root
->entry
.etype
== ET_SHELL
)
1487 load_string(root
->entry
.data
.cFileName
, IDS_DESKTOP
);
1490 wsprintf(root
->entry
.data
.cFileName
, RS(b1
,IDS_TITLEFMT
), drv
, root
->fs
);
1492 root
->entry
.data
.dwFileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1494 child
->left
.root
= &root
->entry
;
1495 child
->right
.root
= NULL
;
1497 set_curdir(child
, entry
, 0, hwnd
);
1503 /* free all memory associated with a child window */
1504 static void free_child_window(ChildWnd
* child
)
1506 free_entries(&child
->root
.entry
);
1511 /* get full path of specified directory entry */
1512 static void get_path(Entry
* dir
, PTSTR path
)
1518 #ifdef _SHELL_FOLDERS
1519 if (dir
->etype
== ET_SHELL
)
1524 path
[0] = TEXT('\0');
1529 hr
= IShellFolder_GetAttributesOf(dir
->folder
, 1, (LPCITEMIDLIST
*)&dir
->pidl
, &attribs
);
1531 if (SUCCEEDED(hr
) && (attribs
&SFGAO_FILESYSTEM
)) {
1532 IShellFolder
* parent
= dir
->up
? dir
->up
->folder
: Globals
.iDesktop
;
1534 hr
= path_from_pidl(parent
, dir
->pidl
, path
, MAX_PATH
);
1540 for(entry
=dir
; entry
; level
++) {
1546 name
= entry
->data
.cFileName
;
1549 for(l
=0; *s
&& *s
!=TEXT('/') && *s
!=TEXT('\\'); s
++)
1555 memmove(path
+l
+1, path
, len
*sizeof(TCHAR
));
1556 memcpy(path
+1, name
, l
*sizeof(TCHAR
));
1559 #ifndef _NO_EXTENSIONS
1560 if (entry
->etype
== ET_UNIX
)
1561 path
[0] = TEXT('/');
1564 path
[0] = TEXT('\\');
1569 memmove(path
+l
, path
, len
*sizeof(TCHAR
));
1570 memcpy(path
, name
, l
*sizeof(TCHAR
));
1577 #ifndef _NO_EXTENSIONS
1578 if (entry
->etype
== ET_UNIX
)
1579 path
[len
++] = TEXT('/');
1582 path
[len
++] = TEXT('\\');
1585 path
[len
] = TEXT('\0');
1589 static windowOptions
load_registry_settings(void)
1596 RegOpenKeyEx( HKEY_CURRENT_USER
, registry_key
,
1597 0, KEY_QUERY_VALUE
, &hKey
);
1599 size
= sizeof(DWORD
);
1601 if( RegQueryValueEx( hKey
, reg_start_x
, NULL
, &type
,
1602 (LPBYTE
) &opts
.start_x
, &size
) != ERROR_SUCCESS
)
1603 opts
.start_x
= CW_USEDEFAULT
;
1605 if( RegQueryValueEx( hKey
, reg_start_y
, NULL
, &type
,
1606 (LPBYTE
) &opts
.start_y
, &size
) != ERROR_SUCCESS
)
1607 opts
.start_y
= CW_USEDEFAULT
;
1609 if( RegQueryValueEx( hKey
, reg_width
, NULL
, &type
,
1610 (LPBYTE
) &opts
.width
, &size
) != ERROR_SUCCESS
)
1611 opts
.width
= CW_USEDEFAULT
;
1613 if( RegQueryValueEx( hKey
, reg_height
, NULL
, &type
,
1614 (LPBYTE
) &opts
.height
, &size
) != ERROR_SUCCESS
)
1615 opts
.height
= CW_USEDEFAULT
;
1617 RegCloseKey( hKey
);
1622 static void save_registry_settings(void)
1628 wi
.cbSize
= sizeof( WINDOWINFO
);
1629 GetWindowInfo(Globals
.hMainWnd
, &wi
);
1630 width
= wi
.rcWindow
.right
- wi
.rcWindow
.left
;
1631 height
= wi
.rcWindow
.bottom
- wi
.rcWindow
.top
;
1633 if ( RegOpenKeyEx( HKEY_CURRENT_USER
, registry_key
,
1634 0, KEY_SET_VALUE
, &hKey
) != ERROR_SUCCESS
)
1636 /* Unable to save registry settings - try to create key */
1637 if ( RegCreateKeyEx( HKEY_CURRENT_USER
, registry_key
,
1638 0, NULL
, REG_OPTION_NON_VOLATILE
,
1639 KEY_SET_VALUE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
1641 /* FIXME: Cannot create key */
1645 /* Save all of the settings */
1646 RegSetValueEx( hKey
, reg_start_x
, 0, REG_DWORD
,
1647 (LPBYTE
) &wi
.rcWindow
.left
, sizeof(DWORD
) );
1648 RegSetValueEx( hKey
, reg_start_y
, 0, REG_DWORD
,
1649 (LPBYTE
) &wi
.rcWindow
.top
, sizeof(DWORD
) );
1650 RegSetValueEx( hKey
, reg_width
, 0, REG_DWORD
,
1651 (LPBYTE
) &width
, sizeof(DWORD
) );
1652 RegSetValueEx( hKey
, reg_height
, 0, REG_DWORD
,
1653 (LPBYTE
) &height
, sizeof(DWORD
) );
1655 /* TODO: Save more settings here (List vs. Detailed View, etc.) */
1656 RegCloseKey( hKey
);
1659 static void resize_frame_rect(HWND hwnd
, PRECT prect
)
1664 if (IsWindowVisible(Globals
.htoolbar
)) {
1665 SendMessage(Globals
.htoolbar
, WM_SIZE
, 0, 0);
1666 GetClientRect(Globals
.htoolbar
, &rt
);
1667 prect
->top
= rt
.bottom
+3;
1668 prect
->bottom
-= rt
.bottom
+3;
1671 if (IsWindowVisible(Globals
.hdrivebar
)) {
1672 SendMessage(Globals
.hdrivebar
, WM_SIZE
, 0, 0);
1673 GetClientRect(Globals
.hdrivebar
, &rt
);
1674 new_top
= --prect
->top
+ rt
.bottom
+3;
1675 MoveWindow(Globals
.hdrivebar
, 0, prect
->top
, rt
.right
, new_top
, TRUE
);
1676 prect
->top
= new_top
;
1677 prect
->bottom
-= rt
.bottom
+2;
1680 if (IsWindowVisible(Globals
.hstatusbar
)) {
1681 int parts
[] = {300, 500};
1683 SendMessage(Globals
.hstatusbar
, WM_SIZE
, 0, 0);
1684 SendMessage(Globals
.hstatusbar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
1685 GetClientRect(Globals
.hstatusbar
, &rt
);
1686 prect
->bottom
-= rt
.bottom
;
1689 MoveWindow(Globals
.hmdiclient
, prect
->left
-1,prect
->top
-1,prect
->right
+2,prect
->bottom
+1, TRUE
);
1692 static void resize_frame(HWND hwnd
, int cx
, int cy
)
1701 resize_frame_rect(hwnd
, &rect
);
1704 static void resize_frame_client(HWND hwnd
)
1708 GetClientRect(hwnd
, &rect
);
1710 resize_frame_rect(hwnd
, &rect
);
1714 static HHOOK hcbthook
;
1715 static ChildWnd
* newchild
= NULL
;
1717 static LRESULT CALLBACK
CBTProc(int code
, WPARAM wparam
, LPARAM lparam
)
1719 if (code
==HCBT_CREATEWND
&& newchild
) {
1720 ChildWnd
* child
= newchild
;
1723 child
->hwnd
= (HWND
) wparam
;
1724 SetWindowLongPtr(child
->hwnd
, GWLP_USERDATA
, (LPARAM
)child
);
1727 return CallNextHookEx(hcbthook
, code
, wparam
, lparam
);
1730 static HWND
create_child_window(ChildWnd
* child
)
1732 MDICREATESTRUCT mcs
;
1735 mcs
.szClass
= sWINEFILETREE
;
1736 mcs
.szTitle
= (LPTSTR
)child
->path
;
1737 mcs
.hOwner
= Globals
.hInstance
;
1738 mcs
.x
= child
->pos
.rcNormalPosition
.left
;
1739 mcs
.y
= child
->pos
.rcNormalPosition
.top
;
1740 mcs
.cx
= child
->pos
.rcNormalPosition
.right
-child
->pos
.rcNormalPosition
.left
;
1741 mcs
.cy
= child
->pos
.rcNormalPosition
.bottom
-child
->pos
.rcNormalPosition
.top
;
1745 hcbthook
= SetWindowsHookEx(WH_CBT
, CBTProc
, 0, GetCurrentThreadId());
1748 child
->hwnd
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDICREATE
, 0, (LPARAM
)&mcs
);
1750 UnhookWindowsHookEx(hcbthook
);
1754 UnhookWindowsHookEx(hcbthook
);
1756 SendMessage(child
->left
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1757 SendMessage(child
->right
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1759 idx
= SendMessage(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)child
->left
.cur
);
1760 SendMessage(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
1766 struct ExecuteDialog
{
1767 TCHAR cmd
[MAX_PATH
];
1771 static INT_PTR CALLBACK
ExecuteDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1773 static struct ExecuteDialog
* dlg
;
1777 dlg
= (struct ExecuteDialog
*) lparam
;
1781 int id
= (int)wparam
;
1784 GetWindowText(GetDlgItem(hwnd
, 201), dlg
->cmd
, MAX_PATH
);
1785 dlg
->cmdshow
= get_check(hwnd
,214) ? SW_SHOWMINIMIZED
: SW_SHOWNORMAL
;
1786 EndDialog(hwnd
, id
);
1787 } else if (id
== IDCANCEL
)
1788 EndDialog(hwnd
, id
);
1797 static INT_PTR CALLBACK
DestinationDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1799 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1803 SetWindowLongPtr(hwnd
, GWLP_USERDATA
, lparam
);
1804 SetWindowText(GetDlgItem(hwnd
, 201), (LPCTSTR
)lparam
);
1808 int id
= (int)wparam
;
1812 LPTSTR dest
= (LPTSTR
) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
1813 GetWindowText(GetDlgItem(hwnd
, 201), dest
, MAX_PATH
);
1814 EndDialog(hwnd
, id
);
1818 EndDialog(hwnd
, id
);
1822 MessageBox(hwnd
, RS(b1
,IDS_NO_IMPL
), RS(b2
,IDS_WINEFILE
), MB_OK
);
1834 struct FilterDialog
{
1835 TCHAR pattern
[MAX_PATH
];
1839 static INT_PTR CALLBACK
FilterDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1841 static struct FilterDialog
* dlg
;
1845 dlg
= (struct FilterDialog
*) lparam
;
1846 SetWindowText(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
);
1847 set_check(hwnd
, IDC_VIEW_TYPE_DIRECTORIES
, dlg
->flags
&TF_DIRECTORIES
);
1848 set_check(hwnd
, IDC_VIEW_TYPE_PROGRAMS
, dlg
->flags
&TF_PROGRAMS
);
1849 set_check(hwnd
, IDC_VIEW_TYPE_DOCUMENTS
, dlg
->flags
&TF_DOCUMENTS
);
1850 set_check(hwnd
, IDC_VIEW_TYPE_OTHERS
, dlg
->flags
&TF_OTHERS
);
1851 set_check(hwnd
, IDC_VIEW_TYPE_HIDDEN
, dlg
->flags
&TF_HIDDEN
);
1855 int id
= (int)wparam
;
1860 GetWindowText(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
, MAX_PATH
);
1862 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_DIRECTORIES
) ? TF_DIRECTORIES
: 0;
1863 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_PROGRAMS
) ? TF_PROGRAMS
: 0;
1864 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_DOCUMENTS
) ? TF_DOCUMENTS
: 0;
1865 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_OTHERS
) ? TF_OTHERS
: 0;
1866 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_HIDDEN
) ? TF_HIDDEN
: 0;
1870 EndDialog(hwnd
, id
);
1871 } else if (id
== IDCANCEL
)
1872 EndDialog(hwnd
, id
);
1881 struct PropertiesDialog
{
1882 TCHAR path
[MAX_PATH
];
1887 /* Structure used to store enumerated languages and code pages. */
1888 struct LANGANDCODEPAGE
{
1893 static LPCSTR InfoStrings
[] = {
1909 static void PropDlg_DisplayValue(HWND hlbox
, HWND hedit
)
1911 int idx
= SendMessage(hlbox
, LB_GETCURSEL
, 0, 0);
1913 if (idx
!= LB_ERR
) {
1914 LPCTSTR pValue
= (LPCTSTR
) SendMessage(hlbox
, LB_GETITEMDATA
, idx
, 0);
1917 SetWindowText(hedit
, pValue
);
1921 static void CheckForFileInfo(struct PropertiesDialog
* dlg
, HWND hwnd
, LPCTSTR strFilename
)
1923 static TCHAR sBackSlash
[] = {'\\','\0'};
1924 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'};
1925 static TCHAR sStringFileInfo
[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1926 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1927 DWORD dwVersionDataLen
= GetFileVersionInfoSize(strFilename
, NULL
);
1929 if (dwVersionDataLen
) {
1930 dlg
->pVersionData
= malloc(dwVersionDataLen
);
1932 if (GetFileVersionInfo(strFilename
, 0, dwVersionDataLen
, dlg
->pVersionData
)) {
1936 if (VerQueryValue(dlg
->pVersionData
, sBackSlash
, &pVal
, &nValLen
)) {
1937 if (nValLen
== sizeof(VS_FIXEDFILEINFO
)) {
1938 VS_FIXEDFILEINFO
* pFixedFileInfo
= (VS_FIXEDFILEINFO
*)pVal
;
1939 char buffer
[BUFFER_LEN
];
1941 sprintf(buffer
, "%d.%d.%d.%d",
1942 HIWORD(pFixedFileInfo
->dwFileVersionMS
), LOWORD(pFixedFileInfo
->dwFileVersionMS
),
1943 HIWORD(pFixedFileInfo
->dwFileVersionLS
), LOWORD(pFixedFileInfo
->dwFileVersionLS
));
1945 SetDlgItemTextA(hwnd
, IDC_STATIC_PROP_VERSION
, buffer
);
1949 /* Read the list of languages and code pages. */
1950 if (VerQueryValue(dlg
->pVersionData
, sTranslation
, &pVal
, &nValLen
)) {
1951 struct LANGANDCODEPAGE
* pTranslate
= (struct LANGANDCODEPAGE
*)pVal
;
1952 struct LANGANDCODEPAGE
* pEnd
= (struct LANGANDCODEPAGE
*)((LPBYTE
)pVal
+nValLen
);
1954 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
1956 /* Read the file description for each language and code page. */
1957 for(; pTranslate
<pEnd
; ++pTranslate
) {
1960 for(p
=InfoStrings
; *p
; ++p
) {
1961 TCHAR subblock
[200];
1968 LPCSTR pInfoString
= *p
;
1970 MultiByteToWideChar(CP_ACP
, 0, pInfoString
, -1, infoStr
, 100);
1972 #define infoStr pInfoString
1974 wsprintf(subblock
, sStringFileInfo
, pTranslate
->wLanguage
, pTranslate
->wCodePage
, infoStr
);
1976 /* Retrieve file description for language and code page */
1977 if (VerQueryValue(dlg
->pVersionData
, subblock
, (PVOID
)&pTxt
, &nValLen
)) {
1978 int idx
= SendMessage(hlbox
, LB_ADDSTRING
, 0L, (LPARAM
)infoStr
);
1979 SendMessage(hlbox
, LB_SETITEMDATA
, idx
, (LPARAM
) pTxt
);
1984 SendMessage(hlbox
, LB_SETCURSEL
, 0, 0);
1986 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
1992 static INT_PTR CALLBACK
PropertiesDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1994 static struct PropertiesDialog
* dlg
;
1997 case WM_INITDIALOG
: {
1998 static const TCHAR sByteFmt
[] = {'%','s',' ','B','y','t','e','s','\0'};
1999 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2000 LPWIN32_FIND_DATA pWFD
;
2003 dlg
= (struct PropertiesDialog
*) lparam
;
2004 pWFD
= (LPWIN32_FIND_DATA
) &dlg
->entry
.data
;
2006 GetWindowText(hwnd
, b1
, MAX_PATH
);
2007 wsprintf(b2
, b1
, pWFD
->cFileName
);
2008 SetWindowText(hwnd
, b2
);
2010 format_date(&pWFD
->ftLastWriteTime
, b1
, COL_DATE
|COL_TIME
);
2011 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_LASTCHANGE
), b1
);
2013 size
= ((ULONGLONG
)pWFD
->nFileSizeHigh
<< 32) | pWFD
->nFileSizeLow
;
2014 _stprintf(b1
, sLongNumFmt
, size
);
2015 wsprintf(b2
, sByteFmt
, b1
);
2016 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_SIZE
), b2
);
2018 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_FILENAME
), pWFD
->cFileName
);
2019 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_PATH
), dlg
->path
);
2021 set_check(hwnd
, IDC_CHECK_READONLY
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_READONLY
);
2022 set_check(hwnd
, IDC_CHECK_ARCHIVE
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_ARCHIVE
);
2023 set_check(hwnd
, IDC_CHECK_COMPRESSED
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_COMPRESSED
);
2024 set_check(hwnd
, IDC_CHECK_HIDDEN
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_HIDDEN
);
2025 set_check(hwnd
, IDC_CHECK_SYSTEM
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_SYSTEM
);
2027 CheckForFileInfo(dlg
, hwnd
, dlg
->path
);
2031 int id
= (int)wparam
;
2033 switch(HIWORD(wparam
)) {
2034 case LBN_SELCHANGE
: {
2035 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
2036 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
2041 if (id
==IDOK
|| id
==IDCANCEL
)
2042 EndDialog(hwnd
, id
);
2048 free(dlg
->pVersionData
);
2049 dlg
->pVersionData
= NULL
;
2056 static void show_properties_dlg(Entry
* entry
, HWND hwnd
)
2058 struct PropertiesDialog dlg
;
2060 memset(&dlg
, 0, sizeof(struct PropertiesDialog
));
2061 get_path(entry
, dlg
.path
);
2062 memcpy(&dlg
.entry
, entry
, sizeof(Entry
));
2064 DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_DIALOG_PROPERTIES
), hwnd
, PropertiesDialogDlgProc
, (LPARAM
)&dlg
);
2068 #ifndef _NO_EXTENSIONS
2070 static struct FullScreenParameters
{
2080 static void frame_get_clientspace(HWND hwnd
, PRECT prect
)
2084 if (!IsIconic(hwnd
))
2085 GetClientRect(hwnd
, prect
);
2089 GetWindowPlacement(hwnd
, &wp
);
2091 prect
->left
= prect
->top
= 0;
2092 prect
->right
= wp
.rcNormalPosition
.right
-wp
.rcNormalPosition
.left
-
2093 2*(GetSystemMetrics(SM_CXSIZEFRAME
)+GetSystemMetrics(SM_CXEDGE
));
2094 prect
->bottom
= wp
.rcNormalPosition
.bottom
-wp
.rcNormalPosition
.top
-
2095 2*(GetSystemMetrics(SM_CYSIZEFRAME
)+GetSystemMetrics(SM_CYEDGE
))-
2096 GetSystemMetrics(SM_CYCAPTION
)-GetSystemMetrics(SM_CYMENUSIZE
);
2099 if (IsWindowVisible(Globals
.htoolbar
)) {
2100 GetClientRect(Globals
.htoolbar
, &rt
);
2101 prect
->top
+= rt
.bottom
+2;
2104 if (IsWindowVisible(Globals
.hdrivebar
)) {
2105 GetClientRect(Globals
.hdrivebar
, &rt
);
2106 prect
->top
+= rt
.bottom
+2;
2109 if (IsWindowVisible(Globals
.hstatusbar
)) {
2110 GetClientRect(Globals
.hstatusbar
, &rt
);
2111 prect
->bottom
-= rt
.bottom
;
2115 static BOOL
toggle_fullscreen(HWND hwnd
)
2119 if ((g_fullscreen
.mode
=!g_fullscreen
.mode
)) {
2120 GetWindowRect(hwnd
, &g_fullscreen
.orgPos
);
2121 g_fullscreen
.wasZoomed
= IsZoomed(hwnd
);
2123 Frame_CalcFrameClient(hwnd
, &rt
);
2124 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
2125 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
2127 rt
.left
= g_fullscreen
.orgPos
.left
-rt
.left
;
2128 rt
.top
= g_fullscreen
.orgPos
.top
-rt
.top
;
2129 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+g_fullscreen
.orgPos
.right
-rt
.right
;
2130 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+g_fullscreen
.orgPos
.bottom
-rt
.bottom
;
2132 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
2134 MoveWindow(hwnd
, g_fullscreen
.orgPos
.left
, g_fullscreen
.orgPos
.top
,
2135 g_fullscreen
.orgPos
.right
-g_fullscreen
.orgPos
.left
,
2136 g_fullscreen
.orgPos
.bottom
-g_fullscreen
.orgPos
.top
, TRUE
);
2138 if (g_fullscreen
.wasZoomed
)
2139 ShowWindow(hwnd
, WS_MAXIMIZE
);
2142 return g_fullscreen
.mode
;
2145 static void fullscreen_move(HWND hwnd
)
2148 GetWindowRect(hwnd
, &pos
);
2150 Frame_CalcFrameClient(hwnd
, &rt
);
2151 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
2152 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
2154 rt
.left
= pos
.left
-rt
.left
;
2155 rt
.top
= pos
.top
-rt
.top
;
2156 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+pos
.right
-rt
.right
;
2157 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+pos
.bottom
-rt
.bottom
;
2159 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
2165 static void toggle_child(HWND hwnd
, UINT cmd
, HWND hchild
)
2167 BOOL vis
= IsWindowVisible(hchild
);
2169 CheckMenuItem(Globals
.hMenuOptions
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
2171 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
2173 #ifndef _NO_EXTENSIONS
2174 if (g_fullscreen
.mode
)
2175 fullscreen_move(hwnd
);
2178 resize_frame_client(hwnd
);
2181 static BOOL
activate_drive_window(LPCTSTR path
)
2183 TCHAR drv1
[_MAX_DRIVE
], drv2
[_MAX_DRIVE
];
2186 _tsplitpath(path
, drv1
, 0, 0, 0);
2188 /* search for a already open window for the same drive */
2189 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2190 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(child_wnd
, GWLP_USERDATA
);
2193 _tsplitpath(child
->root
.path
, drv2
, 0, 0, 0);
2195 if (!lstrcmpi(drv2
, drv1
)) {
2196 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2198 if (IsIconic(child_wnd
))
2199 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2209 static BOOL
activate_fs_window(LPCTSTR filesys
)
2213 /* search for a already open window of the given file system name */
2214 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2215 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(child_wnd
, GWLP_USERDATA
);
2218 if (!lstrcmpi(child
->root
.fs
, filesys
)) {
2219 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2221 if (IsIconic(child_wnd
))
2222 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2232 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
2234 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2238 if (Globals
.saveSettings
)
2239 save_registry_settings();
2241 DestroyWindow(hwnd
);
2243 /* clear handle variables */
2244 Globals
.hMenuFrame
= 0;
2245 Globals
.hMenuView
= 0;
2246 Globals
.hMenuOptions
= 0;
2247 Globals
.hMainWnd
= 0;
2248 Globals
.hmdiclient
= 0;
2249 Globals
.hdrivebar
= 0;
2256 case WM_INITMENUPOPUP
: {
2257 HWND hwndClient
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2259 if (!SendMessage(hwndClient
, WM_INITMENUPOPUP
, wparam
, lparam
))
2264 UINT cmd
= LOWORD(wparam
);
2265 HWND hwndClient
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2267 if (SendMessage(hwndClient
, WM_DISPATCH_COMMAND
, wparam
, lparam
))
2270 if (cmd
>=ID_DRIVE_FIRST
&& cmd
<=ID_DRIVE_FIRST
+0xFF) {
2271 TCHAR drv
[_MAX_DRIVE
], path
[MAX_PATH
];
2273 LPCTSTR root
= Globals
.drives
;
2276 for(i
=cmd
-ID_DRIVE_FIRST
; i
--; root
++)
2280 if (activate_drive_window(root
))
2283 _tsplitpath(root
, drv
, 0, 0, 0);
2285 if (!SetCurrentDirectory(drv
)) {
2286 display_error(hwnd
, GetLastError());
2290 GetCurrentDirectory(MAX_PATH
, path
); /*TODO: store last directory per drive */
2291 child
= alloc_child_window(path
, NULL
, hwnd
);
2293 if (!create_child_window(child
))
2295 } else switch(cmd
) {
2297 SendMessage(hwnd
, WM_CLOSE
, 0, 0);
2300 case ID_WINDOW_NEW
: {
2301 TCHAR path
[MAX_PATH
];
2304 GetCurrentDirectory(MAX_PATH
, path
);
2305 child
= alloc_child_window(path
, NULL
, hwnd
);
2307 if (!create_child_window(child
))
2315 case ID_WINDOW_CASCADE
:
2316 SendMessage(Globals
.hmdiclient
, WM_MDICASCADE
, 0, 0);
2319 case ID_WINDOW_TILE_HORZ
:
2320 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
2323 case ID_WINDOW_TILE_VERT
:
2324 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
2327 case ID_WINDOW_ARRANGE
:
2328 SendMessage(Globals
.hmdiclient
, WM_MDIICONARRANGE
, 0, 0);
2331 case ID_SELECT_FONT
: {
2332 TCHAR dlg_name
[BUFFER_LEN
], dlg_info
[BUFFER_LEN
];
2336 HDC hdc
= GetDC(hwnd
);
2337 chFont
.lStructSize
= sizeof(CHOOSEFONT
);
2338 chFont
.hwndOwner
= hwnd
;
2340 chFont
.lpLogFont
= &lFont
;
2341 chFont
.Flags
= CF_SCREENFONTS
| CF_FORCEFONTEXIST
| CF_LIMITSIZE
| CF_NOSCRIPTSEL
;
2342 chFont
.rgbColors
= RGB(0,0,0);
2343 chFont
.lCustData
= 0;
2344 chFont
.lpfnHook
= NULL
;
2345 chFont
.lpTemplateName
= NULL
;
2346 chFont
.hInstance
= Globals
.hInstance
;
2347 chFont
.lpszStyle
= NULL
;
2348 chFont
.nFontType
= SIMULATED_FONTTYPE
;
2349 chFont
.nSizeMin
= 0;
2350 chFont
.nSizeMax
= 24;
2352 if (ChooseFont(&chFont
)) {
2356 DeleteObject(Globals
.hfont
);
2357 Globals
.hfont
= CreateFontIndirect(&lFont
);
2358 hFontOld
= SelectObject(hdc
, Globals
.hfont
);
2359 GetTextExtentPoint32(hdc
, sSpace
, 1, &Globals
.spaceSize
);
2361 /* change font in all open child windows */
2362 for(childWnd
=GetWindow(Globals
.hmdiclient
,GW_CHILD
); childWnd
; childWnd
=GetNextWindow(childWnd
,GW_HWNDNEXT
)) {
2363 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(childWnd
, GWLP_USERDATA
);
2364 SendMessage(child
->left
.hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, TRUE
);
2365 SendMessage(child
->right
.hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, TRUE
);
2366 SendMessage(child
->left
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
2367 SendMessage(child
->right
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
2368 InvalidateRect(child
->left
.hwnd
, NULL
, TRUE
);
2369 InvalidateRect(child
->right
.hwnd
, NULL
, TRUE
);
2372 SelectObject(hdc
, hFontOld
);
2374 else if (CommDlgExtendedError()) {
2375 LoadString(Globals
.hInstance
, IDS_FONT_SEL_DLG_NAME
, dlg_name
, BUFFER_LEN
);
2376 LoadString(Globals
.hInstance
, IDS_FONT_SEL_ERROR
, dlg_info
, BUFFER_LEN
);
2377 MessageBox(hwnd
, dlg_info
, dlg_name
, MB_OK
);
2380 ReleaseDC(hwnd
, hdc
);
2384 case ID_VIEW_TOOL_BAR
:
2385 toggle_child(hwnd
, cmd
, Globals
.htoolbar
);
2388 case ID_VIEW_DRIVE_BAR
:
2389 toggle_child(hwnd
, cmd
, Globals
.hdrivebar
);
2392 case ID_VIEW_STATUSBAR
:
2393 toggle_child(hwnd
, cmd
, Globals
.hstatusbar
);
2396 case ID_VIEW_SAVESETTINGS
:
2397 Globals
.saveSettings
= !Globals
.saveSettings
;
2398 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_SAVESETTINGS
,
2399 Globals
.saveSettings
? MF_CHECKED
: MF_UNCHECKED
);
2403 struct ExecuteDialog dlg
;
2405 memset(&dlg
, 0, sizeof(struct ExecuteDialog
));
2407 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_EXECUTE
), hwnd
, ExecuteDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
2408 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, dlg
.cmd
/*file*/, NULL
/*parameters*/, NULL
/*dir*/, dlg
.cmdshow
);
2410 if ((int)hinst
<= 32)
2411 display_error(hwnd
, GetLastError());
2415 case ID_CONNECT_NETWORK_DRIVE
: {
2416 DWORD ret
= WNetConnectionDialog(hwnd
, RESOURCETYPE_DISK
);
2417 if (ret
== NO_ERROR
)
2419 else if (ret
!= (DWORD
)-1) {
2420 if (ret
== ERROR_EXTENDED_ERROR
)
2421 display_network_error(hwnd
);
2423 display_error(hwnd
, ret
);
2427 case ID_DISCONNECT_NETWORK_DRIVE
: {
2428 DWORD ret
= WNetDisconnectDialog(hwnd
, RESOURCETYPE_DISK
);
2429 if (ret
== NO_ERROR
)
2431 else if (ret
!= (DWORD
)-1) {
2432 if (ret
== ERROR_EXTENDED_ERROR
)
2433 display_network_error(hwnd
);
2435 display_error(hwnd
, ret
);
2439 case ID_FORMAT_DISK
: {
2440 UINT sem_org
= SetErrorMode(0); /* Get the current Error Mode settings. */
2441 SetErrorMode(sem_org
& ~SEM_FAILCRITICALERRORS
); /* Force O/S to handle */
2442 SHFormatDrive(hwnd
, 0 /* A: */, SHFMT_ID_DEFAULT
, 0);
2443 SetErrorMode(sem_org
); /* Put it back the way it was. */
2447 WinHelp(hwnd
, RS(b1
,IDS_WINEFILE
), HELP_INDEX
, 0);
2450 #ifndef _NO_EXTENSIONS
2451 case ID_VIEW_FULLSCREEN
:
2452 CheckMenuItem(Globals
.hMenuOptions
, cmd
, toggle_fullscreen(hwnd
)?MF_CHECKED
:0);
2456 case ID_DRIVE_UNIX_FS
: {
2457 TCHAR path
[MAX_PATH
];
2459 char cpath
[MAX_PATH
];
2463 if (activate_fs_window(RS(b1
,IDS_UNIXFS
)))
2467 getcwd(cpath
, MAX_PATH
);
2468 MultiByteToWideChar(CP_UNIXCP
, 0, cpath
, -1, path
, MAX_PATH
);
2470 getcwd(path
, MAX_PATH
);
2472 child
= alloc_child_window(path
, NULL
, hwnd
);
2474 if (!create_child_window(child
))
2478 #ifdef _SHELL_FOLDERS
2479 case ID_DRIVE_SHELL_NS
: {
2480 TCHAR path
[MAX_PATH
];
2483 if (activate_fs_window(RS(b1
,IDS_SHELL
)))
2486 GetCurrentDirectory(MAX_PATH
, path
);
2487 child
= alloc_child_window(path
, get_path_pidl(path
,hwnd
), hwnd
);
2489 if (!create_child_window(child
))
2495 /*TODO: There are even more menu items! */
2497 #ifndef _NO_EXTENSIONS
2500 WineLicense(Globals
.hMainWnd
);
2503 case ID_NO_WARRANTY
:
2504 WineWarranty(Globals
.hMainWnd
);
2508 ShellAbout(hwnd
, RS(b2
,IDS_WINE
), RS(b1
,IDS_WINEFILE
), 0);
2513 ShellAbout(hwnd
, RS(b1
,IDS_WINEFILE
), NULL
, 0);
2515 #endif /* _NO_EXTENSIONS */
2518 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2519 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2520 else */if ((cmd
<IDW_FIRST_CHILD
|| cmd
>=IDW_FIRST_CHILD
+0x100) &&
2521 (cmd
<SC_SIZE
|| cmd
>SC_RESTORE
))
2522 MessageBox(hwnd
, RS(b2
,IDS_NO_IMPL
), RS(b1
,IDS_WINEFILE
), MB_OK
);
2524 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2529 resize_frame(hwnd
, LOWORD(lparam
), HIWORD(lparam
));
2530 break; /* do not pass message to DefFrameProc */
2532 case WM_DEVICECHANGE
:
2533 SendMessage(hwnd
, WM_COMMAND
, MAKELONG(ID_REFRESH
,0), 0);
2536 #ifndef _NO_EXTENSIONS
2537 case WM_GETMINMAXINFO
: {
2538 LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
2540 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2541 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2544 case FRM_CALC_CLIENT
:
2545 frame_get_clientspace(hwnd
, (PRECT
)lparam
);
2547 #endif /* _NO_EXTENSIONS */
2550 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2557 static TCHAR g_pos_names
[COLUMNS
][20] = {
2561 static const int g_pos_align
[] = {
2563 HDF_LEFT
, /* Name */
2564 HDF_RIGHT
, /* Size */
2565 HDF_LEFT
, /* CDate */
2566 #ifndef _NO_EXTENSIONS
2567 HDF_LEFT
, /* ADate */
2568 HDF_LEFT
, /* MDate */
2569 HDF_LEFT
, /* Index */
2570 HDF_CENTER
, /* Links */
2572 HDF_CENTER
, /* Attributes */
2573 #ifndef _NO_EXTENSIONS
2574 HDF_LEFT
/* Security */
2578 static void resize_tree(ChildWnd
* child
, int cx
, int cy
)
2580 HDWP hdwp
= BeginDeferWindowPos(4);
2588 cx
= child
->split_pos
+ SPLIT_WIDTH
/2;
2590 #ifndef _NO_EXTENSIONS
2598 SendMessage(child
->left
.hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hdl
);
2600 DeferWindowPos(hdwp
, child
->left
.hwndHeader
, wp
.hwndInsertAfter
,
2601 wp
.x
-1, wp
.y
, child
->split_pos
-SPLIT_WIDTH
/2+1, wp
.cy
, wp
.flags
);
2602 DeferWindowPos(hdwp
, child
->right
.hwndHeader
, wp
.hwndInsertAfter
,
2603 rt
.left
+cx
+1, wp
.y
, wp
.cx
-cx
+2, wp
.cy
, wp
.flags
);
2605 #endif /* _NO_EXTENSIONS */
2607 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
);
2608 DeferWindowPos(hdwp
, child
->right
.hwnd
, 0, rt
.left
+cx
+1, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
2610 EndDeferWindowPos(hdwp
);
2614 #ifndef _NO_EXTENSIONS
2616 static HWND
create_header(HWND parent
, Pane
* pane
, int id
)
2621 HWND hwnd
= CreateWindow(WC_HEADER
, 0, WS_CHILD
|WS_VISIBLE
|HDS_HORZ
|HDS_FULLDRAG
/*TODO: |HDS_BUTTONS + sort orders*/,
2622 0, 0, 0, 0, parent
, (HMENU
)id
, Globals
.hInstance
, 0);
2626 SendMessage(hwnd
, WM_SETFONT
, (WPARAM
)GetStockObject(DEFAULT_GUI_FONT
), FALSE
);
2628 hdi
.mask
= HDI_TEXT
|HDI_WIDTH
|HDI_FORMAT
;
2630 for(idx
=0; idx
<COLUMNS
; idx
++) {
2631 hdi
.pszText
= g_pos_names
[idx
];
2632 hdi
.fmt
= HDF_STRING
| g_pos_align
[idx
];
2633 hdi
.cxy
= pane
->widths
[idx
];
2634 SendMessage(hwnd
, HDM_INSERTITEM
, idx
, (LPARAM
) &hdi
);
2640 #endif /* _NO_EXTENSIONS */
2643 static void init_output(HWND hwnd
)
2645 static const TCHAR s1000
[] = {'1','0','0','0','\0'};
2649 HDC hdc
= GetDC(hwnd
);
2651 if (GetNumberFormat(LOCALE_USER_DEFAULT
, 0, s1000
, 0, b
, 16) > 4)
2652 Globals
.num_sep
= b
[1];
2654 Globals
.num_sep
= TEXT('.');
2656 old_font
= SelectObject(hdc
, Globals
.hfont
);
2657 GetTextExtentPoint32(hdc
, sSpace
, 1, &Globals
.spaceSize
);
2658 SelectObject(hdc
, old_font
);
2659 ReleaseDC(hwnd
, hdc
);
2662 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
);
2665 /* calculate preferred width for all visible columns */
2667 static BOOL
calc_widths(Pane
* pane
, BOOL anyway
)
2669 int col
, x
, cx
, spc
=3*Globals
.spaceSize
.cx
;
2670 int entries
= SendMessage(pane
->hwnd
, LB_GETCOUNT
, 0, 0);
2671 int orgWidths
[COLUMNS
];
2672 int orgPositions
[COLUMNS
+1];
2678 memcpy(orgWidths
, pane
->widths
, sizeof(orgWidths
));
2679 memcpy(orgPositions
, pane
->positions
, sizeof(orgPositions
));
2682 for(col
=0; col
<COLUMNS
; col
++)
2683 pane
->widths
[col
] = 0;
2685 hdc
= GetDC(pane
->hwnd
);
2686 hfontOld
= SelectObject(hdc
, Globals
.hfont
);
2688 for(cnt
=0; cnt
<entries
; cnt
++) {
2689 Entry
* entry
= (Entry
*) SendMessage(pane
->hwnd
, LB_GETITEMDATA
, cnt
, 0);
2698 dis
.hwndItem
= pane
->hwnd
;
2700 dis
.rcItem
.left
= 0;
2702 dis
.rcItem
.right
= 0;
2703 dis
.rcItem
.bottom
= 0;
2704 /*dis.itemData = 0; */
2706 draw_item(pane
, &dis
, entry
, COLUMNS
);
2709 SelectObject(hdc
, hfontOld
);
2710 ReleaseDC(pane
->hwnd
, hdc
);
2713 for(col
=0; col
<COLUMNS
; col
++) {
2714 pane
->positions
[col
] = x
;
2715 cx
= pane
->widths
[col
];
2720 if (cx
< IMAGE_WIDTH
)
2723 pane
->widths
[col
] = cx
;
2729 pane
->positions
[COLUMNS
] = x
;
2731 SendMessage(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, x
, 0);
2734 if (!memcmp(orgWidths
, pane
->widths
, sizeof(orgWidths
)))
2737 /* don't move, if only collapsing an entry */
2738 if (!anyway
&& pane
->widths
[0]<orgWidths
[0] &&
2739 !memcmp(orgWidths
+1, pane
->widths
+1, sizeof(orgWidths
)-sizeof(int))) {
2740 pane
->widths
[0] = orgWidths
[0];
2741 memcpy(pane
->positions
, orgPositions
, sizeof(orgPositions
));
2746 InvalidateRect(pane
->hwnd
, 0, TRUE
);
2752 /* calculate one preferred column width */
2754 static void calc_single_width(Pane
* pane
, int col
)
2758 int entries
= SendMessage(pane
->hwnd
, LB_GETCOUNT
, 0, 0);
2762 pane
->widths
[col
] = 0;
2764 hdc
= GetDC(pane
->hwnd
);
2765 hfontOld
= SelectObject(hdc
, Globals
.hfont
);
2767 for(cnt
=0; cnt
<entries
; cnt
++) {
2768 Entry
* entry
= (Entry
*) SendMessage(pane
->hwnd
, LB_GETITEMDATA
, cnt
, 0);
2776 dis
.hwndItem
= pane
->hwnd
;
2778 dis
.rcItem
.left
= 0;
2780 dis
.rcItem
.right
= 0;
2781 dis
.rcItem
.bottom
= 0;
2782 /*dis.itemData = 0; */
2784 draw_item(pane
, &dis
, entry
, col
);
2787 SelectObject(hdc
, hfontOld
);
2788 ReleaseDC(pane
->hwnd
, hdc
);
2790 cx
= pane
->widths
[col
];
2793 cx
+= 3*Globals
.spaceSize
.cx
;
2795 if (cx
< IMAGE_WIDTH
)
2799 pane
->widths
[col
] = cx
;
2801 x
= pane
->positions
[col
] + cx
;
2803 for(; col
<COLUMNS
; ) {
2804 pane
->positions
[++col
] = x
;
2805 x
+= pane
->widths
[col
];
2808 SendMessage(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, x
, 0);
2812 static BOOL
pattern_match(LPCTSTR str
, LPCTSTR pattern
)
2814 for( ; *str
&&*pattern
; str
++,pattern
++) {
2815 if (*pattern
== '*') {
2817 while(*pattern
== '*');
2823 if (*str
==*pattern
&& pattern_match(str
, pattern
))
2828 else if (*str
!=*pattern
&& *pattern
!='?')
2832 if (*str
|| *pattern
)
2833 if (*pattern
!='*' || pattern
[1]!='\0')
2839 static BOOL
pattern_imatch(LPCTSTR str
, LPCTSTR pattern
)
2841 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2844 lstrcpy(b2
, pattern
);
2848 return pattern_match(b1
, b2
);
2858 static enum FILE_TYPE
get_file_type(LPCTSTR filename
);
2861 /* insert listbox entries after index idx */
2863 static int insert_entries(Pane
* pane
, Entry
* dir
, LPCTSTR pattern
, int filter_flags
, int idx
)
2870 ShowWindow(pane
->hwnd
, SW_HIDE
);
2872 for(; entry
; entry
=entry
->next
) {
2874 if (pane
->treePane
&& !(entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
2878 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
2879 /* don't display entries "." and ".." in the left pane */
2880 if (pane
->treePane
&& entry
->data
.cFileName
[0]==TEXT('.'))
2882 #ifndef _NO_EXTENSIONS
2883 entry
->data
.cFileName
[1]==TEXT('\0') ||
2885 (entry
->data
.cFileName
[1]==TEXT('.') && entry
->data
.cFileName
[2]==TEXT('\0')))
2888 /* filter directories in right pane */
2889 if (!pane
->treePane
&& !(filter_flags
&TF_DIRECTORIES
))
2893 /* filter using the file name pattern */
2895 if (!pattern_imatch(entry
->data
.cFileName
, pattern
))
2898 /* filter system and hidden files */
2899 if (!(filter_flags
&TF_HIDDEN
) && (entry
->data
.dwFileAttributes
&(FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
)))
2902 /* filter looking at the file type */
2903 if ((filter_flags
&(TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
)) != (TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
))
2904 switch(get_file_type(entry
->data
.cFileName
)) {
2906 if (!(filter_flags
& TF_PROGRAMS
))
2911 if (!(filter_flags
& TF_DOCUMENTS
))
2915 default: /* TF_OTHERS */
2916 if (!(filter_flags
& TF_OTHERS
))
2923 SendMessage(pane
->hwnd
, LB_INSERTSTRING
, idx
, (LPARAM
) entry
);
2925 if (pane
->treePane
&& entry
->expanded
)
2926 idx
= insert_entries(pane
, entry
->down
, pattern
, filter_flags
, idx
);
2929 ShowWindow(pane
->hwnd
, SW_SHOW
);
2935 static void format_bytes(LPTSTR buffer
, LONGLONG bytes
)
2937 static const TCHAR sFmtGB
[] = {'%', '.', '1', 'f', ' ', 'G', 'B', '\0'};
2938 static const TCHAR sFmtMB
[] = {'%', '.', '1', 'f', ' ', 'M', 'B', '\0'};
2939 static const TCHAR sFmtkB
[] = {'%', '.', '1', 'f', ' ', 'k', 'B', '\0'};
2941 float fBytes
= (float)bytes
;
2943 if (bytes
>= 1073741824) /* 1 GB */
2944 _stprintf(buffer
, sFmtGB
, fBytes
/1073741824.f
+.5f
);
2945 else if (bytes
>= 1048576) /* 1 MB */
2946 _stprintf(buffer
, sFmtMB
, fBytes
/1048576.f
+.5f
);
2947 else if (bytes
>= 1024) /* 1 kB */
2948 _stprintf(buffer
, sFmtkB
, fBytes
/1024.f
+.5f
);
2950 _stprintf(buffer
, sLongNumFmt
, bytes
);
2953 static void set_space_status(void)
2955 ULARGE_INTEGER ulFreeBytesToCaller
, ulTotalBytes
, ulFreeBytes
;
2956 TCHAR fmt
[64], b1
[64], b2
[64], buffer
[BUFFER_LEN
];
2958 if (GetDiskFreeSpaceEx(NULL
, &ulFreeBytesToCaller
, &ulTotalBytes
, &ulFreeBytes
)) {
2959 format_bytes(b1
, ulFreeBytesToCaller
.QuadPart
);
2960 format_bytes(b2
, ulTotalBytes
.QuadPart
);
2961 wsprintf(buffer
, RS(fmt
,IDS_FREE_SPACE_FMT
), b1
, b2
);
2963 lstrcpy(buffer
, sQMarks
);
2965 SendMessage(Globals
.hstatusbar
, SB_SETTEXT
, 0, (LPARAM
)buffer
);
2969 static WNDPROC g_orgTreeWndProc
;
2971 static void create_tree_window(HWND parent
, Pane
* pane
, int id
, int id_header
, LPCTSTR pattern
, int filter_flags
)
2973 static const TCHAR sListBox
[] = {'L','i','s','t','B','o','x','\0'};
2975 static int s_init
= 0;
2976 Entry
* entry
= pane
->root
;
2978 pane
->hwnd
= CreateWindow(sListBox
, sEmpty
, WS_CHILD
|WS_VISIBLE
|WS_HSCROLL
|WS_VSCROLL
|
2979 LBS_DISABLENOSCROLL
|LBS_NOINTEGRALHEIGHT
|LBS_OWNERDRAWFIXED
|LBS_NOTIFY
,
2980 0, 0, 0, 0, parent
, (HMENU
)id
, Globals
.hInstance
, 0);
2982 SetWindowLongPtr(pane
->hwnd
, GWLP_USERDATA
, (LPARAM
)pane
);
2983 g_orgTreeWndProc
= (WNDPROC
) SetWindowLongPtr(pane
->hwnd
, GWLP_WNDPROC
, (LPARAM
)TreeWndProc
);
2985 SendMessage(pane
->hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, FALSE
);
2987 /* insert entries into listbox */
2989 insert_entries(pane
, entry
, pattern
, filter_flags
, -1);
2991 /* calculate column widths */
2994 init_output(pane
->hwnd
);
2997 calc_widths(pane
, TRUE
);
2999 #ifndef _NO_EXTENSIONS
3000 pane
->hwndHeader
= create_header(parent
, pane
, id_header
);
3005 static void InitChildWindow(ChildWnd
* child
)
3007 create_tree_window(child
->hwnd
, &child
->left
, IDW_TREE_LEFT
, IDW_HEADER_LEFT
, NULL
, TF_ALL
);
3008 create_tree_window(child
->hwnd
, &child
->right
, IDW_TREE_RIGHT
, IDW_HEADER_RIGHT
, child
->filter_pattern
, child
->filter_flags
);
3012 static void format_date(const FILETIME
* ft
, TCHAR
* buffer
, int visible_cols
)
3018 *buffer
= TEXT('\0');
3020 if (!ft
->dwLowDateTime
&& !ft
->dwHighDateTime
)
3023 if (!FileTimeToLocalFileTime(ft
, &lft
))
3024 {err
: lstrcpy(buffer
,sQMarks
); return;}
3026 if (!FileTimeToSystemTime(&lft
, &systime
))
3029 if (visible_cols
& COL_DATE
) {
3030 len
= GetDateFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
, BUFFER_LEN
);
3035 if (visible_cols
& COL_TIME
) {
3037 buffer
[len
-1] = ' ';
3039 buffer
[len
++] = ' ';
3041 if (!GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
+len
, BUFFER_LEN
-len
))
3042 buffer
[len
] = TEXT('\0');
3047 static void calc_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3049 RECT rt
= {0, 0, 0, 0};
3051 DrawText(dis
->hDC
, str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
3053 if (rt
.right
> pane
->widths
[col
])
3054 pane
->widths
[col
] = rt
.right
;
3057 static void calc_tabbed_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3059 RECT rt
= {0, 0, 0, 0};
3061 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
3062 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
3064 DrawText(dis
->hDC
, str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
3065 /*FIXME rt (0,0) ??? */
3067 if (rt
.right
> pane
->widths
[col
])
3068 pane
->widths
[col
] = rt
.right
;
3072 static void output_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
, DWORD flags
)
3074 int x
= dis
->rcItem
.left
;
3077 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
3078 rt
.top
= dis
->rcItem
.top
;
3079 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
3080 rt
.bottom
= dis
->rcItem
.bottom
;
3082 DrawText(dis
->hDC
, str
, -1, &rt
, DT_SINGLELINE
|DT_NOPREFIX
|flags
);
3085 static void output_tabbed_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3087 int x
= dis
->rcItem
.left
;
3090 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
3091 rt
.top
= dis
->rcItem
.top
;
3092 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
3093 rt
.bottom
= dis
->rcItem
.bottom
;
3095 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
3096 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
3098 DrawText(dis
->hDC
, str
, -1, &rt
, DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
3101 static void output_number(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3103 int x
= dis
->rcItem
.left
;
3110 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
3111 rt
.top
= dis
->rcItem
.top
;
3112 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
3113 rt
.bottom
= dis
->rcItem
.bottom
;
3118 /* insert number separator characters */
3119 pos
= lstrlen(s
) % 3;
3125 *d
++ = Globals
.num_sep
;
3129 DrawText(dis
->hDC
, b
, d
-b
, &rt
, DT_RIGHT
|DT_SINGLELINE
|DT_NOPREFIX
|DT_END_ELLIPSIS
);
3133 static BOOL
is_exe_file(LPCTSTR ext
)
3135 static const TCHAR executable_extensions
[][4] = {
3140 #ifndef _NO_EXTENSIONS
3144 #endif /* _NO_EXTENSIONS */
3148 TCHAR ext_buffer
[_MAX_EXT
];
3149 const TCHAR (*p
)[4];
3153 for(s
=ext
+1,d
=ext_buffer
; (*d
=tolower(*s
)); s
++)
3156 for(p
=executable_extensions
; (*p
)[0]; p
++)
3157 if (!lstrcmpi(ext_buffer
, *p
))
3163 static BOOL
is_registered_type(LPCTSTR ext
)
3165 /* check if there exists a classname for this file extension in the registry */
3166 if (!RegQueryValue(HKEY_CLASSES_ROOT
, ext
, NULL
, NULL
))
3172 static enum FILE_TYPE
get_file_type(LPCTSTR filename
)
3174 LPCTSTR ext
= _tcsrchr(filename
, '.');
3178 if (is_exe_file(ext
))
3179 return FT_EXECUTABLE
;
3180 else if (is_registered_type(ext
))
3187 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
)
3189 TCHAR buffer
[BUFFER_LEN
];
3191 int visible_cols
= pane
->visible_cols
;
3192 COLORREF bkcolor
, textcolor
;
3193 RECT focusRect
= dis
->rcItem
;
3200 attrs
= entry
->data
.dwFileAttributes
;
3202 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) {
3203 if (entry
->data
.cFileName
[0]==TEXT('.') && entry
->data
.cFileName
[1]==TEXT('.')
3204 && entry
->data
.cFileName
[2]==TEXT('\0'))
3205 img
= IMG_FOLDER_UP
;
3206 #ifndef _NO_EXTENSIONS
3207 else if (entry
->data
.cFileName
[0]==TEXT('.') && entry
->data
.cFileName
[1]==TEXT('\0'))
3208 img
= IMG_FOLDER_CUR
;
3211 #ifdef _NO_EXTENSIONS
3214 (pane
->treePane
&& (dis
->itemState
&ODS_FOCUS
)))
3215 img
= IMG_OPEN_FOLDER
;
3219 switch(get_file_type(entry
->data
.cFileName
)) {
3220 case FT_EXECUTABLE
: img
= IMG_EXECUTABLE
; break;
3221 case FT_DOCUMENT
: img
= IMG_DOCUMENT
; break;
3222 default: img
= IMG_FILE
;
3230 if (pane
->treePane
) {
3232 img_pos
= dis
->rcItem
.left
+ entry
->level
*(IMAGE_WIDTH
+TREE_LINE_DX
);
3234 if (calcWidthCol
== -1) {
3236 int y
= dis
->rcItem
.top
+ IMAGE_HEIGHT
/2;
3239 HRGN hrgn_org
= CreateRectRgn(0, 0, 0, 0);
3242 rt_clip
.left
= dis
->rcItem
.left
;
3243 rt_clip
.top
= dis
->rcItem
.top
;
3244 rt_clip
.right
= dis
->rcItem
.left
+pane
->widths
[col
];
3245 rt_clip
.bottom
= dis
->rcItem
.bottom
;
3247 hrgn
= CreateRectRgnIndirect(&rt_clip
);
3249 if (!GetClipRgn(dis
->hDC
, hrgn_org
)) {
3250 DeleteObject(hrgn_org
);
3254 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
3255 ExtSelectClipRgn(dis
->hDC
, hrgn
, RGN_AND
);
3258 if ((up
=entry
->up
) != NULL
) {
3259 MoveToEx(dis
->hDC
, img_pos
-IMAGE_WIDTH
/2, y
, 0);
3260 LineTo(dis
->hDC
, img_pos
-2, y
);
3262 x
= img_pos
- IMAGE_WIDTH
/2;
3265 x
-= IMAGE_WIDTH
+TREE_LINE_DX
;
3269 && (up
->next
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
3272 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
3273 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
3275 } while((up
=up
->up
) != NULL
);
3278 x
= img_pos
- IMAGE_WIDTH
/2;
3280 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
3281 LineTo(dis
->hDC
, x
, y
);
3285 && (entry
->next
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
)
3288 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
3290 SelectClipRgn(dis
->hDC
, hrgn_org
);
3291 if (hrgn_org
) DeleteObject(hrgn_org
);
3292 /* SelectObject(dis->hDC, holdPen); */
3293 } else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
) {
3294 int right
= img_pos
+ IMAGE_WIDTH
- TREE_LINE_DX
;
3296 if (right
> pane
->widths
[col
])
3297 pane
->widths
[col
] = right
;
3300 img_pos
= dis
->rcItem
.left
;
3303 img_pos
= dis
->rcItem
.left
;
3305 if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3306 pane
->widths
[col
] = IMAGE_WIDTH
;
3309 if (calcWidthCol
== -1) {
3310 focusRect
.left
= img_pos
-2;
3312 #ifdef _NO_EXTENSIONS
3313 if (pane
->treePane
&& entry
) {
3316 DrawText(dis
->hDC
, entry
->data
.cFileName
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
3318 focusRect
.right
= dis
->rcItem
.left
+pane
->positions
[col
+1]+TREE_LINE_DX
+ rt
.right
+2;
3322 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
)
3323 textcolor
= COLOR_COMPRESSED
;
3325 #endif /* _NO_EXTENSIONS */
3326 textcolor
= RGB(0,0,0);
3328 if (dis
->itemState
& ODS_FOCUS
) {
3329 textcolor
= RGB(255,255,255);
3330 bkcolor
= COLOR_SELECTION
;
3332 bkcolor
= RGB(255,255,255);
3335 hbrush
= CreateSolidBrush(bkcolor
);
3336 FillRect(dis
->hDC
, &focusRect
, hbrush
);
3337 DeleteObject(hbrush
);
3339 SetBkMode(dis
->hDC
, TRANSPARENT
);
3340 SetTextColor(dis
->hDC
, textcolor
);
3342 cx
= pane
->widths
[col
];
3344 if (cx
&& img
!=IMG_NONE
) {
3345 if (cx
> IMAGE_WIDTH
)
3348 #ifdef _SHELL_FOLDERS
3349 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
3350 DrawIconEx(dis
->hDC
, img_pos
, dis
->rcItem
.top
, entry
->hicon
, cx
, GetSystemMetrics(SM_CYSMICON
), 0, 0, DI_NORMAL
);
3353 ImageList_DrawEx(Globals
.himl
, img
, dis
->hDC
,
3354 img_pos
, dis
->rcItem
.top
, cx
,
3355 IMAGE_HEIGHT
, bkcolor
, CLR_DEFAULT
, ILD_NORMAL
);
3362 #ifdef _NO_EXTENSIONS
3363 if (img
>= IMG_FOLDER_UP
)
3369 /* ouput file name */
3370 if (calcWidthCol
== -1)
3371 output_text(pane
, dis
, col
, entry
->data
.cFileName
, 0);
3372 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3373 calc_width(pane
, dis
, col
, entry
->data
.cFileName
);
3377 #ifdef _NO_EXTENSIONS
3378 if (!pane
->treePane
) {
3381 /* display file size */
3382 if (visible_cols
& COL_SIZE
) {
3383 #ifdef _NO_EXTENSIONS
3384 if (!(attrs
&FILE_ATTRIBUTE_DIRECTORY
))
3389 size
= ((ULONGLONG
)entry
->data
.nFileSizeHigh
<< 32) | entry
->data
.nFileSizeLow
;
3391 _stprintf(buffer
, sLongNumFmt
, size
);
3393 if (calcWidthCol
== -1)
3394 output_number(pane
, dis
, col
, buffer
);
3395 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3396 calc_width(pane
, dis
, col
, buffer
);/*TODO: not ever time enough */
3402 /* display file date */
3403 if (visible_cols
& (COL_DATE
|COL_TIME
)) {
3404 #ifndef _NO_EXTENSIONS
3405 format_date(&entry
->data
.ftCreationTime
, buffer
, visible_cols
);
3406 if (calcWidthCol
== -1)
3407 output_text(pane
, dis
, col
, buffer
, 0);
3408 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3409 calc_width(pane
, dis
, col
, buffer
);
3412 format_date(&entry
->data
.ftLastAccessTime
, buffer
, visible_cols
);
3413 if (calcWidthCol
== -1)
3414 output_text(pane
, dis
, col
, buffer
, 0);
3415 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3416 calc_width(pane
, dis
, col
, buffer
);
3418 #endif /* _NO_EXTENSIONS */
3420 format_date(&entry
->data
.ftLastWriteTime
, buffer
, visible_cols
);
3421 if (calcWidthCol
== -1)
3422 output_text(pane
, dis
, col
, buffer
, 0);
3423 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3424 calc_width(pane
, dis
, col
, buffer
);
3428 #ifndef _NO_EXTENSIONS
3429 if (entry
->bhfi_valid
) {
3430 ULONGLONG index
= ((ULONGLONG
)entry
->bhfi
.nFileIndexHigh
<< 32) | entry
->bhfi
.nFileIndexLow
;
3432 if (visible_cols
& COL_INDEX
) {
3433 _stprintf(buffer
, sLongHexFmt
, index
);
3435 if (calcWidthCol
== -1)
3436 output_text(pane
, dis
, col
, buffer
, DT_RIGHT
);
3437 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3438 calc_width(pane
, dis
, col
, buffer
);
3443 if (visible_cols
& COL_LINKS
) {
3444 wsprintf(buffer
, sNumFmt
, entry
->bhfi
.nNumberOfLinks
);
3446 if (calcWidthCol
== -1)
3447 output_text(pane
, dis
, col
, buffer
, DT_CENTER
);
3448 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3449 calc_width(pane
, dis
, col
, buffer
);
3455 #endif /* _NO_EXTENSIONS */
3457 /* show file attributes */
3458 if (visible_cols
& COL_ATTRIBUTES
) {
3459 #ifdef _NO_EXTENSIONS
3460 static const TCHAR s4Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3461 lstrcpy(buffer
, s4Tabs
);
3463 static const TCHAR s11Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3464 lstrcpy(buffer
, s11Tabs
);
3467 if (attrs
& FILE_ATTRIBUTE_NORMAL
) buffer
[ 0] = 'N';
3469 if (attrs
& FILE_ATTRIBUTE_READONLY
) buffer
[ 2] = 'R';
3470 if (attrs
& FILE_ATTRIBUTE_HIDDEN
) buffer
[ 4] = 'H';
3471 if (attrs
& FILE_ATTRIBUTE_SYSTEM
) buffer
[ 6] = 'S';
3472 if (attrs
& FILE_ATTRIBUTE_ARCHIVE
) buffer
[ 8] = 'A';
3473 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
) buffer
[10] = 'C';
3474 #ifndef _NO_EXTENSIONS
3475 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) buffer
[12] = 'D';
3476 if (attrs
& FILE_ATTRIBUTE_ENCRYPTED
) buffer
[14] = 'E';
3477 if (attrs
& FILE_ATTRIBUTE_TEMPORARY
) buffer
[16] = 'T';
3478 if (attrs
& FILE_ATTRIBUTE_SPARSE_FILE
) buffer
[18] = 'P';
3479 if (attrs
& FILE_ATTRIBUTE_REPARSE_POINT
) buffer
[20] = 'Q';
3480 if (attrs
& FILE_ATTRIBUTE_OFFLINE
) buffer
[22] = 'O';
3481 if (attrs
& FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
) buffer
[24] = 'X';
3482 #endif /* _NO_EXTENSIONS */
3485 if (calcWidthCol
== -1)
3486 output_tabbed_text(pane
, dis
, col
, buffer
);
3487 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3488 calc_tabbed_width(pane
, dis
, col
, buffer
);
3494 if (flags.security) {
3495 static const TCHAR sSecTabs[] = {
3496 ' ','\t',' ','\t',' ','\t',' ',
3498 ' ','\t',' ','\t',' ','\t',' ',
3500 ' ','\t',' ','\t',' ','\t',' ',
3504 DWORD rights = get_access_mask();
3506 lstrcpy(buffer, sSecTabs);
3508 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
3509 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
3510 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
3511 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
3512 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
3513 if (rights & FILE_EXECUTE) buffer[12] = 'X';
3514 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
3515 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
3516 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
3517 if (rights & WRITE_DAC) buffer[22] = 'C';
3518 if (rights & WRITE_OWNER) buffer[24] = 'O';
3519 if (rights & SYNCHRONIZE) buffer[26] = 'S';
3521 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
3524 if (flags.description) {
3525 get_description(buffer);
3526 output_text(dis, col++, buffer, 0, psize);
3530 #ifdef _NO_EXTENSIONS
3533 /* draw focus frame */
3534 if ((dis
->itemState
&ODS_FOCUS
) && calcWidthCol
==-1) {
3535 /* Currently [04/2000] Wine neither behaves exactly the same */
3536 /* way as WIN 95 nor like Windows NT... */
3541 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
3542 LOGBRUSH lb
= {PS_SOLID
, RGB(255,255,255)};
3543 hpen
= ExtCreatePen(PS_COSMETIC
|PS_ALTERNATE
, 1, &lb
, 0, 0);
3545 hpen
= CreatePen(PS_DOT
, 0, RGB(255,255,255));
3547 lastPen
= SelectPen(dis
->hDC
, hpen
);
3548 lastBrush
= SelectObject(dis
->hDC
, GetStockObject(HOLLOW_BRUSH
));
3549 SetROP2(dis
->hDC
, R2_XORPEN
);
3550 Rectangle(dis
->hDC
, focusRect
.left
, focusRect
.top
, focusRect
.right
, focusRect
.bottom
);
3551 SelectObject(dis
->hDC
, lastBrush
);
3552 SelectObject(dis
->hDC
, lastPen
);
3555 #endif /* _NO_EXTENSIONS */
3559 #ifdef _NO_EXTENSIONS
3561 static void draw_splitbar(HWND hwnd
, int x
)
3564 HDC hdc
= GetDC(hwnd
);
3566 GetClientRect(hwnd
, &rt
);
3568 rt
.left
= x
- SPLIT_WIDTH
/2;
3569 rt
.right
= x
+ SPLIT_WIDTH
/2+1;
3571 InvertRect(hdc
, &rt
);
3573 ReleaseDC(hwnd
, hdc
);
3576 #endif /* _NO_EXTENSIONS */
3579 #ifndef _NO_EXTENSIONS
3581 static void set_header(Pane
* pane
)
3584 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3587 item
.mask
= HDI_WIDTH
;
3590 for(; x
+pane
->widths
[i
]<scroll_pos
&& i
<COLUMNS
; i
++) {
3591 x
+= pane
->widths
[i
];
3592 SendMessage(pane
->hwndHeader
, HDM_SETITEM
, i
, (LPARAM
) &item
);
3596 x
+= pane
->widths
[i
];
3597 item
.cxy
= x
- scroll_pos
;
3598 SendMessage(pane
->hwndHeader
, HDM_SETITEM
, i
++, (LPARAM
) &item
);
3600 for(; i
<COLUMNS
; i
++) {
3601 item
.cxy
= pane
->widths
[i
];
3602 x
+= pane
->widths
[i
];
3603 SendMessage(pane
->hwndHeader
, HDM_SETITEM
, i
, (LPARAM
) &item
);
3608 static LRESULT
pane_notify(Pane
* pane
, NMHDR
* pnmh
)
3610 switch(pnmh
->code
) {
3611 case HDN_ITEMCHANGED
: {
3612 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3613 int idx
= phdn
->iItem
;
3614 int dx
= phdn
->pitem
->cxy
- pane
->widths
[idx
];
3618 GetClientRect(pane
->hwnd
, &clnt
);
3620 pane
->widths
[idx
] += dx
;
3622 for(i
=idx
; ++i
<=COLUMNS
; )
3623 pane
->positions
[i
] += dx
;
3626 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3630 rt_scr
.left
= pane
->positions
[idx
+1]-scroll_pos
;
3632 rt_scr
.right
= clnt
.right
;
3633 rt_scr
.bottom
= clnt
.bottom
;
3635 rt_clip
.left
= pane
->positions
[idx
]-scroll_pos
;
3637 rt_clip
.right
= clnt
.right
;
3638 rt_clip
.bottom
= clnt
.bottom
;
3640 if (rt_scr
.left
< 0) rt_scr
.left
= 0;
3641 if (rt_clip
.left
< 0) rt_clip
.left
= 0;
3643 ScrollWindowEx(pane
->hwnd
, dx
, 0, &rt_scr
, &rt_clip
, 0, 0, SW_INVALIDATE
);
3645 rt_clip
.right
= pane
->positions
[idx
+1];
3646 RedrawWindow(pane
->hwnd
, &rt_clip
, 0, RDW_INVALIDATE
|RDW_UPDATENOW
);
3648 if (pnmh
->code
== HDN_ENDTRACK
) {
3649 SendMessage(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, pane
->positions
[COLUMNS
], 0);
3651 if (GetScrollPos(pane
->hwnd
, SB_HORZ
) != scroll_pos
)
3659 case HDN_DIVIDERDBLCLICK
: {
3660 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3663 calc_single_width(pane
, phdn
->iItem
);
3664 item
.mask
= HDI_WIDTH
;
3665 item
.cxy
= pane
->widths
[phdn
->iItem
];
3667 SendMessage(pane
->hwndHeader
, HDM_SETITEM
, phdn
->iItem
, (LPARAM
) &item
);
3668 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3675 #endif /* _NO_EXTENSIONS */
3678 static void scan_entry(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3680 TCHAR path
[MAX_PATH
];
3681 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
3683 /* delete sub entries in left pane */
3685 LRESULT res
= SendMessage(child
->left
.hwnd
, LB_GETITEMDATA
, idx
+1, 0);
3686 Entry
* sub
= (Entry
*) res
;
3688 if (res
==LB_ERR
|| !sub
|| sub
->level
<=entry
->level
)
3691 SendMessage(child
->left
.hwnd
, LB_DELETESTRING
, idx
+1, 0);
3694 /* empty right pane */
3695 SendMessage(child
->right
.hwnd
, LB_RESETCONTENT
, 0, 0);
3697 /* release memory */
3698 free_entries(entry
);
3700 /* read contents from disk */
3701 #ifdef _SHELL_FOLDERS
3702 if (entry
->etype
== ET_SHELL
)
3704 read_directory(entry
, NULL
, child
->sortOrder
, hwnd
);
3709 get_path(entry
, path
);
3710 read_directory(entry
, path
, child
->sortOrder
, hwnd
);
3713 /* insert found entries in right pane */
3714 insert_entries(&child
->right
, entry
->down
, child
->filter_pattern
, child
->filter_flags
, -1);
3715 calc_widths(&child
->right
, FALSE
);
3716 #ifndef _NO_EXTENSIONS
3717 set_header(&child
->right
);
3720 child
->header_wdths_ok
= FALSE
;
3722 SetCursor(old_cursor
);
3726 /* expand a directory entry */
3728 static BOOL
expand_entry(ChildWnd
* child
, Entry
* dir
)
3733 if (!dir
|| dir
->expanded
|| !dir
->down
)
3738 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='\0' && p
->next
) {
3741 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='.' &&
3742 p
->data
.cFileName
[2]=='\0' && p
->next
)
3746 /* no subdirectories ? */
3747 if (!(p
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
3750 idx
= SendMessage(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)dir
);
3752 dir
->expanded
= TRUE
;
3754 /* insert entries in left pane */
3755 insert_entries(&child
->left
, p
, NULL
, TF_ALL
, idx
);
3757 if (!child
->header_wdths_ok
) {
3758 if (calc_widths(&child
->left
, FALSE
)) {
3759 #ifndef _NO_EXTENSIONS
3760 set_header(&child
->left
);
3763 child
->header_wdths_ok
= TRUE
;
3771 static void collapse_entry(Pane
* pane
, Entry
* dir
)
3773 int idx
= SendMessage(pane
->hwnd
, LB_FINDSTRING
, 0, (LPARAM
)dir
);
3775 ShowWindow(pane
->hwnd
, SW_HIDE
);
3777 /* hide sub entries */
3779 LRESULT res
= SendMessage(pane
->hwnd
, LB_GETITEMDATA
, idx
+1, 0);
3780 Entry
* sub
= (Entry
*) res
;
3782 if (res
==LB_ERR
|| !sub
|| sub
->level
<=dir
->level
)
3785 SendMessage(pane
->hwnd
, LB_DELETESTRING
, idx
+1, 0);
3788 dir
->expanded
= FALSE
;
3790 ShowWindow(pane
->hwnd
, SW_SHOW
);
3794 static void refresh_right_pane(ChildWnd
* child
)
3796 SendMessage(child
->right
.hwnd
, LB_RESETCONTENT
, 0, 0);
3797 insert_entries(&child
->right
, child
->right
.root
, child
->filter_pattern
, child
->filter_flags
, -1);
3798 calc_widths(&child
->right
, FALSE
);
3800 #ifndef _NO_EXTENSIONS
3801 set_header(&child
->right
);
3805 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3807 TCHAR path
[MAX_PATH
];
3814 child
->left
.cur
= entry
;
3816 child
->right
.root
= entry
->down
? entry
->down
: entry
;
3817 child
->right
.cur
= entry
;
3819 if (!entry
->scanned
)
3820 scan_entry(child
, entry
, idx
, hwnd
);
3822 refresh_right_pane(child
);
3824 get_path(entry
, path
);
3825 lstrcpy(child
->path
, path
);
3827 if (child
->hwnd
) /* only change window title, if the window already exists */
3828 SetWindowText(child
->hwnd
, path
);
3831 if (SetCurrentDirectory(path
))
3836 static void refresh_child(ChildWnd
* child
)
3838 TCHAR path
[MAX_PATH
], drv
[_MAX_DRIVE
+1];
3842 get_path(child
->left
.cur
, path
);
3843 _tsplitpath(path
, drv
, NULL
, NULL
, NULL
);
3845 child
->right
.root
= NULL
;
3847 scan_entry(child
, &child
->root
.entry
, 0, child
->hwnd
);
3849 #ifdef _SHELL_FOLDERS
3850 if (child
->root
.entry
.etype
== ET_SHELL
)
3851 entry
= read_tree(&child
->root
, NULL
, get_path_pidl(path
,child
->hwnd
), drv
, child
->sortOrder
, child
->hwnd
);
3854 entry
= read_tree(&child
->root
, path
, NULL
, drv
, child
->sortOrder
, child
->hwnd
);
3857 entry
= &child
->root
.entry
;
3859 insert_entries(&child
->left
, child
->root
.entry
.down
, NULL
, TF_ALL
, 0);
3861 set_curdir(child
, entry
, 0, child
->hwnd
);
3863 idx
= SendMessage(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)child
->left
.cur
);
3864 SendMessage(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
3868 static void create_drive_bar(void)
3870 TBBUTTON drivebarBtn
= {0, 0, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0};
3871 #ifndef _NO_EXTENSIONS
3872 TCHAR b1
[BUFFER_LEN
];
3877 GetLogicalDriveStrings(BUFFER_LEN
, Globals
.drives
);
3879 Globals
.hdrivebar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
,
3880 IDW_DRIVEBAR
, 2, Globals
.hInstance
, IDB_DRIVEBAR
, &drivebarBtn
,
3881 0, 16, 13, 16, 13, sizeof(TBBUTTON
));
3883 #ifndef _NO_EXTENSIONS
3885 /* insert unix file system button */
3889 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
3891 drivebarBtn
.idCommand
= ID_DRIVE_UNIX_FS
;
3892 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3893 drivebarBtn
.iString
++;
3895 #ifdef _SHELL_FOLDERS
3896 /* insert shell namespace button */
3897 load_string(b1
, IDS_SHELL
);
3898 b1
[lstrlen(b1
)+1] = '\0';
3899 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
3901 drivebarBtn
.idCommand
= ID_DRIVE_SHELL_NS
;
3902 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3903 drivebarBtn
.iString
++;
3906 /* register windows drive root strings */
3907 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)Globals
.drives
);
3910 drivebarBtn
.idCommand
= ID_DRIVE_FIRST
;
3912 for(p
=Globals
.drives
; *p
; ) {
3913 #ifdef _NO_EXTENSIONS
3914 /* insert drive letter */
3915 TCHAR b
[3] = {tolower(*p
)};
3916 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b
);
3918 switch(GetDriveType(p
)) {
3919 case DRIVE_REMOVABLE
: drivebarBtn
.iBitmap
= 1; break;
3920 case DRIVE_CDROM
: drivebarBtn
.iBitmap
= 3; break;
3921 case DRIVE_REMOTE
: drivebarBtn
.iBitmap
= 4; break;
3922 case DRIVE_RAMDISK
: drivebarBtn
.iBitmap
= 5; break;
3923 default:/*DRIVE_FIXED*/ drivebarBtn
.iBitmap
= 2;
3926 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3927 drivebarBtn
.idCommand
++;
3928 drivebarBtn
.iString
++;
3934 static void refresh_drives(void)
3938 /* destroy drive bar */
3939 DestroyWindow(Globals
.hdrivebar
);
3940 Globals
.hdrivebar
= 0;
3942 /* re-create drive bar */
3945 /* update window layout */
3946 GetClientRect(Globals
.hMainWnd
, &rect
);
3947 SendMessage(Globals
.hMainWnd
, WM_SIZE
, 0, MAKELONG(rect
.right
, rect
.bottom
));
3951 static BOOL
launch_file(HWND hwnd
, LPCTSTR cmd
, UINT nCmdShow
)
3953 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3955 if ((int)hinst
<= 32) {
3956 display_error(hwnd
, GetLastError());
3964 static BOOL
launch_entry(Entry
* entry
, HWND hwnd
, UINT nCmdShow
)
3966 TCHAR cmd
[MAX_PATH
];
3968 #ifdef _SHELL_FOLDERS
3969 if (entry
->etype
== ET_SHELL
) {
3972 SHELLEXECUTEINFO shexinfo
;
3974 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFO
);
3975 shexinfo
.fMask
= SEE_MASK_IDLIST
;
3976 shexinfo
.hwnd
= hwnd
;
3977 shexinfo
.lpVerb
= NULL
;
3978 shexinfo
.lpFile
= NULL
;
3979 shexinfo
.lpParameters
= NULL
;
3980 shexinfo
.lpDirectory
= NULL
;
3981 shexinfo
.nShow
= nCmdShow
;
3982 shexinfo
.lpIDList
= get_to_absolute_pidl(entry
, hwnd
);
3984 if (!ShellExecuteEx(&shexinfo
)) {
3985 display_error(hwnd
, GetLastError());
3989 if (shexinfo
.lpIDList
!= entry
->pidl
)
3990 IMalloc_Free(Globals
.iMalloc
, shexinfo
.lpIDList
);
3996 get_path(entry
, cmd
);
3998 /* start program, open document... */
3999 return launch_file(hwnd
, cmd
, nCmdShow
);
4003 static void activate_entry(ChildWnd
* child
, Pane
* pane
, HWND hwnd
)
4005 Entry
* entry
= pane
->cur
;
4010 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
4011 int scanned_old
= entry
->scanned
;
4015 int idx
= SendMessage(child
->left
.hwnd
, LB_GETCURSEL
, 0, 0);
4016 scan_entry(child
, entry
, idx
, hwnd
);
4019 #ifndef _NO_EXTENSIONS
4020 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='\0')
4024 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='.' && entry
->data
.cFileName
[2]=='\0') {
4025 entry
= child
->left
.cur
->up
;
4026 collapse_entry(&child
->left
, entry
);
4028 } else if (entry
->expanded
)
4029 collapse_entry(pane
, child
->left
.cur
);
4031 expand_entry(child
, child
->left
.cur
);
4033 if (!pane
->treePane
) focus_entry
: {
4034 int idxstart
= SendMessage(child
->left
.hwnd
, LB_GETCURSEL
, 0, 0);
4035 int idx
= SendMessage(child
->left
.hwnd
, LB_FINDSTRING
, idxstart
, (LPARAM
)entry
);
4036 SendMessage(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
4037 set_curdir(child
, entry
, idx
, hwnd
);
4042 calc_widths(pane
, FALSE
);
4044 #ifndef _NO_EXTENSIONS
4049 if (GetKeyState(VK_MENU
) < 0)
4050 show_properties_dlg(entry
, child
->hwnd
);
4052 launch_entry(entry
, child
->hwnd
, SW_SHOWNORMAL
);
4057 static BOOL
pane_command(Pane
* pane
, UINT cmd
)
4061 if (pane
->visible_cols
) {
4062 pane
->visible_cols
= 0;
4063 calc_widths(pane
, TRUE
);
4064 #ifndef _NO_EXTENSIONS
4067 InvalidateRect(pane
->hwnd
, 0, TRUE
);
4068 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
|MF_CHECKED
);
4069 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
);
4070 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
4074 case ID_VIEW_ALL_ATTRIBUTES
:
4075 if (pane
->visible_cols
!= COL_ALL
) {
4076 pane
->visible_cols
= COL_ALL
;
4077 calc_widths(pane
, TRUE
);
4078 #ifndef _NO_EXTENSIONS
4081 InvalidateRect(pane
->hwnd
, 0, TRUE
);
4082 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
);
4083 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
|MF_CHECKED
);
4084 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
4088 #ifndef _NO_EXTENSIONS
4089 case ID_PREFERRED_SIZES
: {
4090 calc_widths(pane
, TRUE
);
4092 InvalidateRect(pane
->hwnd
, 0, TRUE
);
4096 /* TODO: more command ids... */
4106 static void set_sort_order(ChildWnd
* child
, SORT_ORDER sortOrder
)
4108 if (child
->sortOrder
!= sortOrder
) {
4109 child
->sortOrder
= sortOrder
;
4110 refresh_child(child
);
4114 static void update_view_menu(ChildWnd
* child
)
4116 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_NAME
, child
->sortOrder
==SORT_NAME
? MF_CHECKED
: MF_UNCHECKED
);
4117 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_TYPE
, child
->sortOrder
==SORT_EXT
? MF_CHECKED
: MF_UNCHECKED
);
4118 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_SIZE
, child
->sortOrder
==SORT_SIZE
? MF_CHECKED
: MF_UNCHECKED
);
4119 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_DATE
, child
->sortOrder
==SORT_DATE
? MF_CHECKED
: MF_UNCHECKED
);
4123 static BOOL
is_directory(LPCTSTR target
)
4125 /*TODO correctly handle UNIX paths */
4126 DWORD target_attr
= GetFileAttributes(target
);
4128 if (target_attr
== INVALID_FILE_ATTRIBUTES
)
4131 return target_attr
&FILE_ATTRIBUTE_DIRECTORY
? TRUE
: FALSE
;
4134 static BOOL
prompt_target(Pane
* pane
, LPTSTR source
, LPTSTR target
)
4136 TCHAR path
[MAX_PATH
];
4139 get_path(pane
->cur
, path
);
4141 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_SELECT_DESTINATION
), pane
->hwnd
, DestinationDlgProc
, (LPARAM
)path
) != IDOK
)
4144 get_path(pane
->cur
, source
);
4146 /* convert relative targets to absolute paths */
4147 if (path
[0]!='/' && path
[1]!=':') {
4148 get_path(pane
->cur
->up
, target
);
4149 len
= lstrlen(target
);
4151 if (target
[len
-1]!='\\' && target
[len
-1]!='/')
4152 target
[len
++] = '/';
4154 lstrcpy(target
+len
, path
);
4156 lstrcpy(target
, path
);
4158 /* If the target already exists as directory, create a new target below this. */
4159 if (is_directory(path
)) {
4160 TCHAR fname
[_MAX_FNAME
], ext
[_MAX_EXT
];
4161 static const TCHAR sAppend
[] = {'%','s','/','%','s','%','s','\0'};
4163 _tsplitpath(source
, NULL
, NULL
, fname
, ext
);
4165 wsprintf(target
, sAppend
, path
, fname
, ext
);
4172 static IContextMenu2
* s_pctxmenu2
= NULL
;
4173 static IContextMenu3
* s_pctxmenu3
= NULL
;
4175 static void CtxMenu_reset(void)
4181 static IContextMenu
* CtxMenu_query_interfaces(IContextMenu
* pcm1
)
4183 IContextMenu
* pcm
= NULL
;
4187 if (IContextMenu_QueryInterface(pcm1
, &IID_IContextMenu3
, (void**)&pcm
) == NOERROR
)
4188 s_pctxmenu3
= (LPCONTEXTMENU3
)pcm
;
4189 else if (IContextMenu_QueryInterface(pcm1
, &IID_IContextMenu2
, (void**)&pcm
) == NOERROR
)
4190 s_pctxmenu2
= (LPCONTEXTMENU2
)pcm
;
4193 IContextMenu_Release(pcm1
);
4199 static BOOL
CtxMenu_HandleMenuMsg(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4202 if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3
, nmsg
, wparam
, lparam
)))
4207 if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2
, nmsg
, wparam
, lparam
)))
4214 static HRESULT
ShellFolderContextMenu(IShellFolder
* shell_folder
, HWND hwndParent
, int cidl
, LPCITEMIDLIST
* apidl
, int x
, int y
)
4217 BOOL executed
= FALSE
;
4219 HRESULT hr
= IShellFolder_GetUIObjectOf(shell_folder
, hwndParent
, cidl
, apidl
, &IID_IContextMenu
, NULL
, (LPVOID
*)&pcm
);
4220 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
4222 if (SUCCEEDED(hr
)) {
4223 HMENU hmenu
= CreatePopupMenu();
4225 pcm
= CtxMenu_query_interfaces(pcm
);
4228 hr
= IContextMenu_QueryContextMenu(pcm
, hmenu
, 0, FCIDM_SHVIEWFIRST
, FCIDM_SHVIEWLAST
, CMF_NORMAL
);
4230 if (SUCCEEDED(hr
)) {
4231 UINT idCmd
= TrackPopupMenu(hmenu
, TPM_LEFTALIGN
|TPM_RETURNCMD
|TPM_RIGHTBUTTON
, x
, y
, 0, hwndParent
, NULL
);
4236 CMINVOKECOMMANDINFO cmi
;
4238 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFO
);
4240 cmi
.hwnd
= hwndParent
;
4241 cmi
.lpVerb
= (LPCSTR
)(INT_PTR
)(idCmd
- FCIDM_SHVIEWFIRST
);
4242 cmi
.lpParameters
= NULL
;
4243 cmi
.lpDirectory
= NULL
;
4244 cmi
.nShow
= SW_SHOWNORMAL
;
4248 hr
= IContextMenu_InvokeCommand(pcm
, &cmi
);
4255 IContextMenu_Release(pcm
);
4258 return FAILED(hr
)? hr
: executed
? S_OK
: S_FALSE
;
4262 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4264 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
4269 LPDRAWITEMSTRUCT dis
= (LPDRAWITEMSTRUCT
)lparam
;
4270 Entry
* entry
= (Entry
*) dis
->itemData
;
4272 if (dis
->CtlID
== IDW_TREE_LEFT
)
4273 draw_item(&child
->left
, dis
, entry
, -1);
4274 else if (dis
->CtlID
== IDW_TREE_RIGHT
)
4275 draw_item(&child
->right
, dis
, entry
, -1);
4277 goto draw_menu_item
;
4282 InitChildWindow(child
);
4286 free_child_window(child
);
4287 SetWindowLongPtr(hwnd
, GWLP_USERDATA
, 0);
4294 GetClientRect(hwnd
, &rt
);
4295 BeginPaint(hwnd
, &ps
);
4296 rt
.left
= child
->split_pos
-SPLIT_WIDTH
/2;
4297 rt
.right
= child
->split_pos
+SPLIT_WIDTH
/2+1;
4298 lastBrush
= SelectObject(ps
.hdc
, GetStockObject(COLOR_SPLITBAR
));
4299 Rectangle(ps
.hdc
, rt
.left
, rt
.top
-1, rt
.right
, rt
.bottom
+1);
4300 SelectObject(ps
.hdc
, lastBrush
);
4301 #ifdef _NO_EXTENSIONS
4302 rt
.top
= rt
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
4303 FillRect(ps
.hdc
, &rt
, GetStockObject(BLACK_BRUSH
));
4305 EndPaint(hwnd
, &ps
);
4309 if (LOWORD(lparam
) == HTCLIENT
) {
4312 ScreenToClient(hwnd
, &pt
);
4314 if (pt
.x
>=child
->split_pos
-SPLIT_WIDTH
/2 && pt
.x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
4315 SetCursor(LoadCursor(0, IDC_SIZEWE
));
4321 case WM_LBUTTONDOWN
: {
4323 int x
= (short)LOWORD(lparam
);
4325 GetClientRect(hwnd
, &rt
);
4327 if (x
>=child
->split_pos
-SPLIT_WIDTH
/2 && x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
4328 last_split
= child
->split_pos
;
4329 #ifdef _NO_EXTENSIONS
4330 draw_splitbar(hwnd
, last_split
);
4338 if (GetCapture() == hwnd
) {
4339 #ifdef _NO_EXTENSIONS
4341 int x
= (short)LOWORD(lparam
);
4342 draw_splitbar(hwnd
, last_split
);
4344 GetClientRect(hwnd
, &rt
);
4345 child
->split_pos
= x
;
4346 resize_tree(child
, rt
.right
, rt
.bottom
);
4352 #ifdef _NO_EXTENSIONS
4353 case WM_CAPTURECHANGED
:
4354 if (GetCapture()==hwnd
&& last_split
>=0)
4355 draw_splitbar(hwnd
, last_split
);
4360 if (wparam
== VK_ESCAPE
)
4361 if (GetCapture() == hwnd
) {
4363 #ifdef _NO_EXTENSIONS
4364 draw_splitbar(hwnd
, last_split
);
4366 child
->split_pos
= last_split
;
4368 GetClientRect(hwnd
, &rt
);
4369 resize_tree(child
, rt
.right
, rt
.bottom
);
4372 SetCursor(LoadCursor(0, IDC_ARROW
));
4377 if (GetCapture() == hwnd
) {
4379 int x
= (short)LOWORD(lparam
);
4381 #ifdef _NO_EXTENSIONS
4382 HDC hdc
= GetDC(hwnd
);
4383 GetClientRect(hwnd
, &rt
);
4385 rt
.left
= last_split
-SPLIT_WIDTH
/2;
4386 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
4387 InvertRect(hdc
, &rt
);
4390 rt
.left
= x
-SPLIT_WIDTH
/2;
4391 rt
.right
= x
+SPLIT_WIDTH
/2+1;
4392 InvertRect(hdc
, &rt
);
4394 ReleaseDC(hwnd
, hdc
);
4396 GetClientRect(hwnd
, &rt
);
4398 if (x
>=0 && x
<rt
.right
) {
4399 child
->split_pos
= x
;
4400 resize_tree(child
, rt
.right
, rt
.bottom
);
4401 rt
.left
= x
-SPLIT_WIDTH
/2;
4402 rt
.right
= x
+SPLIT_WIDTH
/2+1;
4403 InvalidateRect(hwnd
, &rt
, FALSE
);
4404 UpdateWindow(child
->left
.hwnd
);
4406 UpdateWindow(child
->right
.hwnd
);
4412 #ifndef _NO_EXTENSIONS
4413 case WM_GETMINMAXINFO
:
4414 DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
4416 {LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
4418 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
4419 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
4421 #endif /* _NO_EXTENSIONS */
4424 if (SetCurrentDirectory(child
->path
))
4426 SetFocus(child
->focus_pane
? child
->right
.hwnd
: child
->left
.hwnd
);
4429 case WM_DISPATCH_COMMAND
: {
4430 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4432 switch(LOWORD(wparam
)) {
4433 case ID_WINDOW_NEW
: {
4434 ChildWnd
* new_child
= alloc_child_window(child
->path
, NULL
, hwnd
);
4436 if (!create_child_window(new_child
))
4443 refresh_child(child
);
4447 activate_entry(child
, pane
, hwnd
);
4450 case ID_FILE_MOVE
: {
4451 TCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
4453 if (prompt_target(pane
, source
, target
)) {
4454 SHFILEOPSTRUCT shfo
= {hwnd
, FO_MOVE
, source
, target
};
4456 source
[lstrlen(source
)+1] = '\0';
4457 target
[lstrlen(target
)+1] = '\0';
4459 if (!SHFileOperation(&shfo
))
4460 refresh_child(child
);
4464 case ID_FILE_COPY
: {
4465 TCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
4467 if (prompt_target(pane
, source
, target
)) {
4468 SHFILEOPSTRUCT shfo
= {hwnd
, FO_COPY
, source
, target
};
4470 source
[lstrlen(source
)+1] = '\0';
4471 target
[lstrlen(target
)+1] = '\0';
4473 if (!SHFileOperation(&shfo
))
4474 refresh_child(child
);
4478 case ID_FILE_DELETE
: {
4479 TCHAR path
[BUFFER_LEN
];
4480 SHFILEOPSTRUCT shfo
= {hwnd
, FO_DELETE
, path
};
4482 get_path(pane
->cur
, path
);
4484 path
[lstrlen(path
)+1] = '\0';
4486 if (!SHFileOperation(&shfo
))
4487 refresh_child(child
);
4490 case ID_VIEW_SORT_NAME
:
4491 set_sort_order(child
, SORT_NAME
);
4494 case ID_VIEW_SORT_TYPE
:
4495 set_sort_order(child
, SORT_EXT
);
4498 case ID_VIEW_SORT_SIZE
:
4499 set_sort_order(child
, SORT_SIZE
);
4502 case ID_VIEW_SORT_DATE
:
4503 set_sort_order(child
, SORT_DATE
);
4506 case ID_VIEW_FILTER
: {
4507 struct FilterDialog dlg
;
4509 memset(&dlg
, 0, sizeof(struct FilterDialog
));
4510 lstrcpy(dlg
.pattern
, child
->filter_pattern
);
4511 dlg
.flags
= child
->filter_flags
;
4513 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE
), hwnd
, FilterDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
4514 lstrcpy(child
->filter_pattern
, dlg
.pattern
);
4515 child
->filter_flags
= dlg
.flags
;
4516 refresh_right_pane(child
);
4520 case ID_VIEW_SPLIT
: {
4521 last_split
= child
->split_pos
;
4522 #ifdef _NO_EXTENSIONS
4523 draw_splitbar(hwnd
, last_split
);
4528 case ID_EDIT_PROPERTIES
:
4529 show_properties_dlg(pane
->cur
, child
->hwnd
);
4533 return pane_command(pane
, LOWORD(wparam
));
4539 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4541 switch(HIWORD(wparam
)) {
4542 case LBN_SELCHANGE
: {
4543 int idx
= SendMessage(pane
->hwnd
, LB_GETCURSEL
, 0, 0);
4544 Entry
* entry
= (Entry
*) SendMessage(pane
->hwnd
, LB_GETITEMDATA
, idx
, 0);
4546 if (pane
== &child
->left
)
4547 set_curdir(child
, entry
, idx
, hwnd
);
4553 activate_entry(child
, pane
, hwnd
);
4558 #ifndef _NO_EXTENSIONS
4560 NMHDR
* pnmh
= (NMHDR
*) lparam
;
4561 return pane_notify(pnmh
->idFrom
==IDW_HEADER_LEFT
? &child
->left
: &child
->right
, pnmh
);}
4564 #ifdef _SHELL_FOLDERS
4565 case WM_CONTEXTMENU
: {
4570 /* first select the current item in the listbox */
4571 HWND hpanel
= (HWND
) wparam
;
4572 pt_clnt
.x
= pt
.x
= (short)LOWORD(lparam
);
4573 pt_clnt
.y
= pt
.y
= (short)HIWORD(lparam
);
4574 ScreenToClient(hpanel
, &pt_clnt
);
4575 SendMessage(hpanel
, WM_LBUTTONDOWN
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4576 SendMessage(hpanel
, WM_LBUTTONUP
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4578 /* now create the popup menu using shell namespace and IContextMenu */
4579 pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4580 idx
= SendMessage(pane
->hwnd
, LB_GETCURSEL
, 0, 0);
4583 Entry
* entry
= (Entry
*) SendMessage(pane
->hwnd
, LB_GETITEMDATA
, idx
, 0);
4585 LPITEMIDLIST pidl_abs
= get_to_absolute_pidl(entry
, hwnd
);
4588 IShellFolder
* parentFolder
;
4589 LPCITEMIDLIST pidlLast
;
4591 /* get and use the parent folder to display correct context menu in all cases */
4592 if (SUCCEEDED(SHBindToParent(pidl_abs
, &IID_IShellFolder
, (LPVOID
*)&parentFolder
, &pidlLast
))) {
4593 if (ShellFolderContextMenu(parentFolder
, hwnd
, 1, &pidlLast
, pt
.x
, pt
.y
) == S_OK
)
4594 refresh_child(child
);
4596 IShellFolder_Release(parentFolder
);
4599 IMalloc_Free(Globals
.iMalloc
, pidl_abs
);
4605 case WM_MEASUREITEM
:
4607 if (!wparam
) /* Is the message menu-related? */
4608 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4613 case WM_INITMENUPOPUP
:
4614 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4617 update_view_menu(child
);
4620 case WM_MENUCHAR
: /* only supported by IContextMenu3 */
4622 LRESULT lResult
= 0;
4624 IContextMenu3_HandleMenuMsg2(s_pctxmenu3
, nmsg
, wparam
, lparam
, &lResult
);
4632 if (wparam
!= SIZE_MINIMIZED
)
4633 resize_tree(child
, LOWORD(lparam
), HIWORD(lparam
));
4637 return DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
4644 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4646 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(GetParent(hwnd
), GWLP_USERDATA
);
4647 Pane
* pane
= (Pane
*) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
4651 #ifndef _NO_EXTENSIONS
4658 child
->focus_pane
= pane
==&child
->right
? 1: 0;
4659 SendMessage(hwnd
, LB_SETSEL
, TRUE
, 1);
4660 /*TODO: check menu items */
4664 if (wparam
== VK_TAB
) {
4665 /*TODO: SetFocus(Globals.hdrivebar) */
4666 SetFocus(child
->focus_pane
? child
->left
.hwnd
: child
->right
.hwnd
);
4670 return CallWindowProc(g_orgTreeWndProc
, hwnd
, nmsg
, wparam
, lparam
);
4674 static void InitInstance(HINSTANCE hinstance
)
4676 static const TCHAR sFont
[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4683 INITCOMMONCONTROLSEX icc
= {
4684 sizeof(INITCOMMONCONTROLSEX
),
4690 setlocale(LC_COLLATE
, ""); /* set collating rules to local settings for compareName */
4692 InitCommonControlsEx(&icc
);
4695 /* register frame window class */
4697 wcFrame
.cbSize
= sizeof(WNDCLASSEX
);
4699 wcFrame
.lpfnWndProc
= FrameWndProc
;
4700 wcFrame
.cbClsExtra
= 0;
4701 wcFrame
.cbWndExtra
= 0;
4702 wcFrame
.hInstance
= hinstance
;
4703 wcFrame
.hIcon
= LoadIcon(hinstance
, MAKEINTRESOURCE(IDI_WINEFILE
));
4704 wcFrame
.hCursor
= LoadCursor(0, IDC_ARROW
);
4705 wcFrame
.hbrBackground
= 0;
4706 wcFrame
.lpszMenuName
= 0;
4707 wcFrame
.lpszClassName
= sWINEFILEFRAME
;
4708 wcFrame
.hIconSm
= (HICON
)LoadImage(hinstance
,
4709 MAKEINTRESOURCE(IDI_WINEFILE
),
4711 GetSystemMetrics(SM_CXSMICON
),
4712 GetSystemMetrics(SM_CYSMICON
),
4715 Globals
.hframeClass
= RegisterClassEx(&wcFrame
);
4718 /* register tree windows class */
4720 wcChild
.style
= CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
;
4721 wcChild
.lpfnWndProc
= ChildWndProc
;
4722 wcChild
.cbClsExtra
= 0;
4723 wcChild
.cbWndExtra
= 0;
4724 wcChild
.hInstance
= hinstance
;
4726 wcChild
.hCursor
= LoadCursor(0, IDC_ARROW
);
4727 wcChild
.hbrBackground
= 0;
4728 wcChild
.lpszMenuName
= 0;
4729 wcChild
.lpszClassName
= sWINEFILETREE
;
4731 hChildClass
= RegisterClass(&wcChild
);
4734 Globals
.haccel
= LoadAccelerators(hinstance
, MAKEINTRESOURCE(IDA_WINEFILE
));
4736 Globals
.hfont
= CreateFont(-MulDiv(8,GetDeviceCaps(hdc
,LOGPIXELSY
),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont
);
4740 Globals
.hInstance
= hinstance
;
4742 #ifdef _SHELL_FOLDERS
4744 CoGetMalloc(MEMCTX_TASK
, &Globals
.iMalloc
);
4745 SHGetDesktopFolder(&Globals
.iDesktop
);
4747 Globals
.cfStrFName
= RegisterClipboardFormatA(CFSTR_FILENAME
);
4749 Globals
.cfStrFName
= RegisterClipboardFormat(CFSTR_FILENAME
);
4753 /* load column strings */
4756 load_string(g_pos_names
[col
++], IDS_COL_NAME
);
4757 load_string(g_pos_names
[col
++], IDS_COL_SIZE
);
4758 load_string(g_pos_names
[col
++], IDS_COL_CDATE
);
4759 #ifndef _NO_EXTENSIONS
4760 load_string(g_pos_names
[col
++], IDS_COL_ADATE
);
4761 load_string(g_pos_names
[col
++], IDS_COL_MDATE
);
4762 load_string(g_pos_names
[col
++], IDS_COL_IDX
);
4763 load_string(g_pos_names
[col
++], IDS_COL_LINKS
);
4765 load_string(g_pos_names
[col
++], IDS_COL_ATTR
);
4766 #ifndef _NO_EXTENSIONS
4767 load_string(g_pos_names
[col
++], IDS_COL_SEC
);
4772 static void show_frame(HWND hwndParent
, int cmdshow
, LPCTSTR path
)
4774 static const TCHAR sMDICLIENT
[] = {'M','D','I','C','L','I','E','N','T','\0'};
4776 TCHAR buffer
[MAX_PATH
], b1
[BUFFER_LEN
];
4778 HMENU hMenuFrame
, hMenuWindow
;
4781 CLIENTCREATESTRUCT ccs
;
4783 if (Globals
.hMainWnd
)
4786 opts
= load_registry_settings();
4787 hMenuFrame
= LoadMenu(Globals
.hInstance
, MAKEINTRESOURCE(IDM_WINEFILE
));
4788 hMenuWindow
= GetSubMenu(hMenuFrame
, GetMenuItemCount(hMenuFrame
)-2);
4790 Globals
.hMenuFrame
= hMenuFrame
;
4791 Globals
.hMenuView
= GetSubMenu(hMenuFrame
, 3);
4792 Globals
.hMenuOptions
= GetSubMenu(hMenuFrame
, 4);
4794 ccs
.hWindowMenu
= hMenuWindow
;
4795 ccs
.idFirstChild
= IDW_FIRST_CHILD
;
4798 /* create main window */
4799 Globals
.hMainWnd
= CreateWindowEx(0, (LPCTSTR
)(int)Globals
.hframeClass
, RS(b1
,IDS_WINE_FILE
), WS_OVERLAPPEDWINDOW
,
4800 opts
.start_x
, opts
.start_y
, opts
.width
, opts
.height
,
4801 hwndParent
, Globals
.hMenuFrame
, Globals
.hInstance
, 0/*lpParam*/);
4804 Globals
.hmdiclient
= CreateWindowEx(0, sMDICLIENT
, NULL
,
4805 WS_CHILD
|WS_CLIPCHILDREN
|WS_VSCROLL
|WS_HSCROLL
|WS_VISIBLE
|WS_BORDER
,
4807 Globals
.hMainWnd
, 0, Globals
.hInstance
, &ccs
);
4809 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_DRIVE_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4810 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_SAVESETTINGS
, MF_BYCOMMAND
);
4815 TBBUTTON toolbarBtns
[] = {
4816 {0, 0, 0, BTNS_SEP
, {0, 0}, 0, 0},
4817 {0, ID_WINDOW_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4818 {1, ID_WINDOW_CASCADE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4819 {2, ID_WINDOW_TILE_HORZ
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4820 {3, ID_WINDOW_TILE_VERT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4822 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4823 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4826 Globals
.htoolbar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
,
4827 IDW_TOOLBAR
, 2, Globals
.hInstance
, IDB_TOOLBAR
, toolbarBtns
,
4828 sizeof(toolbarBtns
)/sizeof(TBBUTTON
), 16, 15, 16, 15, sizeof(TBBUTTON
));
4829 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_TOOL_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4832 Globals
.hstatusbar
= CreateStatusWindow(WS_CHILD
|WS_VISIBLE
, 0, Globals
.hMainWnd
, IDW_STATUSBAR
);
4833 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
4835 /* CreateStatusWindow does not accept WS_BORDER
4836 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
4837 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
4838 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
4840 /*TODO: read paths from registry */
4842 if (!path
|| !*path
) {
4843 GetCurrentDirectory(MAX_PATH
, buffer
);
4847 ShowWindow(Globals
.hMainWnd
, cmdshow
);
4849 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4850 /* Shell Namespace as default: */
4851 child
= alloc_child_window(path
, get_path_pidl(path
,Globals
.hMainWnd
), Globals
.hMainWnd
);
4853 child
= alloc_child_window(path
, NULL
, Globals
.hMainWnd
);
4856 child
->pos
.showCmd
= SW_SHOWMAXIMIZED
;
4857 child
->pos
.rcNormalPosition
.left
= 0;
4858 child
->pos
.rcNormalPosition
.top
= 0;
4859 child
->pos
.rcNormalPosition
.right
= 320;
4860 child
->pos
.rcNormalPosition
.bottom
= 280;
4862 if (!create_child_window(child
))
4865 SetWindowPlacement(child
->hwnd
, &child
->pos
);
4867 Globals
.himl
= ImageList_LoadBitmap(Globals
.hInstance
, MAKEINTRESOURCE(IDB_IMAGES
), 16, 0, RGB(0,255,0));
4869 Globals
.prescan_node
= FALSE
;
4871 UpdateWindow(Globals
.hMainWnd
);
4873 if (path
&& path
[0])
4876 TCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
4877 TCHAR fullname
[_MAX_FNAME
+_MAX_EXT
+1];
4879 memset(name
,0,sizeof(name
));
4880 memset(name
,0,sizeof(ext
));
4881 _tsplitpath(path
, drv
, dir
, name
, ext
);
4884 count
= SendMessage(child
->right
.hwnd
, LB_GETCOUNT
, 0, 0);
4885 lstrcpy(fullname
,name
);
4886 lstrcat(fullname
,ext
);
4888 for (index
= 0; index
< count
; index
++)
4890 Entry
* entry
= (Entry
*) SendMessage(child
->right
.hwnd
, LB_GETITEMDATA
, index
, 0);
4891 if (lstrcmp(entry
->data
.cFileName
,fullname
)==0 ||
4892 lstrcmp(entry
->data
.cAlternateFileName
,fullname
)==0)
4894 SendMessage(child
->right
.hwnd
, LB_SETCURSEL
, index
, 0);
4895 SetFocus(child
->right
.hwnd
);
4903 static void ExitInstance(void)
4905 #ifdef _SHELL_FOLDERS
4906 IShellFolder_Release(Globals
.iDesktop
);
4907 IMalloc_Release(Globals
.iMalloc
);
4911 DeleteObject(Globals
.hfont
);
4912 ImageList_Destroy(Globals
.himl
);
4915 #ifdef _NO_EXTENSIONS
4917 /* search for already running win[e]files */
4919 static int g_foundPrevInstance
= 0;
4921 static BOOL CALLBACK
EnumWndProc(HWND hwnd
, LPARAM lparam
)
4925 GetClassName(hwnd
, cls
, 128);
4927 if (!lstrcmp(cls
, (LPCTSTR
)lparam
)) {
4928 g_foundPrevInstance
++;
4935 /* search for window of given class name to allow only one running instance */
4936 static int find_window_class(LPCTSTR classname
)
4938 EnumWindows(EnumWndProc
, (LPARAM
)classname
);
4940 if (g_foundPrevInstance
)
4948 static int winefile_main(HINSTANCE hinstance
, int cmdshow
, LPCTSTR path
)
4952 InitInstance(hinstance
);
4954 show_frame(0, cmdshow
, path
);
4956 while(GetMessage(&msg
, 0, 0, 0)) {
4957 if (Globals
.hmdiclient
&& TranslateMDISysAccel(Globals
.hmdiclient
, &msg
))
4960 if (Globals
.hMainWnd
&& TranslateAccelerator(Globals
.hMainWnd
, Globals
.haccel
, &msg
))
4963 TranslateMessage(&msg
);
4964 DispatchMessage(&msg
);
4973 #if defined(UNICODE) && defined(_MSC_VER)
4974 int APIENTRY
wWinMain(HINSTANCE hinstance
, HINSTANCE previnstance
, LPWSTR cmdline
, int cmdshow
)
4976 int APIENTRY
WinMain(HINSTANCE hinstance
, HINSTANCE previnstance
, LPSTR cmdline
, int cmdshow
)
4979 #ifdef _NO_EXTENSIONS
4980 if (find_window_class(sWINEFILEFRAME
))
4984 #if defined(UNICODE) && !defined(_MSC_VER)
4985 { /* convert ANSI cmdline into WCS path string */
4986 TCHAR buffer
[MAX_PATH
];
4987 MultiByteToWideChar(CP_ACP
, 0, cmdline
, -1, buffer
, MAX_PATH
);
4988 winefile_main(hinstance
, cmdshow
, buffer
);
4991 winefile_main(hinstance
, cmdshow
, cmdline
);