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 WCHAR 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 WCHAR cap
[20], text
[1024];
249 LoadStringW(Globals
.hInstance
, IDS_LICENSE
, text
, 1024);
250 LoadStringW(Globals
.hInstance
, IDS_LICENSE_CAPTION
, cap
, 20);
251 MessageBoxW(Wnd
, text
, cap
, MB_ICONINFORMATION
| MB_OK
);
254 static VOID
WineWarranty(HWND Wnd
)
256 WCHAR cap
[20], text
[1024];
257 LoadStringW(Globals
.hInstance
, IDS_WARRANTY
, text
, 1024);
258 LoadStringW(Globals
.hInstance
, IDS_WARRANTY_CAPTION
, cap
, 20);
259 MessageBoxW(Wnd
, text
, cap
, MB_ICONEXCLAMATION
| MB_OK
);
262 static inline BOOL
get_check(HWND hwnd
, INT id
)
264 return BST_CHECKED
&SendMessageW(GetDlgItem(hwnd
, id
), BM_GETSTATE
, 0, 0);
267 static inline INT
set_check(HWND hwnd
, INT id
, BOOL on
)
269 return SendMessageW(GetDlgItem(hwnd
, id
), BM_SETCHECK
, on
?BST_CHECKED
:BST_UNCHECKED
, 0);
272 static inline void choose_font(HWND hwnd
)
274 WCHAR dlg_name
[BUFFER_LEN
], dlg_info
[BUFFER_LEN
];
278 HDC hdc
= GetDC(hwnd
);
279 chFont
.lStructSize
= sizeof(CHOOSEFONT
);
280 chFont
.hwndOwner
= hwnd
;
282 chFont
.lpLogFont
= &lFont
;
283 chFont
.Flags
= CF_SCREENFONTS
| CF_FORCEFONTEXIST
| CF_LIMITSIZE
| CF_NOSCRIPTSEL
;
284 chFont
.rgbColors
= RGB(0,0,0);
285 chFont
.lCustData
= 0;
286 chFont
.lpfnHook
= NULL
;
287 chFont
.lpTemplateName
= NULL
;
288 chFont
.hInstance
= Globals
.hInstance
;
289 chFont
.lpszStyle
= NULL
;
290 chFont
.nFontType
= SIMULATED_FONTTYPE
;
292 chFont
.nSizeMax
= 24;
294 if (ChooseFontW(&chFont
)) {
298 DeleteObject(Globals
.hfont
);
299 Globals
.hfont
= CreateFontIndirectW(&lFont
);
300 hFontOld
= SelectObject(hdc
, Globals
.hfont
);
301 GetTextExtentPoint32W(hdc
, sSpace
, 1, &Globals
.spaceSize
);
303 /* change font in all open child windows */
304 for(childWnd
=GetWindow(Globals
.hmdiclient
,GW_CHILD
); childWnd
; childWnd
=GetNextWindow(childWnd
,GW_HWNDNEXT
)) {
305 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtrW(childWnd
, GWLP_USERDATA
);
306 SendMessageW(child
->left
.hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, TRUE
);
307 SendMessageW(child
->right
.hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, TRUE
);
308 SendMessageW(child
->left
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
309 SendMessageW(child
->right
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
310 InvalidateRect(child
->left
.hwnd
, NULL
, TRUE
);
311 InvalidateRect(child
->right
.hwnd
, NULL
, TRUE
);
314 SelectObject(hdc
, hFontOld
);
316 else if (CommDlgExtendedError()) {
317 LoadStringW(Globals
.hInstance
, IDS_FONT_SEL_DLG_NAME
, dlg_name
, BUFFER_LEN
);
318 LoadStringW(Globals
.hInstance
, IDS_FONT_SEL_ERROR
, dlg_info
, BUFFER_LEN
);
319 MessageBoxW(hwnd
, dlg_info
, dlg_name
, MB_OK
);
322 ReleaseDC(hwnd
, hdc
);
329 /* call vswprintf() in msvcrt.dll */
330 /*TODO: fix swprintf() in non-msvcrt mode, so that this dynamic linking function can be removed */
331 static int msvcrt_swprintf(WCHAR
* buffer
, const WCHAR
* fmt
, ...)
333 static int (__cdecl
*pvswprintf
)(WCHAR
*, const WCHAR
*, va_list) = NULL
;
338 HMODULE hModMsvcrt
= LoadLibraryA("msvcrt");
339 pvswprintf
= (int(__cdecl
*)(WCHAR
*,const WCHAR
*,va_list)) GetProcAddress(hModMsvcrt
, "vswprintf");
343 ret
= (*pvswprintf
)(buffer
, fmt
, ap
);
349 static LPCWSTR
my_wcsrchr(LPCWSTR str
, WCHAR c
)
364 #define _tcsrchr my_wcsrchr
366 #define _tcsrchr strrchr
369 #endif /* __WINE__ */
372 /* allocate and initialise a directory entry */
373 static Entry
* alloc_entry(void)
375 Entry
* entry
= HeapAlloc(GetProcessHeap(), 0, sizeof(Entry
));
377 #ifdef _SHELL_FOLDERS
379 entry
->folder
= NULL
;
386 /* free a directory entry */
387 static void free_entry(Entry
* entry
)
389 #ifdef _SHELL_FOLDERS
390 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
391 DestroyIcon(entry
->hicon
);
393 if (entry
->folder
&& entry
->folder
!=Globals
.iDesktop
)
394 IShellFolder_Release(entry
->folder
);
397 IMalloc_Free(Globals
.iMalloc
, entry
->pidl
);
400 HeapFree(GetProcessHeap(), 0, entry
);
403 /* recursively free all child entries */
404 static void free_entries(Entry
* dir
)
406 Entry
*entry
, *next
=dir
->down
;
422 static void read_directory_win(Entry
* dir
, LPCTSTR path
)
424 Entry
* first_entry
= NULL
;
428 int level
= dir
->level
+ 1;
429 WIN32_FIND_DATA w32fd
;
431 #ifndef _NO_EXTENSIONS
435 TCHAR buffer
[MAX_PATH
], *p
;
436 for(p
=buffer
; *path
; )
443 hFind
= FindFirstFile(buffer
, &w32fd
);
445 if (hFind
!= INVALID_HANDLE_VALUE
) {
447 #ifdef _NO_EXTENSIONS
448 /* hide directory entry "." */
449 if (w32fd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
450 LPCTSTR name
= w32fd
.cFileName
;
452 if (name
[0]=='.' && name
[1]=='\0')
456 entry
= alloc_entry();
464 memcpy(&entry
->data
, &w32fd
, sizeof(WIN32_FIND_DATA
));
467 entry
->expanded
= FALSE
;
468 entry
->scanned
= FALSE
;
469 entry
->level
= level
;
471 #ifndef _NO_EXTENSIONS
472 entry
->etype
= ET_WINDOWS
;
473 entry
->bhfi_valid
= FALSE
;
475 lstrcpy(p
, entry
->data
.cFileName
);
477 hFile
= CreateFile(buffer
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
478 0, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0);
480 if (hFile
!= INVALID_HANDLE_VALUE
) {
481 if (GetFileInformationByHandle(hFile
, &entry
->bhfi
))
482 entry
->bhfi_valid
= TRUE
;
489 } while(FindNextFile(hFind
, &w32fd
));
497 dir
->down
= first_entry
;
502 static Entry
* find_entry_win(Entry
* dir
, LPCTSTR name
)
506 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
508 LPCTSTR q
= entry
->data
.cFileName
;
511 if (!*p
|| *p
== '\\' || *p
== '/')
513 } while(tolower(*p
++) == tolower(*q
++));
516 q
= entry
->data
.cAlternateFileName
;
519 if (!*p
|| *p
== '\\' || *p
== '/')
521 } while(tolower(*p
++) == tolower(*q
++));
528 static Entry
* read_tree_win(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
530 TCHAR buffer
[MAX_PATH
];
531 Entry
* entry
= &root
->entry
;
535 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
537 #ifndef _NO_EXTENSIONS
538 entry
->etype
= ET_WINDOWS
;
542 while(*s
&& *s
!= '\\' && *s
!= '/')
545 while(*s
== '\\' || *s
== '/')
551 read_directory(entry
, buffer
, sortOrder
, hwnd
);
554 entry
->expanded
= TRUE
;
559 entry
= find_entry_win(entry
, s
);
562 SetCursor(old_cursor
);
568 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
570 static BOOL
time_to_filetime(const time_t* t
, FILETIME
* ftime
)
572 struct tm
* tm
= gmtime(t
);
578 stime
.wYear
= tm
->tm_year
+1900;
579 stime
.wMonth
= tm
->tm_mon
+1;
580 /* stime.wDayOfWeek */
581 stime
.wDay
= tm
->tm_mday
;
582 stime
.wHour
= tm
->tm_hour
;
583 stime
.wMinute
= tm
->tm_min
;
584 stime
.wSecond
= tm
->tm_sec
;
586 return SystemTimeToFileTime(&stime
, ftime
);
589 static void read_directory_unix(Entry
* dir
, LPCTSTR path
)
591 Entry
* first_entry
= NULL
;
596 int level
= dir
->level
+ 1;
598 char cpath
[MAX_PATH
];
600 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, cpath
, MAX_PATH
, NULL
, NULL
);
602 const char* cpath
= path
;
605 pdir
= opendir(cpath
);
610 char buffer
[MAX_PATH
], *p
;
613 for(p
=buffer
,s
=cpath
; *s
; )
616 if (p
==buffer
|| p
[-1]!='/')
619 while((ent
=readdir(pdir
))) {
620 entry
= alloc_entry();
628 entry
->etype
= ET_UNIX
;
630 strcpy(p
, ent
->d_name
);
632 MultiByteToWideChar(CP_UNIXCP
, 0, p
, -1, entry
->data
.cFileName
, MAX_PATH
);
634 lstrcpy(entry
->data
.cFileName
, p
);
637 if (!stat(buffer
, &st
)) {
638 entry
->data
.dwFileAttributes
= p
[0]=='.'? FILE_ATTRIBUTE_HIDDEN
: 0;
640 if (S_ISDIR(st
.st_mode
))
641 entry
->data
.dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
643 entry
->data
.nFileSizeLow
= st
.st_size
& 0xFFFFFFFF;
644 entry
->data
.nFileSizeHigh
= st
.st_size
>> 32;
646 memset(&entry
->data
.ftCreationTime
, 0, sizeof(FILETIME
));
647 time_to_filetime(&st
.st_atime
, &entry
->data
.ftLastAccessTime
);
648 time_to_filetime(&st
.st_mtime
, &entry
->data
.ftLastWriteTime
);
650 entry
->bhfi
.nFileIndexLow
= ent
->d_ino
;
651 entry
->bhfi
.nFileIndexHigh
= 0;
653 entry
->bhfi
.nNumberOfLinks
= st
.st_nlink
;
655 entry
->bhfi_valid
= TRUE
;
657 entry
->data
.nFileSizeLow
= 0;
658 entry
->data
.nFileSizeHigh
= 0;
659 entry
->bhfi_valid
= FALSE
;
664 entry
->expanded
= FALSE
;
665 entry
->scanned
= FALSE
;
666 entry
->level
= level
;
677 dir
->down
= first_entry
;
681 static Entry
* find_entry_unix(Entry
* dir
, LPCTSTR name
)
685 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
687 LPCTSTR q
= entry
->data
.cFileName
;
690 if (!*p
|| *p
== '/')
692 } while(*p
++ == *q
++);
698 static Entry
* read_tree_unix(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
700 TCHAR buffer
[MAX_PATH
];
701 Entry
* entry
= &root
->entry
;
705 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
707 entry
->etype
= ET_UNIX
;
710 while(*s
&& *s
!= '/')
719 read_directory(entry
, buffer
, sortOrder
, hwnd
);
722 entry
->expanded
= TRUE
;
727 entry
= find_entry_unix(entry
, s
);
730 SetCursor(old_cursor
);
735 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
738 #ifdef _SHELL_FOLDERS
741 #define get_strret get_strretW
742 #define path_from_pidl path_from_pidlW
744 #define get_strret get_strretA
745 #define path_from_pidl path_from_pidlA
749 static void free_strret(STRRET
* str
)
751 if (str
->uType
== STRRET_WSTR
)
752 IMalloc_Free(Globals
.iMalloc
, str
->UNION_MEMBER(pOleStr
));
758 static LPSTR
strcpyn(LPSTR dest
, LPCSTR source
, size_t count
)
763 for(s
=source
; count
&&(*d
++=*s
++); )
769 static void get_strretA(STRRET
* str
, const SHITEMID
* shiid
, LPSTR buffer
, int len
)
773 WideCharToMultiByte(CP_ACP
, 0, str
->UNION_MEMBER(pOleStr
), -1, buffer
, len
, NULL
, NULL
);
777 strcpyn(buffer
, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), len
);
781 strcpyn(buffer
, str
->UNION_MEMBER(cStr
), len
);
785 static HRESULT
path_from_pidlA(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPSTR buffer
, int len
)
789 /* SHGDN_FORPARSING: get full path of id list */
790 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, SHGDN_FORPARSING
, &str
);
793 get_strretA(&str
, &pidl
->mkid
, buffer
, len
);
803 static LPWSTR
wcscpyn(LPWSTR dest
, LPCWSTR source
, size_t count
)
808 for(s
=source
; count
&&(*d
++=*s
++); )
814 static void get_strretW(STRRET
* str
, const SHITEMID
* shiid
, LPWSTR buffer
, int len
)
818 wcscpyn(buffer
, str
->UNION_MEMBER(pOleStr
), len
);
822 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), -1, buffer
, len
);
826 MultiByteToWideChar(CP_ACP
, 0, str
->UNION_MEMBER(cStr
), -1, buffer
, len
);
831 static HRESULT
name_from_pidl(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPTSTR buffer
, int len
, SHGDNF flags
)
835 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, flags
, &str
);
838 get_strret(&str
, &pidl
->mkid
, buffer
, len
);
847 static HRESULT
path_from_pidlW(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPWSTR buffer
, int len
)
851 /* SHGDN_FORPARSING: get full path of id list */
852 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, SHGDN_FORPARSING
, &str
);
855 get_strretW(&str
, &pidl
->mkid
, buffer
, len
);
864 /* create an item id list from a file system path */
866 static LPITEMIDLIST
get_path_pidl(LPTSTR path
, HWND hwnd
)
873 LPWSTR buffer
= path
;
875 WCHAR buffer
[MAX_PATH
];
876 MultiByteToWideChar(CP_ACP
, 0, path
, -1, buffer
, MAX_PATH
);
879 hr
= IShellFolder_ParseDisplayName(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
887 /* convert an item id list from relative to absolute (=relative to the desktop) format */
889 static LPITEMIDLIST
get_to_absolute_pidl(Entry
* entry
, HWND hwnd
)
891 if (entry
->up
&& entry
->up
->etype
==ET_SHELL
) {
892 IShellFolder
* folder
= entry
->up
->folder
;
893 WCHAR buffer
[MAX_PATH
];
895 HRESULT hr
= path_from_pidlW(folder
, entry
->pidl
, buffer
, MAX_PATH
);
901 hr
= IShellFolder_ParseDisplayName(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
906 } else if (entry
->etype
== ET_WINDOWS
) {
907 TCHAR path
[MAX_PATH
];
909 get_path(entry
, path
);
911 return get_path_pidl(path
, hwnd
);
912 } else if (entry
->pidl
)
913 return ILClone(entry
->pidl
);
919 static HICON
extract_icon(IShellFolder
* folder
, LPCITEMIDLIST pidl
)
921 IExtractIcon
* pExtract
;
923 if (SUCCEEDED(IShellFolder_GetUIObjectOf(folder
, 0, 1, (LPCITEMIDLIST
*)&pidl
, &IID_IExtractIcon
, 0, (LPVOID
*)&pExtract
))) {
924 TCHAR path
[_MAX_PATH
];
929 if (SUCCEEDED(IExtractIconW_GetIconLocation(pExtract
, GIL_FORSHELL
, path
, _MAX_PATH
, &idx
, &flags
))) {
930 if (!(flags
& GIL_NOTFILENAME
)) {
932 idx
= 0; /* special case for some control panel applications */
934 if ((int)ExtractIconEx(path
, idx
, 0, &hicon
, 1) > 0)
935 flags
&= ~GIL_DONTCACHE
;
937 HICON hIconLarge
= 0;
939 HRESULT hr
= IExtractIconW_Extract(pExtract
, path
, idx
, &hIconLarge
, &hicon
, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON
)));
942 DestroyIcon(hIconLarge
);
953 static Entry
* find_entry_shell(Entry
* dir
, LPCITEMIDLIST pidl
)
957 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
958 if (entry
->pidl
->mkid
.cb
== pidl
->mkid
.cb
&&
959 !memcmp(entry
->pidl
, pidl
, entry
->pidl
->mkid
.cb
))
966 static Entry
* read_tree_shell(Root
* root
, LPITEMIDLIST pidl
, SORT_ORDER sortOrder
, HWND hwnd
)
968 Entry
* entry
= &root
->entry
;
970 LPITEMIDLIST next_pidl
= pidl
;
971 IShellFolder
* folder
;
972 IShellFolder
* child
= NULL
;
975 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
977 #ifndef _NO_EXTENSIONS
978 entry
->etype
= ET_SHELL
;
981 folder
= Globals
.iDesktop
;
984 entry
->pidl
= next_pidl
;
985 entry
->folder
= folder
;
990 /* copy first element of item idlist */
991 next_pidl
= IMalloc_Alloc(Globals
.iMalloc
, pidl
->mkid
.cb
+sizeof(USHORT
));
992 memcpy(next_pidl
, pidl
, pidl
->mkid
.cb
);
993 ((LPITEMIDLIST
)((LPBYTE
)next_pidl
+pidl
->mkid
.cb
))->mkid
.cb
= 0;
995 hr
= IShellFolder_BindToObject(folder
, next_pidl
, 0, &IID_IShellFolder
, (void**)&child
);
999 read_directory(entry
, NULL
, sortOrder
, hwnd
);
1002 entry
->expanded
= TRUE
;
1004 next
= find_entry_shell(entry
, next_pidl
);
1011 /* go to next element */
1012 pidl
= (LPITEMIDLIST
) ((LPBYTE
)pidl
+pidl
->mkid
.cb
);
1015 SetCursor(old_cursor
);
1021 static void fill_w32fdata_shell(IShellFolder
* folder
, LPCITEMIDLIST pidl
, SFGAOF attribs
, WIN32_FIND_DATA
* w32fdata
)
1023 if (!(attribs
& SFGAO_FILESYSTEM
) ||
1024 FAILED(SHGetDataFromIDList(folder
, pidl
, SHGDFIL_FINDDATA
, w32fdata
, sizeof(WIN32_FIND_DATA
)))) {
1025 WIN32_FILE_ATTRIBUTE_DATA fad
;
1026 IDataObject
* pDataObj
;
1028 STGMEDIUM medium
= {0, {0}, 0};
1029 FORMATETC fmt
= {Globals
.cfStrFName
, 0, DVASPECT_CONTENT
, -1, TYMED_HGLOBAL
};
1031 HRESULT hr
= IShellFolder_GetUIObjectOf(folder
, 0, 1, &pidl
, &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
1033 if (SUCCEEDED(hr
)) {
1034 hr
= IDataObject_GetData(pDataObj
, &fmt
, &medium
);
1036 IDataObject_Release(pDataObj
);
1038 if (SUCCEEDED(hr
)) {
1039 LPCTSTR path
= (LPCTSTR
)GlobalLock(medium
.UNION_MEMBER(hGlobal
));
1040 UINT sem_org
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1042 if (GetFileAttributesEx(path
, GetFileExInfoStandard
, &fad
)) {
1043 w32fdata
->dwFileAttributes
= fad
.dwFileAttributes
;
1044 w32fdata
->ftCreationTime
= fad
.ftCreationTime
;
1045 w32fdata
->ftLastAccessTime
= fad
.ftLastAccessTime
;
1046 w32fdata
->ftLastWriteTime
= fad
.ftLastWriteTime
;
1048 if (!(fad
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)) {
1049 w32fdata
->nFileSizeLow
= fad
.nFileSizeLow
;
1050 w32fdata
->nFileSizeHigh
= fad
.nFileSizeHigh
;
1054 SetErrorMode(sem_org
);
1056 GlobalUnlock(medium
.UNION_MEMBER(hGlobal
));
1057 GlobalFree(medium
.UNION_MEMBER(hGlobal
));
1062 if (attribs
& (SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
))
1063 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
1065 if (attribs
& SFGAO_READONLY
)
1066 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_READONLY
;
1068 if (attribs
& SFGAO_COMPRESSED
)
1069 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_COMPRESSED
;
1073 static void read_directory_shell(Entry
* dir
, HWND hwnd
)
1075 IShellFolder
* folder
= dir
->folder
;
1076 int level
= dir
->level
+ 1;
1079 IShellFolder
* child
;
1080 IEnumIDList
* idlist
;
1082 Entry
* first_entry
= NULL
;
1089 hr
= IShellFolder_EnumObjects(folder
, hwnd
, SHCONTF_FOLDERS
|SHCONTF_NONFOLDERS
|SHCONTF_INCLUDEHIDDEN
|SHCONTF_SHAREABLE
|SHCONTF_STORAGE
, &idlist
);
1091 if (SUCCEEDED(hr
)) {
1093 #define FETCH_ITEM_COUNT 32
1094 LPITEMIDLIST pidls
[FETCH_ITEM_COUNT
];
1099 memset(pidls
, 0, sizeof(pidls
));
1101 hr
= IEnumIDList_Next(idlist
, FETCH_ITEM_COUNT
, pidls
, &cnt
);
1108 for(n
=0; n
<cnt
; ++n
) {
1109 entry
= alloc_entry();
1112 first_entry
= entry
;
1117 memset(&entry
->data
, 0, sizeof(WIN32_FIND_DATA
));
1118 entry
->bhfi_valid
= FALSE
;
1120 attribs
= ~SFGAO_FILESYSTEM
; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
1122 hr
= IShellFolder_GetAttributesOf(folder
, 1, (LPCITEMIDLIST
*)&pidls
[n
], &attribs
);
1124 if (SUCCEEDED(hr
)) {
1125 if (attribs
!= (SFGAOF
)~SFGAO_FILESYSTEM
) {
1126 fill_w32fdata_shell(folder
, pidls
[n
], attribs
, &entry
->data
);
1128 entry
->bhfi_valid
= TRUE
;
1134 entry
->pidl
= pidls
[n
];
1136 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1137 hr
= IShellFolder_BindToObject(folder
, pidls
[n
], 0, &IID_IShellFolder
, (void**)&child
);
1140 entry
->folder
= child
;
1142 entry
->folder
= NULL
;
1145 entry
->folder
= NULL
;
1147 if (!entry
->data
.cFileName
[0])
1148 /*hr = */name_from_pidl(folder
, pidls
[n
], entry
->data
.cFileName
, MAX_PATH
, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1150 /* get display icons for files and virtual objects */
1151 if (!(entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ||
1152 !(attribs
& SFGAO_FILESYSTEM
)) {
1153 entry
->hicon
= extract_icon(folder
, pidls
[n
]);
1156 entry
->hicon
= (HICON
)-1; /* don't try again later */
1161 entry
->expanded
= FALSE
;
1162 entry
->scanned
= FALSE
;
1163 entry
->level
= level
;
1165 #ifndef _NO_EXTENSIONS
1166 entry
->etype
= ET_SHELL
;
1167 entry
->bhfi_valid
= FALSE
;
1174 IEnumIDList_Release(idlist
);
1180 dir
->down
= first_entry
;
1181 dir
->scanned
= TRUE
;
1184 #endif /* _SHELL_FOLDERS */
1187 /* sort order for different directory/file types */
1196 /* distinguish between ".", ".." and any other directory names */
1197 static int TypeOrderFromDirname(LPCTSTR name
)
1199 if (name
[0] == '.') {
1200 if (name
[1] == '\0')
1201 return TO_DOT
; /* "." */
1203 if (name
[1]=='.' && name
[2]=='\0')
1204 return TO_DOTDOT
; /* ".." */
1207 return TO_OTHER_DIR
; /* anything else */
1210 /* directories first... */
1211 static int compareType(const WIN32_FIND_DATA
* fd1
, const WIN32_FIND_DATA
* fd2
)
1213 int order1
= fd1
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1214 int order2
= fd2
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1216 /* Handle "." and ".." as special case and move them at the very first beginning. */
1217 if (order1
==TO_DIR
&& order2
==TO_DIR
) {
1218 order1
= TypeOrderFromDirname(fd1
->cFileName
);
1219 order2
= TypeOrderFromDirname(fd2
->cFileName
);
1222 return order2
==order1
? 0: order1
<order2
? -1: 1;
1226 static int compareName(const void* arg1
, const void* arg2
)
1228 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1229 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1231 int cmp
= compareType(fd1
, fd2
);
1235 return lstrcmpi(fd1
->cFileName
, fd2
->cFileName
);
1238 static int compareExt(const void* arg1
, const void* arg2
)
1240 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1241 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1242 const TCHAR
*name1
, *name2
, *ext1
, *ext2
;
1244 int cmp
= compareType(fd1
, fd2
);
1248 name1
= fd1
->cFileName
;
1249 name2
= fd2
->cFileName
;
1251 ext1
= _tcsrchr(name1
, '.');
1252 ext2
= _tcsrchr(name2
, '.');
1264 cmp
= lstrcmpi(ext1
, ext2
);
1268 return lstrcmpi(name1
, name2
);
1271 static int compareSize(const void* arg1
, const void* arg2
)
1273 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1274 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1276 int cmp
= compareType(fd1
, fd2
);
1280 cmp
= fd2
->nFileSizeHigh
- fd1
->nFileSizeHigh
;
1287 cmp
= fd2
->nFileSizeLow
- fd1
->nFileSizeLow
;
1289 return cmp
<0? -1: cmp
>0? 1: 0;
1292 static int compareDate(const void* arg1
, const void* arg2
)
1294 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1295 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1297 int cmp
= compareType(fd1
, fd2
);
1301 return CompareFileTime(&fd2
->ftLastWriteTime
, &fd1
->ftLastWriteTime
);
1305 static int (*sortFunctions
[])(const void* arg1
, const void* arg2
) = {
1306 compareName
, /* SORT_NAME */
1307 compareExt
, /* SORT_EXT */
1308 compareSize
, /* SORT_SIZE */
1309 compareDate
/* SORT_DATE */
1313 static void SortDirectory(Entry
* dir
, SORT_ORDER sortOrder
)
1315 Entry
* entry
= dir
->down
;
1320 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1324 array
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(Entry
*));
1327 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1330 /* call qsort with the appropriate compare function */
1331 qsort(array
, len
, sizeof(array
[0]), sortFunctions
[sortOrder
]);
1333 dir
->down
= array
[0];
1335 for(p
=array
; --len
; p
++)
1340 HeapFree(GetProcessHeap(), 0, array
);
1345 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
1347 TCHAR buffer
[MAX_PATH
];
1352 #ifdef _SHELL_FOLDERS
1353 if (dir
->etype
== ET_SHELL
)
1355 read_directory_shell(dir
, hwnd
);
1357 if (Globals
.prescan_node
) {
1366 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1367 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1368 read_directory_shell(entry
, hwnd
);
1369 SortDirectory(entry
, sortOrder
);
1375 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1376 if (dir
->etype
== ET_UNIX
)
1378 read_directory_unix(dir
, path
);
1380 if (Globals
.prescan_node
) {
1389 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1390 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1391 lstrcpy(d
, entry
->data
.cFileName
);
1392 read_directory_unix(entry
, buffer
);
1393 SortDirectory(entry
, sortOrder
);
1400 read_directory_win(dir
, path
);
1402 if (Globals
.prescan_node
) {
1411 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1412 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1413 lstrcpy(d
, entry
->data
.cFileName
);
1414 read_directory_win(entry
, buffer
);
1415 SortDirectory(entry
, sortOrder
);
1420 SortDirectory(dir
, sortOrder
);
1424 static Entry
* read_tree(Root
* root
, LPCTSTR path
, LPITEMIDLIST pidl
, LPTSTR drv
, SORT_ORDER sortOrder
, HWND hwnd
)
1426 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1427 static const TCHAR sSlash
[] = {'/', '\0'};
1429 static const TCHAR sBackslash
[] = {'\\', '\0'};
1431 #ifdef _SHELL_FOLDERS
1434 /* read shell namespace tree */
1435 root
->drive_type
= DRIVE_UNKNOWN
;
1438 load_string(root
->volname
, IDS_DESKTOP
);
1440 load_string(root
->fs
, IDS_SHELL
);
1442 return read_tree_shell(root
, pidl
, sortOrder
, hwnd
);
1446 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1449 /* read unix file system tree */
1450 root
->drive_type
= GetDriveType(path
);
1452 lstrcat(drv
, sSlash
);
1453 load_string(root
->volname
, IDS_ROOT_FS
);
1455 load_string(root
->fs
, IDS_UNIXFS
);
1457 lstrcpy(root
->path
, sSlash
);
1459 return read_tree_unix(root
, path
, sortOrder
, hwnd
);
1463 /* read WIN32 file system tree */
1464 root
->drive_type
= GetDriveType(path
);
1466 lstrcat(drv
, sBackslash
);
1467 GetVolumeInformation(drv
, root
->volname
, _MAX_FNAME
, 0, 0, &root
->fs_flags
, root
->fs
, _MAX_DIR
);
1469 lstrcpy(root
->path
, drv
);
1471 return read_tree_win(root
, path
, sortOrder
, hwnd
);
1475 /* flags to filter different file types */
1477 TF_DIRECTORIES
= 0x01,
1479 TF_DOCUMENTS
= 0x04,
1486 static ChildWnd
* alloc_child_window(LPCTSTR path
, LPITEMIDLIST pidl
, HWND hwnd
)
1488 TCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
1489 TCHAR dir_path
[MAX_PATH
];
1490 TCHAR b1
[BUFFER_LEN
];
1491 static const TCHAR sAsterics
[] = {'*', '\0'};
1493 ChildWnd
* child
= HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd
));
1494 Root
* root
= &child
->root
;
1497 memset(child
, 0, sizeof(ChildWnd
));
1499 child
->left
.treePane
= TRUE
;
1500 child
->left
.visible_cols
= 0;
1502 child
->right
.treePane
= FALSE
;
1503 #ifndef _NO_EXTENSIONS
1504 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_INDEX
|COL_LINKS
;
1506 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
;
1509 child
->pos
.length
= sizeof(WINDOWPLACEMENT
);
1510 child
->pos
.flags
= 0;
1511 child
->pos
.showCmd
= SW_SHOWNORMAL
;
1512 child
->pos
.rcNormalPosition
.left
= CW_USEDEFAULT
;
1513 child
->pos
.rcNormalPosition
.top
= CW_USEDEFAULT
;
1514 child
->pos
.rcNormalPosition
.right
= CW_USEDEFAULT
;
1515 child
->pos
.rcNormalPosition
.bottom
= CW_USEDEFAULT
;
1517 child
->focus_pane
= 0;
1518 child
->split_pos
= DEFAULT_SPLIT_POS
;
1519 child
->sortOrder
= SORT_NAME
;
1520 child
->header_wdths_ok
= FALSE
;
1524 lstrcpy(child
->path
, path
);
1526 _tsplitpath(path
, drv
, dir
, name
, ext
);
1529 lstrcpy(child
->filter_pattern
, sAsterics
);
1530 child
->filter_flags
= TF_ALL
;
1532 root
->entry
.level
= 0;
1534 lstrcpy(dir_path
, drv
);
1535 lstrcat(dir_path
, dir
);
1536 entry
= read_tree(root
, dir_path
, pidl
, drv
, child
->sortOrder
, hwnd
);
1538 #ifdef _SHELL_FOLDERS
1539 if (root
->entry
.etype
== ET_SHELL
)
1540 load_string(root
->entry
.data
.cFileName
, IDS_DESKTOP
);
1543 wsprintf(root
->entry
.data
.cFileName
, RS(b1
,IDS_TITLEFMT
), drv
, root
->fs
);
1545 root
->entry
.data
.dwFileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1547 child
->left
.root
= &root
->entry
;
1548 child
->right
.root
= NULL
;
1550 set_curdir(child
, entry
, 0, hwnd
);
1556 /* free all memory associated with a child window */
1557 static void free_child_window(ChildWnd
* child
)
1559 free_entries(&child
->root
.entry
);
1560 HeapFree(GetProcessHeap(), 0, child
);
1564 /* get full path of specified directory entry */
1565 static void get_path(Entry
* dir
, PTSTR path
)
1571 #ifdef _SHELL_FOLDERS
1572 if (dir
->etype
== ET_SHELL
)
1582 hr
= IShellFolder_GetAttributesOf(dir
->folder
, 1, (LPCITEMIDLIST
*)&dir
->pidl
, &attribs
);
1584 if (SUCCEEDED(hr
) && (attribs
&SFGAO_FILESYSTEM
)) {
1585 IShellFolder
* parent
= dir
->up
? dir
->up
->folder
: Globals
.iDesktop
;
1587 hr
= path_from_pidl(parent
, dir
->pidl
, path
, MAX_PATH
);
1593 for(entry
=dir
; entry
; level
++) {
1599 name
= entry
->data
.cFileName
;
1602 for(l
=0; *s
&& *s
!= '/' && *s
!= '\\'; s
++)
1608 memmove(path
+l
+1, path
, len
*sizeof(TCHAR
));
1609 memcpy(path
+1, name
, l
*sizeof(TCHAR
));
1612 #ifndef _NO_EXTENSIONS
1613 if (entry
->etype
== ET_UNIX
)
1622 memmove(path
+l
, path
, len
*sizeof(TCHAR
));
1623 memcpy(path
, name
, l
*sizeof(TCHAR
));
1630 #ifndef _NO_EXTENSIONS
1631 if (entry
->etype
== ET_UNIX
)
1642 static windowOptions
load_registry_settings(void)
1649 RegOpenKeyExW( HKEY_CURRENT_USER
, registry_key
,
1650 0, KEY_QUERY_VALUE
, &hKey
);
1652 size
= sizeof(DWORD
);
1654 if( RegQueryValueExW( hKey
, reg_start_x
, NULL
, &type
,
1655 (LPBYTE
) &opts
.start_x
, &size
) != ERROR_SUCCESS
)
1656 opts
.start_x
= CW_USEDEFAULT
;
1658 if( RegQueryValueExW( hKey
, reg_start_y
, NULL
, &type
,
1659 (LPBYTE
) &opts
.start_y
, &size
) != ERROR_SUCCESS
)
1660 opts
.start_y
= CW_USEDEFAULT
;
1662 if( RegQueryValueExW( hKey
, reg_width
, NULL
, &type
,
1663 (LPBYTE
) &opts
.width
, &size
) != ERROR_SUCCESS
)
1664 opts
.width
= CW_USEDEFAULT
;
1666 if( RegQueryValueExW( hKey
, reg_height
, NULL
, &type
,
1667 (LPBYTE
) &opts
.height
, &size
) != ERROR_SUCCESS
)
1668 opts
.height
= CW_USEDEFAULT
;
1670 RegCloseKey( hKey
);
1675 static void save_registry_settings(void)
1681 wi
.cbSize
= sizeof( WINDOWINFO
);
1682 GetWindowInfo(Globals
.hMainWnd
, &wi
);
1683 width
= wi
.rcWindow
.right
- wi
.rcWindow
.left
;
1684 height
= wi
.rcWindow
.bottom
- wi
.rcWindow
.top
;
1686 if ( RegOpenKeyExW( HKEY_CURRENT_USER
, registry_key
,
1687 0, KEY_SET_VALUE
, &hKey
) != ERROR_SUCCESS
)
1689 /* Unable to save registry settings - try to create key */
1690 if ( RegCreateKeyExW( HKEY_CURRENT_USER
, registry_key
,
1691 0, NULL
, REG_OPTION_NON_VOLATILE
,
1692 KEY_SET_VALUE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
1694 /* FIXME: Cannot create key */
1698 /* Save all of the settings */
1699 RegSetValueExW( hKey
, reg_start_x
, 0, REG_DWORD
,
1700 (LPBYTE
) &wi
.rcWindow
.left
, sizeof(DWORD
) );
1701 RegSetValueExW( hKey
, reg_start_y
, 0, REG_DWORD
,
1702 (LPBYTE
) &wi
.rcWindow
.top
, sizeof(DWORD
) );
1703 RegSetValueExW( hKey
, reg_width
, 0, REG_DWORD
,
1704 (LPBYTE
) &width
, sizeof(DWORD
) );
1705 RegSetValueExW( hKey
, reg_height
, 0, REG_DWORD
,
1706 (LPBYTE
) &height
, sizeof(DWORD
) );
1708 /* TODO: Save more settings here (List vs. Detailed View, etc.) */
1709 RegCloseKey( hKey
);
1712 static void resize_frame_rect(HWND hwnd
, PRECT prect
)
1717 if (IsWindowVisible(Globals
.htoolbar
)) {
1718 SendMessage(Globals
.htoolbar
, WM_SIZE
, 0, 0);
1719 GetClientRect(Globals
.htoolbar
, &rt
);
1720 prect
->top
= rt
.bottom
+3;
1721 prect
->bottom
-= rt
.bottom
+3;
1724 if (IsWindowVisible(Globals
.hdrivebar
)) {
1725 SendMessage(Globals
.hdrivebar
, WM_SIZE
, 0, 0);
1726 GetClientRect(Globals
.hdrivebar
, &rt
);
1727 new_top
= --prect
->top
+ rt
.bottom
+3;
1728 MoveWindow(Globals
.hdrivebar
, 0, prect
->top
, rt
.right
, new_top
, TRUE
);
1729 prect
->top
= new_top
;
1730 prect
->bottom
-= rt
.bottom
+2;
1733 if (IsWindowVisible(Globals
.hstatusbar
)) {
1734 int parts
[] = {300, 500};
1736 SendMessage(Globals
.hstatusbar
, WM_SIZE
, 0, 0);
1737 SendMessage(Globals
.hstatusbar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
1738 GetClientRect(Globals
.hstatusbar
, &rt
);
1739 prect
->bottom
-= rt
.bottom
;
1742 MoveWindow(Globals
.hmdiclient
, prect
->left
-1,prect
->top
-1,prect
->right
+2,prect
->bottom
+1, TRUE
);
1745 static void resize_frame(HWND hwnd
, int cx
, int cy
)
1754 resize_frame_rect(hwnd
, &rect
);
1757 static void resize_frame_client(HWND hwnd
)
1761 GetClientRect(hwnd
, &rect
);
1763 resize_frame_rect(hwnd
, &rect
);
1767 static HHOOK hcbthook
;
1768 static ChildWnd
* newchild
= NULL
;
1770 static LRESULT CALLBACK
CBTProc(int code
, WPARAM wparam
, LPARAM lparam
)
1772 if (code
==HCBT_CREATEWND
&& newchild
) {
1773 ChildWnd
* child
= newchild
;
1776 child
->hwnd
= (HWND
) wparam
;
1777 SetWindowLongPtr(child
->hwnd
, GWLP_USERDATA
, (LPARAM
)child
);
1780 return CallNextHookEx(hcbthook
, code
, wparam
, lparam
);
1783 static HWND
create_child_window(ChildWnd
* child
)
1785 MDICREATESTRUCT mcs
;
1788 mcs
.szClass
= sWINEFILETREE
;
1789 mcs
.szTitle
= (LPTSTR
)child
->path
;
1790 mcs
.hOwner
= Globals
.hInstance
;
1791 mcs
.x
= child
->pos
.rcNormalPosition
.left
;
1792 mcs
.y
= child
->pos
.rcNormalPosition
.top
;
1793 mcs
.cx
= child
->pos
.rcNormalPosition
.right
-child
->pos
.rcNormalPosition
.left
;
1794 mcs
.cy
= child
->pos
.rcNormalPosition
.bottom
-child
->pos
.rcNormalPosition
.top
;
1798 hcbthook
= SetWindowsHookEx(WH_CBT
, CBTProc
, 0, GetCurrentThreadId());
1801 child
->hwnd
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDICREATE
, 0, (LPARAM
)&mcs
);
1803 UnhookWindowsHookEx(hcbthook
);
1807 UnhookWindowsHookEx(hcbthook
);
1809 SendMessage(child
->left
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1810 SendMessage(child
->right
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1812 idx
= SendMessage(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)child
->left
.cur
);
1813 SendMessage(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
1819 struct ExecuteDialog
{
1820 TCHAR cmd
[MAX_PATH
];
1824 static INT_PTR CALLBACK
ExecuteDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1826 static struct ExecuteDialog
* dlg
;
1830 dlg
= (struct ExecuteDialog
*) lparam
;
1834 int id
= (int)wparam
;
1837 GetWindowText(GetDlgItem(hwnd
, 201), dlg
->cmd
, MAX_PATH
);
1838 dlg
->cmdshow
= get_check(hwnd
,214) ? SW_SHOWMINIMIZED
: SW_SHOWNORMAL
;
1839 EndDialog(hwnd
, id
);
1840 } else if (id
== IDCANCEL
)
1841 EndDialog(hwnd
, id
);
1850 static INT_PTR CALLBACK
DestinationDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1852 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1856 SetWindowLongPtr(hwnd
, GWLP_USERDATA
, lparam
);
1857 SetWindowText(GetDlgItem(hwnd
, 201), (LPCTSTR
)lparam
);
1861 int id
= (int)wparam
;
1865 LPTSTR dest
= (LPTSTR
) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
1866 GetWindowText(GetDlgItem(hwnd
, 201), dest
, MAX_PATH
);
1867 EndDialog(hwnd
, id
);
1871 EndDialog(hwnd
, id
);
1875 MessageBox(hwnd
, RS(b1
,IDS_NO_IMPL
), RS(b2
,IDS_WINEFILE
), MB_OK
);
1887 struct FilterDialog
{
1888 TCHAR pattern
[MAX_PATH
];
1892 static INT_PTR CALLBACK
FilterDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1894 static struct FilterDialog
* dlg
;
1898 dlg
= (struct FilterDialog
*) lparam
;
1899 SetWindowText(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
);
1900 set_check(hwnd
, IDC_VIEW_TYPE_DIRECTORIES
, dlg
->flags
&TF_DIRECTORIES
);
1901 set_check(hwnd
, IDC_VIEW_TYPE_PROGRAMS
, dlg
->flags
&TF_PROGRAMS
);
1902 set_check(hwnd
, IDC_VIEW_TYPE_DOCUMENTS
, dlg
->flags
&TF_DOCUMENTS
);
1903 set_check(hwnd
, IDC_VIEW_TYPE_OTHERS
, dlg
->flags
&TF_OTHERS
);
1904 set_check(hwnd
, IDC_VIEW_TYPE_HIDDEN
, dlg
->flags
&TF_HIDDEN
);
1908 int id
= (int)wparam
;
1913 GetWindowText(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
, MAX_PATH
);
1915 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_DIRECTORIES
) ? TF_DIRECTORIES
: 0;
1916 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_PROGRAMS
) ? TF_PROGRAMS
: 0;
1917 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_DOCUMENTS
) ? TF_DOCUMENTS
: 0;
1918 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_OTHERS
) ? TF_OTHERS
: 0;
1919 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_HIDDEN
) ? TF_HIDDEN
: 0;
1923 EndDialog(hwnd
, id
);
1924 } else if (id
== IDCANCEL
)
1925 EndDialog(hwnd
, id
);
1934 struct PropertiesDialog
{
1935 TCHAR path
[MAX_PATH
];
1940 /* Structure used to store enumerated languages and code pages. */
1941 struct LANGANDCODEPAGE
{
1946 static LPCSTR InfoStrings
[] = {
1962 static void PropDlg_DisplayValue(HWND hlbox
, HWND hedit
)
1964 int idx
= SendMessage(hlbox
, LB_GETCURSEL
, 0, 0);
1966 if (idx
!= LB_ERR
) {
1967 LPCTSTR pValue
= (LPCTSTR
) SendMessage(hlbox
, LB_GETITEMDATA
, idx
, 0);
1970 SetWindowText(hedit
, pValue
);
1974 static void CheckForFileInfo(struct PropertiesDialog
* dlg
, HWND hwnd
, LPCTSTR strFilename
)
1976 static TCHAR sBackSlash
[] = {'\\','\0'};
1977 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'};
1978 static TCHAR sStringFileInfo
[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1979 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1980 DWORD dwVersionDataLen
= GetFileVersionInfoSize(strFilename
, NULL
);
1982 if (dwVersionDataLen
) {
1983 dlg
->pVersionData
= HeapAlloc(GetProcessHeap(), 0, dwVersionDataLen
);
1985 if (GetFileVersionInfo(strFilename
, 0, dwVersionDataLen
, dlg
->pVersionData
)) {
1989 if (VerQueryValue(dlg
->pVersionData
, sBackSlash
, &pVal
, &nValLen
)) {
1990 if (nValLen
== sizeof(VS_FIXEDFILEINFO
)) {
1991 VS_FIXEDFILEINFO
* pFixedFileInfo
= (VS_FIXEDFILEINFO
*)pVal
;
1992 char buffer
[BUFFER_LEN
];
1994 sprintf(buffer
, "%d.%d.%d.%d",
1995 HIWORD(pFixedFileInfo
->dwFileVersionMS
), LOWORD(pFixedFileInfo
->dwFileVersionMS
),
1996 HIWORD(pFixedFileInfo
->dwFileVersionLS
), LOWORD(pFixedFileInfo
->dwFileVersionLS
));
1998 SetDlgItemTextA(hwnd
, IDC_STATIC_PROP_VERSION
, buffer
);
2002 /* Read the list of languages and code pages. */
2003 if (VerQueryValue(dlg
->pVersionData
, sTranslation
, &pVal
, &nValLen
)) {
2004 struct LANGANDCODEPAGE
* pTranslate
= (struct LANGANDCODEPAGE
*)pVal
;
2005 struct LANGANDCODEPAGE
* pEnd
= (struct LANGANDCODEPAGE
*)((LPBYTE
)pVal
+nValLen
);
2007 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
2009 /* Read the file description for each language and code page. */
2010 for(; pTranslate
<pEnd
; ++pTranslate
) {
2013 for(p
=InfoStrings
; *p
; ++p
) {
2014 TCHAR subblock
[200];
2021 LPCSTR pInfoString
= *p
;
2023 MultiByteToWideChar(CP_ACP
, 0, pInfoString
, -1, infoStr
, 100);
2025 #define infoStr pInfoString
2027 wsprintf(subblock
, sStringFileInfo
, pTranslate
->wLanguage
, pTranslate
->wCodePage
, infoStr
);
2029 /* Retrieve file description for language and code page */
2030 if (VerQueryValue(dlg
->pVersionData
, subblock
, (PVOID
)&pTxt
, &nValLen
)) {
2031 int idx
= SendMessage(hlbox
, LB_ADDSTRING
, 0L, (LPARAM
)infoStr
);
2032 SendMessage(hlbox
, LB_SETITEMDATA
, idx
, (LPARAM
) pTxt
);
2037 SendMessage(hlbox
, LB_SETCURSEL
, 0, 0);
2039 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
2045 static INT_PTR CALLBACK
PropertiesDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
2047 static struct PropertiesDialog
* dlg
;
2050 case WM_INITDIALOG
: {
2051 static const TCHAR sByteFmt
[] = {'%','s',' ','B','y','t','e','s','\0'};
2052 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2053 LPWIN32_FIND_DATA pWFD
;
2056 dlg
= (struct PropertiesDialog
*) lparam
;
2057 pWFD
= (LPWIN32_FIND_DATA
) &dlg
->entry
.data
;
2059 GetWindowText(hwnd
, b1
, MAX_PATH
);
2060 wsprintf(b2
, b1
, pWFD
->cFileName
);
2061 SetWindowText(hwnd
, b2
);
2063 format_date(&pWFD
->ftLastWriteTime
, b1
, COL_DATE
|COL_TIME
);
2064 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_LASTCHANGE
), b1
);
2066 size
= ((ULONGLONG
)pWFD
->nFileSizeHigh
<< 32) | pWFD
->nFileSizeLow
;
2067 _stprintf(b1
, sLongNumFmt
, size
);
2068 wsprintf(b2
, sByteFmt
, b1
);
2069 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_SIZE
), b2
);
2071 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_FILENAME
), pWFD
->cFileName
);
2072 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_PATH
), dlg
->path
);
2074 set_check(hwnd
, IDC_CHECK_READONLY
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_READONLY
);
2075 set_check(hwnd
, IDC_CHECK_ARCHIVE
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_ARCHIVE
);
2076 set_check(hwnd
, IDC_CHECK_COMPRESSED
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_COMPRESSED
);
2077 set_check(hwnd
, IDC_CHECK_HIDDEN
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_HIDDEN
);
2078 set_check(hwnd
, IDC_CHECK_SYSTEM
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_SYSTEM
);
2080 CheckForFileInfo(dlg
, hwnd
, dlg
->path
);
2084 int id
= (int)wparam
;
2086 switch(HIWORD(wparam
)) {
2087 case LBN_SELCHANGE
: {
2088 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
2089 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
2094 if (id
==IDOK
|| id
==IDCANCEL
)
2095 EndDialog(hwnd
, id
);
2101 HeapFree(GetProcessHeap(), 0, dlg
->pVersionData
);
2102 dlg
->pVersionData
= NULL
;
2109 static void show_properties_dlg(Entry
* entry
, HWND hwnd
)
2111 struct PropertiesDialog dlg
;
2113 memset(&dlg
, 0, sizeof(struct PropertiesDialog
));
2114 get_path(entry
, dlg
.path
);
2115 memcpy(&dlg
.entry
, entry
, sizeof(Entry
));
2117 DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_DIALOG_PROPERTIES
), hwnd
, PropertiesDialogDlgProc
, (LPARAM
)&dlg
);
2121 #ifndef _NO_EXTENSIONS
2123 static struct FullScreenParameters
{
2133 static void frame_get_clientspace(HWND hwnd
, PRECT prect
)
2137 if (!IsIconic(hwnd
))
2138 GetClientRect(hwnd
, prect
);
2142 GetWindowPlacement(hwnd
, &wp
);
2144 prect
->left
= prect
->top
= 0;
2145 prect
->right
= wp
.rcNormalPosition
.right
-wp
.rcNormalPosition
.left
-
2146 2*(GetSystemMetrics(SM_CXSIZEFRAME
)+GetSystemMetrics(SM_CXEDGE
));
2147 prect
->bottom
= wp
.rcNormalPosition
.bottom
-wp
.rcNormalPosition
.top
-
2148 2*(GetSystemMetrics(SM_CYSIZEFRAME
)+GetSystemMetrics(SM_CYEDGE
))-
2149 GetSystemMetrics(SM_CYCAPTION
)-GetSystemMetrics(SM_CYMENUSIZE
);
2152 if (IsWindowVisible(Globals
.htoolbar
)) {
2153 GetClientRect(Globals
.htoolbar
, &rt
);
2154 prect
->top
+= rt
.bottom
+2;
2157 if (IsWindowVisible(Globals
.hdrivebar
)) {
2158 GetClientRect(Globals
.hdrivebar
, &rt
);
2159 prect
->top
+= rt
.bottom
+2;
2162 if (IsWindowVisible(Globals
.hstatusbar
)) {
2163 GetClientRect(Globals
.hstatusbar
, &rt
);
2164 prect
->bottom
-= rt
.bottom
;
2168 static BOOL
toggle_fullscreen(HWND hwnd
)
2172 if ((g_fullscreen
.mode
=!g_fullscreen
.mode
)) {
2173 GetWindowRect(hwnd
, &g_fullscreen
.orgPos
);
2174 g_fullscreen
.wasZoomed
= IsZoomed(hwnd
);
2176 Frame_CalcFrameClient(hwnd
, &rt
);
2177 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
2178 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
2180 rt
.left
= g_fullscreen
.orgPos
.left
-rt
.left
;
2181 rt
.top
= g_fullscreen
.orgPos
.top
-rt
.top
;
2182 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+g_fullscreen
.orgPos
.right
-rt
.right
;
2183 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+g_fullscreen
.orgPos
.bottom
-rt
.bottom
;
2185 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
2187 MoveWindow(hwnd
, g_fullscreen
.orgPos
.left
, g_fullscreen
.orgPos
.top
,
2188 g_fullscreen
.orgPos
.right
-g_fullscreen
.orgPos
.left
,
2189 g_fullscreen
.orgPos
.bottom
-g_fullscreen
.orgPos
.top
, TRUE
);
2191 if (g_fullscreen
.wasZoomed
)
2192 ShowWindow(hwnd
, WS_MAXIMIZE
);
2195 return g_fullscreen
.mode
;
2198 static void fullscreen_move(HWND hwnd
)
2201 GetWindowRect(hwnd
, &pos
);
2203 Frame_CalcFrameClient(hwnd
, &rt
);
2204 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
2205 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
2207 rt
.left
= pos
.left
-rt
.left
;
2208 rt
.top
= pos
.top
-rt
.top
;
2209 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+pos
.right
-rt
.right
;
2210 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+pos
.bottom
-rt
.bottom
;
2212 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
2218 static void toggle_child(HWND hwnd
, UINT cmd
, HWND hchild
)
2220 BOOL vis
= IsWindowVisible(hchild
);
2222 CheckMenuItem(Globals
.hMenuOptions
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
2224 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
2226 #ifndef _NO_EXTENSIONS
2227 if (g_fullscreen
.mode
)
2228 fullscreen_move(hwnd
);
2231 resize_frame_client(hwnd
);
2234 static BOOL
activate_drive_window(LPCTSTR path
)
2236 TCHAR drv1
[_MAX_DRIVE
], drv2
[_MAX_DRIVE
];
2239 _tsplitpath(path
, drv1
, 0, 0, 0);
2241 /* search for a already open window for the same drive */
2242 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2243 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(child_wnd
, GWLP_USERDATA
);
2246 _tsplitpath(child
->root
.path
, drv2
, 0, 0, 0);
2248 if (!lstrcmpi(drv2
, drv1
)) {
2249 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2251 if (IsIconic(child_wnd
))
2252 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2262 static BOOL
activate_fs_window(LPCTSTR filesys
)
2266 /* search for a already open window of the given file system name */
2267 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2268 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(child_wnd
, GWLP_USERDATA
);
2271 if (!lstrcmpi(child
->root
.fs
, filesys
)) {
2272 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2274 if (IsIconic(child_wnd
))
2275 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2285 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
2287 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2291 if (Globals
.saveSettings
)
2292 save_registry_settings();
2294 DestroyWindow(hwnd
);
2296 /* clear handle variables */
2297 Globals
.hMenuFrame
= 0;
2298 Globals
.hMenuView
= 0;
2299 Globals
.hMenuOptions
= 0;
2300 Globals
.hMainWnd
= 0;
2301 Globals
.hmdiclient
= 0;
2302 Globals
.hdrivebar
= 0;
2309 case WM_INITMENUPOPUP
: {
2310 HWND hwndClient
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2312 if (!SendMessage(hwndClient
, WM_INITMENUPOPUP
, wparam
, lparam
))
2317 UINT cmd
= LOWORD(wparam
);
2318 HWND hwndClient
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2320 if (SendMessage(hwndClient
, WM_DISPATCH_COMMAND
, wparam
, lparam
))
2323 if (cmd
>=ID_DRIVE_FIRST
&& cmd
<=ID_DRIVE_FIRST
+0xFF) {
2324 TCHAR drv
[_MAX_DRIVE
], path
[MAX_PATH
];
2326 LPCTSTR root
= Globals
.drives
;
2329 for(i
=cmd
-ID_DRIVE_FIRST
; i
--; root
++)
2333 if (activate_drive_window(root
))
2336 _tsplitpath(root
, drv
, 0, 0, 0);
2338 if (!SetCurrentDirectory(drv
)) {
2339 display_error(hwnd
, GetLastError());
2343 GetCurrentDirectory(MAX_PATH
, path
); /*TODO: store last directory per drive */
2344 child
= alloc_child_window(path
, NULL
, hwnd
);
2346 if (!create_child_window(child
))
2347 HeapFree(GetProcessHeap(), 0, child
);
2348 } else switch(cmd
) {
2350 SendMessage(hwnd
, WM_CLOSE
, 0, 0);
2353 case ID_WINDOW_NEW
: {
2354 TCHAR path
[MAX_PATH
];
2357 GetCurrentDirectory(MAX_PATH
, path
);
2358 child
= alloc_child_window(path
, NULL
, hwnd
);
2360 if (!create_child_window(child
))
2361 HeapFree(GetProcessHeap(), 0, child
);
2368 case ID_WINDOW_CASCADE
:
2369 SendMessage(Globals
.hmdiclient
, WM_MDICASCADE
, 0, 0);
2372 case ID_WINDOW_TILE_HORZ
:
2373 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
2376 case ID_WINDOW_TILE_VERT
:
2377 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
2380 case ID_WINDOW_ARRANGE
:
2381 SendMessage(Globals
.hmdiclient
, WM_MDIICONARRANGE
, 0, 0);
2384 case ID_SELECT_FONT
:
2388 case ID_VIEW_TOOL_BAR
:
2389 toggle_child(hwnd
, cmd
, Globals
.htoolbar
);
2392 case ID_VIEW_DRIVE_BAR
:
2393 toggle_child(hwnd
, cmd
, Globals
.hdrivebar
);
2396 case ID_VIEW_STATUSBAR
:
2397 toggle_child(hwnd
, cmd
, Globals
.hstatusbar
);
2400 case ID_VIEW_SAVESETTINGS
:
2401 Globals
.saveSettings
= !Globals
.saveSettings
;
2402 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_SAVESETTINGS
,
2403 Globals
.saveSettings
? MF_CHECKED
: MF_UNCHECKED
);
2407 struct ExecuteDialog dlg
;
2409 memset(&dlg
, 0, sizeof(struct ExecuteDialog
));
2411 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_EXECUTE
), hwnd
, ExecuteDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
2412 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, dlg
.cmd
/*file*/, NULL
/*parameters*/, NULL
/*dir*/, dlg
.cmdshow
);
2414 if ((int)hinst
<= 32)
2415 display_error(hwnd
, GetLastError());
2419 case ID_CONNECT_NETWORK_DRIVE
: {
2420 DWORD ret
= WNetConnectionDialog(hwnd
, RESOURCETYPE_DISK
);
2421 if (ret
== NO_ERROR
)
2423 else if (ret
!= (DWORD
)-1) {
2424 if (ret
== ERROR_EXTENDED_ERROR
)
2425 display_network_error(hwnd
);
2427 display_error(hwnd
, ret
);
2431 case ID_DISCONNECT_NETWORK_DRIVE
: {
2432 DWORD ret
= WNetDisconnectDialog(hwnd
, RESOURCETYPE_DISK
);
2433 if (ret
== NO_ERROR
)
2435 else if (ret
!= (DWORD
)-1) {
2436 if (ret
== ERROR_EXTENDED_ERROR
)
2437 display_network_error(hwnd
);
2439 display_error(hwnd
, ret
);
2443 case ID_FORMAT_DISK
: {
2444 UINT sem_org
= SetErrorMode(0); /* Get the current Error Mode settings. */
2445 SetErrorMode(sem_org
& ~SEM_FAILCRITICALERRORS
); /* Force O/S to handle */
2446 SHFormatDrive(hwnd
, 0 /* A: */, SHFMT_ID_DEFAULT
, 0);
2447 SetErrorMode(sem_org
); /* Put it back the way it was. */
2451 WinHelp(hwnd
, RS(b1
,IDS_WINEFILE
), HELP_INDEX
, 0);
2454 #ifndef _NO_EXTENSIONS
2455 case ID_VIEW_FULLSCREEN
:
2456 CheckMenuItem(Globals
.hMenuOptions
, cmd
, toggle_fullscreen(hwnd
)?MF_CHECKED
:0);
2460 case ID_DRIVE_UNIX_FS
: {
2461 TCHAR path
[MAX_PATH
];
2463 char cpath
[MAX_PATH
];
2467 if (activate_fs_window(RS(b1
,IDS_UNIXFS
)))
2471 getcwd(cpath
, MAX_PATH
);
2472 MultiByteToWideChar(CP_UNIXCP
, 0, cpath
, -1, path
, MAX_PATH
);
2474 getcwd(path
, MAX_PATH
);
2476 child
= alloc_child_window(path
, NULL
, hwnd
);
2478 if (!create_child_window(child
))
2479 HeapFree(GetProcessHeap(), 0, child
);
2482 #ifdef _SHELL_FOLDERS
2483 case ID_DRIVE_SHELL_NS
: {
2484 TCHAR path
[MAX_PATH
];
2487 if (activate_fs_window(RS(b1
,IDS_SHELL
)))
2490 GetCurrentDirectory(MAX_PATH
, path
);
2491 child
= alloc_child_window(path
, get_path_pidl(path
,hwnd
), hwnd
);
2493 if (!create_child_window(child
))
2494 HeapFree(GetProcessHeap(), 0, child
);
2499 /*TODO: There are even more menu items! */
2501 #ifndef _NO_EXTENSIONS
2504 WineLicense(Globals
.hMainWnd
);
2507 case ID_NO_WARRANTY
:
2508 WineWarranty(Globals
.hMainWnd
);
2512 ShellAbout(hwnd
, RS(b2
,IDS_WINE
), RS(b1
,IDS_WINEFILE
), 0);
2517 ShellAbout(hwnd
, RS(b1
,IDS_WINEFILE
), NULL
, 0);
2519 #endif /* _NO_EXTENSIONS */
2522 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2523 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2524 else */if ((cmd
<IDW_FIRST_CHILD
|| cmd
>=IDW_FIRST_CHILD
+0x100) &&
2525 (cmd
<SC_SIZE
|| cmd
>SC_RESTORE
))
2526 MessageBox(hwnd
, RS(b2
,IDS_NO_IMPL
), RS(b1
,IDS_WINEFILE
), MB_OK
);
2528 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2533 resize_frame(hwnd
, LOWORD(lparam
), HIWORD(lparam
));
2534 break; /* do not pass message to DefFrameProc */
2536 case WM_DEVICECHANGE
:
2537 SendMessage(hwnd
, WM_COMMAND
, MAKELONG(ID_REFRESH
,0), 0);
2540 #ifndef _NO_EXTENSIONS
2541 case WM_GETMINMAXINFO
: {
2542 LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
2544 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2545 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2548 case FRM_CALC_CLIENT
:
2549 frame_get_clientspace(hwnd
, (PRECT
)lparam
);
2551 #endif /* _NO_EXTENSIONS */
2554 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2561 static TCHAR g_pos_names
[COLUMNS
][20] = {
2565 static const int g_pos_align
[] = {
2567 HDF_LEFT
, /* Name */
2568 HDF_RIGHT
, /* Size */
2569 HDF_LEFT
, /* CDate */
2570 #ifndef _NO_EXTENSIONS
2571 HDF_LEFT
, /* ADate */
2572 HDF_LEFT
, /* MDate */
2573 HDF_LEFT
, /* Index */
2574 HDF_CENTER
, /* Links */
2576 HDF_CENTER
, /* Attributes */
2577 #ifndef _NO_EXTENSIONS
2578 HDF_LEFT
/* Security */
2582 static void resize_tree(ChildWnd
* child
, int cx
, int cy
)
2584 HDWP hdwp
= BeginDeferWindowPos(4);
2592 cx
= child
->split_pos
+ SPLIT_WIDTH
/2;
2594 #ifndef _NO_EXTENSIONS
2602 SendMessage(child
->left
.hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hdl
);
2604 DeferWindowPos(hdwp
, child
->left
.hwndHeader
, wp
.hwndInsertAfter
,
2605 wp
.x
-1, wp
.y
, child
->split_pos
-SPLIT_WIDTH
/2+1, wp
.cy
, wp
.flags
);
2606 DeferWindowPos(hdwp
, child
->right
.hwndHeader
, wp
.hwndInsertAfter
,
2607 rt
.left
+cx
+1, wp
.y
, wp
.cx
-cx
+2, wp
.cy
, wp
.flags
);
2609 #endif /* _NO_EXTENSIONS */
2611 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
);
2612 DeferWindowPos(hdwp
, child
->right
.hwnd
, 0, rt
.left
+cx
+1, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
2614 EndDeferWindowPos(hdwp
);
2618 #ifndef _NO_EXTENSIONS
2620 static HWND
create_header(HWND parent
, Pane
* pane
, int id
)
2625 HWND hwnd
= CreateWindow(WC_HEADER
, 0, WS_CHILD
|WS_VISIBLE
|HDS_HORZ
|HDS_FULLDRAG
/*TODO: |HDS_BUTTONS + sort orders*/,
2626 0, 0, 0, 0, parent
, (HMENU
)id
, Globals
.hInstance
, 0);
2630 SendMessage(hwnd
, WM_SETFONT
, (WPARAM
)GetStockObject(DEFAULT_GUI_FONT
), FALSE
);
2632 hdi
.mask
= HDI_TEXT
|HDI_WIDTH
|HDI_FORMAT
;
2634 for(idx
=0; idx
<COLUMNS
; idx
++) {
2635 hdi
.pszText
= g_pos_names
[idx
];
2636 hdi
.fmt
= HDF_STRING
| g_pos_align
[idx
];
2637 hdi
.cxy
= pane
->widths
[idx
];
2638 SendMessage(hwnd
, HDM_INSERTITEM
, idx
, (LPARAM
) &hdi
);
2644 #endif /* _NO_EXTENSIONS */
2647 static void init_output(HWND hwnd
)
2649 static const WCHAR s1000
[] = {'1','0','0','0','\0'};
2652 HDC hdc
= GetDC(hwnd
);
2654 if (GetNumberFormatW(LOCALE_USER_DEFAULT
, 0, s1000
, 0, b
, 16) > 4)
2655 Globals
.num_sep
= b
[1];
2657 Globals
.num_sep
= '.';
2659 old_font
= SelectObject(hdc
, Globals
.hfont
);
2660 GetTextExtentPoint32W(hdc
, sSpace
, 1, &Globals
.spaceSize
);
2661 SelectObject(hdc
, old_font
);
2662 ReleaseDC(hwnd
, hdc
);
2665 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
);
2668 /* calculate preferred width for all visible columns */
2670 static BOOL
calc_widths(Pane
* pane
, BOOL anyway
)
2672 int col
, x
, cx
, spc
=3*Globals
.spaceSize
.cx
;
2673 int entries
= SendMessage(pane
->hwnd
, LB_GETCOUNT
, 0, 0);
2674 int orgWidths
[COLUMNS
];
2675 int orgPositions
[COLUMNS
+1];
2681 memcpy(orgWidths
, pane
->widths
, sizeof(orgWidths
));
2682 memcpy(orgPositions
, pane
->positions
, sizeof(orgPositions
));
2685 for(col
=0; col
<COLUMNS
; col
++)
2686 pane
->widths
[col
] = 0;
2688 hdc
= GetDC(pane
->hwnd
);
2689 hfontOld
= SelectObject(hdc
, Globals
.hfont
);
2691 for(cnt
=0; cnt
<entries
; cnt
++) {
2692 Entry
* entry
= (Entry
*) SendMessage(pane
->hwnd
, LB_GETITEMDATA
, cnt
, 0);
2701 dis
.hwndItem
= pane
->hwnd
;
2703 dis
.rcItem
.left
= 0;
2705 dis
.rcItem
.right
= 0;
2706 dis
.rcItem
.bottom
= 0;
2707 /*dis.itemData = 0; */
2709 draw_item(pane
, &dis
, entry
, COLUMNS
);
2712 SelectObject(hdc
, hfontOld
);
2713 ReleaseDC(pane
->hwnd
, hdc
);
2716 for(col
=0; col
<COLUMNS
; col
++) {
2717 pane
->positions
[col
] = x
;
2718 cx
= pane
->widths
[col
];
2723 if (cx
< IMAGE_WIDTH
)
2726 pane
->widths
[col
] = cx
;
2732 pane
->positions
[COLUMNS
] = x
;
2734 SendMessage(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, x
, 0);
2737 if (!memcmp(orgWidths
, pane
->widths
, sizeof(orgWidths
)))
2740 /* don't move, if only collapsing an entry */
2741 if (!anyway
&& pane
->widths
[0]<orgWidths
[0] &&
2742 !memcmp(orgWidths
+1, pane
->widths
+1, sizeof(orgWidths
)-sizeof(int))) {
2743 pane
->widths
[0] = orgWidths
[0];
2744 memcpy(pane
->positions
, orgPositions
, sizeof(orgPositions
));
2749 InvalidateRect(pane
->hwnd
, 0, TRUE
);
2755 /* calculate one preferred column width */
2757 static void calc_single_width(Pane
* pane
, int col
)
2761 int entries
= SendMessage(pane
->hwnd
, LB_GETCOUNT
, 0, 0);
2765 pane
->widths
[col
] = 0;
2767 hdc
= GetDC(pane
->hwnd
);
2768 hfontOld
= SelectObject(hdc
, Globals
.hfont
);
2770 for(cnt
=0; cnt
<entries
; cnt
++) {
2771 Entry
* entry
= (Entry
*) SendMessage(pane
->hwnd
, LB_GETITEMDATA
, cnt
, 0);
2779 dis
.hwndItem
= pane
->hwnd
;
2781 dis
.rcItem
.left
= 0;
2783 dis
.rcItem
.right
= 0;
2784 dis
.rcItem
.bottom
= 0;
2785 /*dis.itemData = 0; */
2787 draw_item(pane
, &dis
, entry
, col
);
2790 SelectObject(hdc
, hfontOld
);
2791 ReleaseDC(pane
->hwnd
, hdc
);
2793 cx
= pane
->widths
[col
];
2796 cx
+= 3*Globals
.spaceSize
.cx
;
2798 if (cx
< IMAGE_WIDTH
)
2802 pane
->widths
[col
] = cx
;
2804 x
= pane
->positions
[col
] + cx
;
2806 for(; col
<COLUMNS
; ) {
2807 pane
->positions
[++col
] = x
;
2808 x
+= pane
->widths
[col
];
2811 SendMessage(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, x
, 0);
2815 static BOOL
pattern_match(LPCTSTR str
, LPCTSTR pattern
)
2817 for( ; *str
&&*pattern
; str
++,pattern
++) {
2818 if (*pattern
== '*') {
2820 while(*pattern
== '*');
2826 if (*str
==*pattern
&& pattern_match(str
, pattern
))
2831 else if (*str
!=*pattern
&& *pattern
!='?')
2835 if (*str
|| *pattern
)
2836 if (*pattern
!='*' || pattern
[1]!='\0')
2842 static BOOL
pattern_imatch(LPCTSTR str
, LPCTSTR pattern
)
2844 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2847 lstrcpy(b2
, pattern
);
2851 return pattern_match(b1
, b2
);
2861 static enum FILE_TYPE
get_file_type(LPCTSTR filename
);
2864 /* insert listbox entries after index idx */
2866 static int insert_entries(Pane
* pane
, Entry
* dir
, LPCTSTR pattern
, int filter_flags
, int idx
)
2873 ShowWindow(pane
->hwnd
, SW_HIDE
);
2875 for(; entry
; entry
=entry
->next
) {
2877 if (pane
->treePane
&& !(entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
2881 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
2882 /* don't display entries "." and ".." in the left pane */
2883 if (pane
->treePane
&& entry
->data
.cFileName
[0] == '.')
2885 #ifndef _NO_EXTENSIONS
2886 entry
->data
.cFileName
[1] == '\0' ||
2888 (entry
->data
.cFileName
[1] == '.' && entry
->data
.cFileName
[2] == '\0'))
2891 /* filter directories in right pane */
2892 if (!pane
->treePane
&& !(filter_flags
&TF_DIRECTORIES
))
2896 /* filter using the file name pattern */
2898 if (!pattern_imatch(entry
->data
.cFileName
, pattern
))
2901 /* filter system and hidden files */
2902 if (!(filter_flags
&TF_HIDDEN
) && (entry
->data
.dwFileAttributes
&(FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
)))
2905 /* filter looking at the file type */
2906 if ((filter_flags
&(TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
)) != (TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
))
2907 switch(get_file_type(entry
->data
.cFileName
)) {
2909 if (!(filter_flags
& TF_PROGRAMS
))
2914 if (!(filter_flags
& TF_DOCUMENTS
))
2918 default: /* TF_OTHERS */
2919 if (!(filter_flags
& TF_OTHERS
))
2926 SendMessage(pane
->hwnd
, LB_INSERTSTRING
, idx
, (LPARAM
) entry
);
2928 if (pane
->treePane
&& entry
->expanded
)
2929 idx
= insert_entries(pane
, entry
->down
, pattern
, filter_flags
, idx
);
2932 ShowWindow(pane
->hwnd
, SW_SHOW
);
2938 static void format_bytes(LPTSTR buffer
, LONGLONG bytes
)
2940 static const TCHAR sFmtGB
[] = {'%', '.', '1', 'f', ' ', 'G', 'B', '\0'};
2941 static const TCHAR sFmtMB
[] = {'%', '.', '1', 'f', ' ', 'M', 'B', '\0'};
2942 static const TCHAR sFmtkB
[] = {'%', '.', '1', 'f', ' ', 'k', 'B', '\0'};
2944 float fBytes
= (float)bytes
;
2946 if (bytes
>= 1073741824) /* 1 GB */
2947 _stprintf(buffer
, sFmtGB
, fBytes
/1073741824.f
+.5f
);
2948 else if (bytes
>= 1048576) /* 1 MB */
2949 _stprintf(buffer
, sFmtMB
, fBytes
/1048576.f
+.5f
);
2950 else if (bytes
>= 1024) /* 1 kB */
2951 _stprintf(buffer
, sFmtkB
, fBytes
/1024.f
+.5f
);
2953 _stprintf(buffer
, sLongNumFmt
, bytes
);
2956 static void set_space_status(void)
2958 ULARGE_INTEGER ulFreeBytesToCaller
, ulTotalBytes
, ulFreeBytes
;
2959 TCHAR fmt
[64], b1
[64], b2
[64], buffer
[BUFFER_LEN
];
2961 if (GetDiskFreeSpaceEx(NULL
, &ulFreeBytesToCaller
, &ulTotalBytes
, &ulFreeBytes
)) {
2962 format_bytes(b1
, ulFreeBytesToCaller
.QuadPart
);
2963 format_bytes(b2
, ulTotalBytes
.QuadPart
);
2964 wsprintf(buffer
, RS(fmt
,IDS_FREE_SPACE_FMT
), b1
, b2
);
2966 lstrcpy(buffer
, sQMarks
);
2968 SendMessage(Globals
.hstatusbar
, SB_SETTEXT
, 0, (LPARAM
)buffer
);
2972 static WNDPROC g_orgTreeWndProc
;
2974 static void create_tree_window(HWND parent
, Pane
* pane
, int id
, int id_header
, LPCTSTR pattern
, int filter_flags
)
2976 static const TCHAR sListBox
[] = {'L','i','s','t','B','o','x','\0'};
2978 static int s_init
= 0;
2979 Entry
* entry
= pane
->root
;
2981 pane
->hwnd
= CreateWindow(sListBox
, sEmpty
, WS_CHILD
|WS_VISIBLE
|WS_HSCROLL
|WS_VSCROLL
|
2982 LBS_DISABLENOSCROLL
|LBS_NOINTEGRALHEIGHT
|LBS_OWNERDRAWFIXED
|LBS_NOTIFY
,
2983 0, 0, 0, 0, parent
, (HMENU
)id
, Globals
.hInstance
, 0);
2985 SetWindowLongPtr(pane
->hwnd
, GWLP_USERDATA
, (LPARAM
)pane
);
2986 g_orgTreeWndProc
= (WNDPROC
) SetWindowLongPtr(pane
->hwnd
, GWLP_WNDPROC
, (LPARAM
)TreeWndProc
);
2988 SendMessage(pane
->hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, FALSE
);
2990 /* insert entries into listbox */
2992 insert_entries(pane
, entry
, pattern
, filter_flags
, -1);
2994 /* calculate column widths */
2997 init_output(pane
->hwnd
);
3000 calc_widths(pane
, TRUE
);
3002 #ifndef _NO_EXTENSIONS
3003 pane
->hwndHeader
= create_header(parent
, pane
, id_header
);
3008 static void InitChildWindow(ChildWnd
* child
)
3010 create_tree_window(child
->hwnd
, &child
->left
, IDW_TREE_LEFT
, IDW_HEADER_LEFT
, NULL
, TF_ALL
);
3011 create_tree_window(child
->hwnd
, &child
->right
, IDW_TREE_RIGHT
, IDW_HEADER_RIGHT
, child
->filter_pattern
, child
->filter_flags
);
3015 static void format_date(const FILETIME
* ft
, TCHAR
* buffer
, int visible_cols
)
3023 if (!ft
->dwLowDateTime
&& !ft
->dwHighDateTime
)
3026 if (!FileTimeToLocalFileTime(ft
, &lft
))
3027 {err
: lstrcpy(buffer
,sQMarks
); return;}
3029 if (!FileTimeToSystemTime(&lft
, &systime
))
3032 if (visible_cols
& COL_DATE
) {
3033 len
= GetDateFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
, BUFFER_LEN
);
3038 if (visible_cols
& COL_TIME
) {
3040 buffer
[len
-1] = ' ';
3042 buffer
[len
++] = ' ';
3044 if (!GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
+len
, BUFFER_LEN
-len
))
3050 static void calc_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3052 RECT rt
= {0, 0, 0, 0};
3054 DrawText(dis
->hDC
, str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
3056 if (rt
.right
> pane
->widths
[col
])
3057 pane
->widths
[col
] = rt
.right
;
3060 static void calc_tabbed_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3062 RECT rt
= {0, 0, 0, 0};
3064 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
3065 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
3067 DrawText(dis
->hDC
, str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
3068 /*FIXME rt (0,0) ??? */
3070 if (rt
.right
> pane
->widths
[col
])
3071 pane
->widths
[col
] = rt
.right
;
3075 static void output_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
, DWORD flags
)
3077 int x
= dis
->rcItem
.left
;
3080 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
3081 rt
.top
= dis
->rcItem
.top
;
3082 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
3083 rt
.bottom
= dis
->rcItem
.bottom
;
3085 DrawText(dis
->hDC
, str
, -1, &rt
, DT_SINGLELINE
|DT_NOPREFIX
|flags
);
3088 static void output_tabbed_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3090 int x
= dis
->rcItem
.left
;
3093 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
3094 rt
.top
= dis
->rcItem
.top
;
3095 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
3096 rt
.bottom
= dis
->rcItem
.bottom
;
3098 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
3099 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
3101 DrawText(dis
->hDC
, str
, -1, &rt
, DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
3104 static void output_number(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3106 int x
= dis
->rcItem
.left
;
3113 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
3114 rt
.top
= dis
->rcItem
.top
;
3115 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
3116 rt
.bottom
= dis
->rcItem
.bottom
;
3121 /* insert number separator characters */
3122 pos
= lstrlen(s
) % 3;
3128 *d
++ = Globals
.num_sep
;
3132 DrawText(dis
->hDC
, b
, d
-b
, &rt
, DT_RIGHT
|DT_SINGLELINE
|DT_NOPREFIX
|DT_END_ELLIPSIS
);
3136 static BOOL
is_exe_file(LPCTSTR ext
)
3138 static const TCHAR executable_extensions
[][4] = {
3143 #ifndef _NO_EXTENSIONS
3147 #endif /* _NO_EXTENSIONS */
3151 TCHAR ext_buffer
[_MAX_EXT
];
3152 const TCHAR (*p
)[4];
3156 for(s
=ext
+1,d
=ext_buffer
; (*d
=tolower(*s
)); s
++)
3159 for(p
=executable_extensions
; (*p
)[0]; p
++)
3160 if (!lstrcmpi(ext_buffer
, *p
))
3166 static BOOL
is_registered_type(LPCTSTR ext
)
3168 /* check if there exists a classname for this file extension in the registry */
3169 if (!RegQueryValue(HKEY_CLASSES_ROOT
, ext
, NULL
, NULL
))
3175 static enum FILE_TYPE
get_file_type(LPCTSTR filename
)
3177 LPCTSTR ext
= _tcsrchr(filename
, '.');
3181 if (is_exe_file(ext
))
3182 return FT_EXECUTABLE
;
3183 else if (is_registered_type(ext
))
3190 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
)
3192 TCHAR buffer
[BUFFER_LEN
];
3194 int visible_cols
= pane
->visible_cols
;
3195 COLORREF bkcolor
, textcolor
;
3196 RECT focusRect
= dis
->rcItem
;
3203 attrs
= entry
->data
.dwFileAttributes
;
3205 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) {
3206 if (entry
->data
.cFileName
[0] == '.' && entry
->data
.cFileName
[1] == '.'
3207 && entry
->data
.cFileName
[2] == '\0')
3208 img
= IMG_FOLDER_UP
;
3209 #ifndef _NO_EXTENSIONS
3210 else if (entry
->data
.cFileName
[0] == '.' && entry
->data
.cFileName
[1] == '\0')
3211 img
= IMG_FOLDER_CUR
;
3214 #ifdef _NO_EXTENSIONS
3217 (pane
->treePane
&& (dis
->itemState
&ODS_FOCUS
)))
3218 img
= IMG_OPEN_FOLDER
;
3222 switch(get_file_type(entry
->data
.cFileName
)) {
3223 case FT_EXECUTABLE
: img
= IMG_EXECUTABLE
; break;
3224 case FT_DOCUMENT
: img
= IMG_DOCUMENT
; break;
3225 default: img
= IMG_FILE
;
3233 if (pane
->treePane
) {
3235 img_pos
= dis
->rcItem
.left
+ entry
->level
*(IMAGE_WIDTH
+TREE_LINE_DX
);
3237 if (calcWidthCol
== -1) {
3239 int y
= dis
->rcItem
.top
+ IMAGE_HEIGHT
/2;
3242 HRGN hrgn_org
= CreateRectRgn(0, 0, 0, 0);
3245 rt_clip
.left
= dis
->rcItem
.left
;
3246 rt_clip
.top
= dis
->rcItem
.top
;
3247 rt_clip
.right
= dis
->rcItem
.left
+pane
->widths
[col
];
3248 rt_clip
.bottom
= dis
->rcItem
.bottom
;
3250 hrgn
= CreateRectRgnIndirect(&rt_clip
);
3252 if (!GetClipRgn(dis
->hDC
, hrgn_org
)) {
3253 DeleteObject(hrgn_org
);
3257 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
3258 ExtSelectClipRgn(dis
->hDC
, hrgn
, RGN_AND
);
3261 if ((up
=entry
->up
) != NULL
) {
3262 MoveToEx(dis
->hDC
, img_pos
-IMAGE_WIDTH
/2, y
, 0);
3263 LineTo(dis
->hDC
, img_pos
-2, y
);
3265 x
= img_pos
- IMAGE_WIDTH
/2;
3268 x
-= IMAGE_WIDTH
+TREE_LINE_DX
;
3272 && (up
->next
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
3275 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
3276 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
3278 } while((up
=up
->up
) != NULL
);
3281 x
= img_pos
- IMAGE_WIDTH
/2;
3283 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
3284 LineTo(dis
->hDC
, x
, y
);
3288 && (entry
->next
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
)
3291 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
3293 SelectClipRgn(dis
->hDC
, hrgn_org
);
3294 if (hrgn_org
) DeleteObject(hrgn_org
);
3295 /* SelectObject(dis->hDC, holdPen); */
3296 } else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
) {
3297 int right
= img_pos
+ IMAGE_WIDTH
- TREE_LINE_DX
;
3299 if (right
> pane
->widths
[col
])
3300 pane
->widths
[col
] = right
;
3303 img_pos
= dis
->rcItem
.left
;
3306 img_pos
= dis
->rcItem
.left
;
3308 if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3309 pane
->widths
[col
] = IMAGE_WIDTH
;
3312 if (calcWidthCol
== -1) {
3313 focusRect
.left
= img_pos
-2;
3315 #ifdef _NO_EXTENSIONS
3316 if (pane
->treePane
&& entry
) {
3319 DrawText(dis
->hDC
, entry
->data
.cFileName
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
3321 focusRect
.right
= dis
->rcItem
.left
+pane
->positions
[col
+1]+TREE_LINE_DX
+ rt
.right
+2;
3325 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
)
3326 textcolor
= COLOR_COMPRESSED
;
3328 #endif /* _NO_EXTENSIONS */
3329 textcolor
= RGB(0,0,0);
3331 if (dis
->itemState
& ODS_FOCUS
) {
3332 textcolor
= RGB(255,255,255);
3333 bkcolor
= COLOR_SELECTION
;
3335 bkcolor
= RGB(255,255,255);
3338 hbrush
= CreateSolidBrush(bkcolor
);
3339 FillRect(dis
->hDC
, &focusRect
, hbrush
);
3340 DeleteObject(hbrush
);
3342 SetBkMode(dis
->hDC
, TRANSPARENT
);
3343 SetTextColor(dis
->hDC
, textcolor
);
3345 cx
= pane
->widths
[col
];
3347 if (cx
&& img
!=IMG_NONE
) {
3348 if (cx
> IMAGE_WIDTH
)
3351 #ifdef _SHELL_FOLDERS
3352 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
3353 DrawIconEx(dis
->hDC
, img_pos
, dis
->rcItem
.top
, entry
->hicon
, cx
, GetSystemMetrics(SM_CYSMICON
), 0, 0, DI_NORMAL
);
3356 ImageList_DrawEx(Globals
.himl
, img
, dis
->hDC
,
3357 img_pos
, dis
->rcItem
.top
, cx
,
3358 IMAGE_HEIGHT
, bkcolor
, CLR_DEFAULT
, ILD_NORMAL
);
3365 #ifdef _NO_EXTENSIONS
3366 if (img
>= IMG_FOLDER_UP
)
3372 /* ouput file name */
3373 if (calcWidthCol
== -1)
3374 output_text(pane
, dis
, col
, entry
->data
.cFileName
, 0);
3375 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3376 calc_width(pane
, dis
, col
, entry
->data
.cFileName
);
3380 #ifdef _NO_EXTENSIONS
3381 if (!pane
->treePane
) {
3384 /* display file size */
3385 if (visible_cols
& COL_SIZE
) {
3386 #ifdef _NO_EXTENSIONS
3387 if (!(attrs
&FILE_ATTRIBUTE_DIRECTORY
))
3392 size
= ((ULONGLONG
)entry
->data
.nFileSizeHigh
<< 32) | entry
->data
.nFileSizeLow
;
3394 _stprintf(buffer
, sLongNumFmt
, size
);
3396 if (calcWidthCol
== -1)
3397 output_number(pane
, dis
, col
, buffer
);
3398 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3399 calc_width(pane
, dis
, col
, buffer
);/*TODO: not ever time enough */
3405 /* display file date */
3406 if (visible_cols
& (COL_DATE
|COL_TIME
)) {
3407 #ifndef _NO_EXTENSIONS
3408 format_date(&entry
->data
.ftCreationTime
, buffer
, visible_cols
);
3409 if (calcWidthCol
== -1)
3410 output_text(pane
, dis
, col
, buffer
, 0);
3411 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3412 calc_width(pane
, dis
, col
, buffer
);
3415 format_date(&entry
->data
.ftLastAccessTime
, buffer
, visible_cols
);
3416 if (calcWidthCol
== -1)
3417 output_text(pane
, dis
, col
, buffer
, 0);
3418 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3419 calc_width(pane
, dis
, col
, buffer
);
3421 #endif /* _NO_EXTENSIONS */
3423 format_date(&entry
->data
.ftLastWriteTime
, buffer
, visible_cols
);
3424 if (calcWidthCol
== -1)
3425 output_text(pane
, dis
, col
, buffer
, 0);
3426 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3427 calc_width(pane
, dis
, col
, buffer
);
3431 #ifndef _NO_EXTENSIONS
3432 if (entry
->bhfi_valid
) {
3433 ULONGLONG index
= ((ULONGLONG
)entry
->bhfi
.nFileIndexHigh
<< 32) | entry
->bhfi
.nFileIndexLow
;
3435 if (visible_cols
& COL_INDEX
) {
3436 _stprintf(buffer
, sLongHexFmt
, index
);
3438 if (calcWidthCol
== -1)
3439 output_text(pane
, dis
, col
, buffer
, DT_RIGHT
);
3440 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3441 calc_width(pane
, dis
, col
, buffer
);
3446 if (visible_cols
& COL_LINKS
) {
3447 wsprintf(buffer
, sNumFmt
, entry
->bhfi
.nNumberOfLinks
);
3449 if (calcWidthCol
== -1)
3450 output_text(pane
, dis
, col
, buffer
, DT_CENTER
);
3451 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3452 calc_width(pane
, dis
, col
, buffer
);
3458 #endif /* _NO_EXTENSIONS */
3460 /* show file attributes */
3461 if (visible_cols
& COL_ATTRIBUTES
) {
3462 #ifdef _NO_EXTENSIONS
3463 static const TCHAR s4Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3464 lstrcpy(buffer
, s4Tabs
);
3466 static const TCHAR s11Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3467 lstrcpy(buffer
, s11Tabs
);
3470 if (attrs
& FILE_ATTRIBUTE_NORMAL
) buffer
[ 0] = 'N';
3472 if (attrs
& FILE_ATTRIBUTE_READONLY
) buffer
[ 2] = 'R';
3473 if (attrs
& FILE_ATTRIBUTE_HIDDEN
) buffer
[ 4] = 'H';
3474 if (attrs
& FILE_ATTRIBUTE_SYSTEM
) buffer
[ 6] = 'S';
3475 if (attrs
& FILE_ATTRIBUTE_ARCHIVE
) buffer
[ 8] = 'A';
3476 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
) buffer
[10] = 'C';
3477 #ifndef _NO_EXTENSIONS
3478 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) buffer
[12] = 'D';
3479 if (attrs
& FILE_ATTRIBUTE_ENCRYPTED
) buffer
[14] = 'E';
3480 if (attrs
& FILE_ATTRIBUTE_TEMPORARY
) buffer
[16] = 'T';
3481 if (attrs
& FILE_ATTRIBUTE_SPARSE_FILE
) buffer
[18] = 'P';
3482 if (attrs
& FILE_ATTRIBUTE_REPARSE_POINT
) buffer
[20] = 'Q';
3483 if (attrs
& FILE_ATTRIBUTE_OFFLINE
) buffer
[22] = 'O';
3484 if (attrs
& FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
) buffer
[24] = 'X';
3485 #endif /* _NO_EXTENSIONS */
3488 if (calcWidthCol
== -1)
3489 output_tabbed_text(pane
, dis
, col
, buffer
);
3490 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3491 calc_tabbed_width(pane
, dis
, col
, buffer
);
3497 if (flags.security) {
3498 static const TCHAR sSecTabs[] = {
3499 ' ','\t',' ','\t',' ','\t',' ',
3501 ' ','\t',' ','\t',' ','\t',' ',
3503 ' ','\t',' ','\t',' ','\t',' ',
3507 DWORD rights = get_access_mask();
3509 lstrcpy(buffer, sSecTabs);
3511 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
3512 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
3513 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
3514 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
3515 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
3516 if (rights & FILE_EXECUTE) buffer[12] = 'X';
3517 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
3518 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
3519 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
3520 if (rights & WRITE_DAC) buffer[22] = 'C';
3521 if (rights & WRITE_OWNER) buffer[24] = 'O';
3522 if (rights & SYNCHRONIZE) buffer[26] = 'S';
3524 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
3527 if (flags.description) {
3528 get_description(buffer);
3529 output_text(dis, col++, buffer, 0, psize);
3533 #ifdef _NO_EXTENSIONS
3536 /* draw focus frame */
3537 if ((dis
->itemState
&ODS_FOCUS
) && calcWidthCol
==-1) {
3538 /* Currently [04/2000] Wine neither behaves exactly the same */
3539 /* way as WIN 95 nor like Windows NT... */
3544 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
3545 LOGBRUSH lb
= {PS_SOLID
, RGB(255,255,255)};
3546 hpen
= ExtCreatePen(PS_COSMETIC
|PS_ALTERNATE
, 1, &lb
, 0, 0);
3548 hpen
= CreatePen(PS_DOT
, 0, RGB(255,255,255));
3550 lastPen
= SelectPen(dis
->hDC
, hpen
);
3551 lastBrush
= SelectObject(dis
->hDC
, GetStockObject(HOLLOW_BRUSH
));
3552 SetROP2(dis
->hDC
, R2_XORPEN
);
3553 Rectangle(dis
->hDC
, focusRect
.left
, focusRect
.top
, focusRect
.right
, focusRect
.bottom
);
3554 SelectObject(dis
->hDC
, lastBrush
);
3555 SelectObject(dis
->hDC
, lastPen
);
3558 #endif /* _NO_EXTENSIONS */
3562 #ifdef _NO_EXTENSIONS
3564 static void draw_splitbar(HWND hwnd
, int x
)
3567 HDC hdc
= GetDC(hwnd
);
3569 GetClientRect(hwnd
, &rt
);
3571 rt
.left
= x
- SPLIT_WIDTH
/2;
3572 rt
.right
= x
+ SPLIT_WIDTH
/2+1;
3574 InvertRect(hdc
, &rt
);
3576 ReleaseDC(hwnd
, hdc
);
3579 #endif /* _NO_EXTENSIONS */
3582 #ifndef _NO_EXTENSIONS
3584 static void set_header(Pane
* pane
)
3587 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3590 item
.mask
= HDI_WIDTH
;
3593 for(; x
+pane
->widths
[i
]<scroll_pos
&& i
<COLUMNS
; i
++) {
3594 x
+= pane
->widths
[i
];
3595 SendMessage(pane
->hwndHeader
, HDM_SETITEM
, i
, (LPARAM
) &item
);
3599 x
+= pane
->widths
[i
];
3600 item
.cxy
= x
- scroll_pos
;
3601 SendMessage(pane
->hwndHeader
, HDM_SETITEM
, i
++, (LPARAM
) &item
);
3603 for(; i
<COLUMNS
; i
++) {
3604 item
.cxy
= pane
->widths
[i
];
3605 x
+= pane
->widths
[i
];
3606 SendMessage(pane
->hwndHeader
, HDM_SETITEM
, i
, (LPARAM
) &item
);
3611 static LRESULT
pane_notify(Pane
* pane
, NMHDR
* pnmh
)
3613 switch(pnmh
->code
) {
3614 case HDN_ITEMCHANGED
: {
3615 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3616 int idx
= phdn
->iItem
;
3617 int dx
= phdn
->pitem
->cxy
- pane
->widths
[idx
];
3621 GetClientRect(pane
->hwnd
, &clnt
);
3623 pane
->widths
[idx
] += dx
;
3625 for(i
=idx
; ++i
<=COLUMNS
; )
3626 pane
->positions
[i
] += dx
;
3629 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3633 rt_scr
.left
= pane
->positions
[idx
+1]-scroll_pos
;
3635 rt_scr
.right
= clnt
.right
;
3636 rt_scr
.bottom
= clnt
.bottom
;
3638 rt_clip
.left
= pane
->positions
[idx
]-scroll_pos
;
3640 rt_clip
.right
= clnt
.right
;
3641 rt_clip
.bottom
= clnt
.bottom
;
3643 if (rt_scr
.left
< 0) rt_scr
.left
= 0;
3644 if (rt_clip
.left
< 0) rt_clip
.left
= 0;
3646 ScrollWindowEx(pane
->hwnd
, dx
, 0, &rt_scr
, &rt_clip
, 0, 0, SW_INVALIDATE
);
3648 rt_clip
.right
= pane
->positions
[idx
+1];
3649 RedrawWindow(pane
->hwnd
, &rt_clip
, 0, RDW_INVALIDATE
|RDW_UPDATENOW
);
3651 if (pnmh
->code
== HDN_ENDTRACK
) {
3652 SendMessage(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, pane
->positions
[COLUMNS
], 0);
3654 if (GetScrollPos(pane
->hwnd
, SB_HORZ
) != scroll_pos
)
3662 case HDN_DIVIDERDBLCLICK
: {
3663 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3666 calc_single_width(pane
, phdn
->iItem
);
3667 item
.mask
= HDI_WIDTH
;
3668 item
.cxy
= pane
->widths
[phdn
->iItem
];
3670 SendMessage(pane
->hwndHeader
, HDM_SETITEM
, phdn
->iItem
, (LPARAM
) &item
);
3671 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3678 #endif /* _NO_EXTENSIONS */
3681 static void scan_entry(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3683 TCHAR path
[MAX_PATH
];
3684 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
3686 /* delete sub entries in left pane */
3688 LRESULT res
= SendMessage(child
->left
.hwnd
, LB_GETITEMDATA
, idx
+1, 0);
3689 Entry
* sub
= (Entry
*) res
;
3691 if (res
==LB_ERR
|| !sub
|| sub
->level
<=entry
->level
)
3694 SendMessage(child
->left
.hwnd
, LB_DELETESTRING
, idx
+1, 0);
3697 /* empty right pane */
3698 SendMessage(child
->right
.hwnd
, LB_RESETCONTENT
, 0, 0);
3700 /* release memory */
3701 free_entries(entry
);
3703 /* read contents from disk */
3704 #ifdef _SHELL_FOLDERS
3705 if (entry
->etype
== ET_SHELL
)
3707 read_directory(entry
, NULL
, child
->sortOrder
, hwnd
);
3712 get_path(entry
, path
);
3713 read_directory(entry
, path
, child
->sortOrder
, hwnd
);
3716 /* insert found entries in right pane */
3717 insert_entries(&child
->right
, entry
->down
, child
->filter_pattern
, child
->filter_flags
, -1);
3718 calc_widths(&child
->right
, FALSE
);
3719 #ifndef _NO_EXTENSIONS
3720 set_header(&child
->right
);
3723 child
->header_wdths_ok
= FALSE
;
3725 SetCursor(old_cursor
);
3729 /* expand a directory entry */
3731 static BOOL
expand_entry(ChildWnd
* child
, Entry
* dir
)
3736 if (!dir
|| dir
->expanded
|| !dir
->down
)
3741 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='\0' && p
->next
) {
3744 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='.' &&
3745 p
->data
.cFileName
[2]=='\0' && p
->next
)
3749 /* no subdirectories ? */
3750 if (!(p
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
3753 idx
= SendMessage(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)dir
);
3755 dir
->expanded
= TRUE
;
3757 /* insert entries in left pane */
3758 insert_entries(&child
->left
, p
, NULL
, TF_ALL
, idx
);
3760 if (!child
->header_wdths_ok
) {
3761 if (calc_widths(&child
->left
, FALSE
)) {
3762 #ifndef _NO_EXTENSIONS
3763 set_header(&child
->left
);
3766 child
->header_wdths_ok
= TRUE
;
3774 static void collapse_entry(Pane
* pane
, Entry
* dir
)
3776 int idx
= SendMessage(pane
->hwnd
, LB_FINDSTRING
, 0, (LPARAM
)dir
);
3778 ShowWindow(pane
->hwnd
, SW_HIDE
);
3780 /* hide sub entries */
3782 LRESULT res
= SendMessage(pane
->hwnd
, LB_GETITEMDATA
, idx
+1, 0);
3783 Entry
* sub
= (Entry
*) res
;
3785 if (res
==LB_ERR
|| !sub
|| sub
->level
<=dir
->level
)
3788 SendMessage(pane
->hwnd
, LB_DELETESTRING
, idx
+1, 0);
3791 dir
->expanded
= FALSE
;
3793 ShowWindow(pane
->hwnd
, SW_SHOW
);
3797 static void refresh_right_pane(ChildWnd
* child
)
3799 SendMessage(child
->right
.hwnd
, LB_RESETCONTENT
, 0, 0);
3800 insert_entries(&child
->right
, child
->right
.root
, child
->filter_pattern
, child
->filter_flags
, -1);
3801 calc_widths(&child
->right
, FALSE
);
3803 #ifndef _NO_EXTENSIONS
3804 set_header(&child
->right
);
3808 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3810 TCHAR path
[MAX_PATH
];
3817 child
->left
.cur
= entry
;
3819 child
->right
.root
= entry
->down
? entry
->down
: entry
;
3820 child
->right
.cur
= entry
;
3822 if (!entry
->scanned
)
3823 scan_entry(child
, entry
, idx
, hwnd
);
3825 refresh_right_pane(child
);
3827 get_path(entry
, path
);
3828 lstrcpy(child
->path
, path
);
3830 if (child
->hwnd
) /* only change window title, if the window already exists */
3831 SetWindowText(child
->hwnd
, path
);
3834 if (SetCurrentDirectory(path
))
3839 static void refresh_child(ChildWnd
* child
)
3841 TCHAR path
[MAX_PATH
], drv
[_MAX_DRIVE
+1];
3845 get_path(child
->left
.cur
, path
);
3846 _tsplitpath(path
, drv
, NULL
, NULL
, NULL
);
3848 child
->right
.root
= NULL
;
3850 scan_entry(child
, &child
->root
.entry
, 0, child
->hwnd
);
3852 #ifdef _SHELL_FOLDERS
3853 if (child
->root
.entry
.etype
== ET_SHELL
)
3854 entry
= read_tree(&child
->root
, NULL
, get_path_pidl(path
,child
->hwnd
), drv
, child
->sortOrder
, child
->hwnd
);
3857 entry
= read_tree(&child
->root
, path
, NULL
, drv
, child
->sortOrder
, child
->hwnd
);
3860 entry
= &child
->root
.entry
;
3862 insert_entries(&child
->left
, child
->root
.entry
.down
, NULL
, TF_ALL
, 0);
3864 set_curdir(child
, entry
, 0, child
->hwnd
);
3866 idx
= SendMessage(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)child
->left
.cur
);
3867 SendMessage(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
3871 static void create_drive_bar(void)
3873 TBBUTTON drivebarBtn
= {0, 0, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0};
3874 #ifndef _NO_EXTENSIONS
3875 TCHAR b1
[BUFFER_LEN
];
3880 GetLogicalDriveStrings(BUFFER_LEN
, Globals
.drives
);
3882 Globals
.hdrivebar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
,
3883 IDW_DRIVEBAR
, 2, Globals
.hInstance
, IDB_DRIVEBAR
, &drivebarBtn
,
3884 0, 16, 13, 16, 13, sizeof(TBBUTTON
));
3886 #ifndef _NO_EXTENSIONS
3888 /* insert unix file system button */
3892 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
3894 drivebarBtn
.idCommand
= ID_DRIVE_UNIX_FS
;
3895 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3896 drivebarBtn
.iString
++;
3898 #ifdef _SHELL_FOLDERS
3899 /* insert shell namespace button */
3900 load_string(b1
, IDS_SHELL
);
3901 b1
[lstrlen(b1
)+1] = '\0';
3902 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
3904 drivebarBtn
.idCommand
= ID_DRIVE_SHELL_NS
;
3905 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3906 drivebarBtn
.iString
++;
3909 /* register windows drive root strings */
3910 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)Globals
.drives
);
3913 drivebarBtn
.idCommand
= ID_DRIVE_FIRST
;
3915 for(p
=Globals
.drives
; *p
; ) {
3916 #ifdef _NO_EXTENSIONS
3917 /* insert drive letter */
3918 TCHAR b
[3] = {tolower(*p
)};
3919 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b
);
3921 switch(GetDriveType(p
)) {
3922 case DRIVE_REMOVABLE
: drivebarBtn
.iBitmap
= 1; break;
3923 case DRIVE_CDROM
: drivebarBtn
.iBitmap
= 3; break;
3924 case DRIVE_REMOTE
: drivebarBtn
.iBitmap
= 4; break;
3925 case DRIVE_RAMDISK
: drivebarBtn
.iBitmap
= 5; break;
3926 default:/*DRIVE_FIXED*/ drivebarBtn
.iBitmap
= 2;
3929 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3930 drivebarBtn
.idCommand
++;
3931 drivebarBtn
.iString
++;
3937 static void refresh_drives(void)
3941 /* destroy drive bar */
3942 DestroyWindow(Globals
.hdrivebar
);
3943 Globals
.hdrivebar
= 0;
3945 /* re-create drive bar */
3948 /* update window layout */
3949 GetClientRect(Globals
.hMainWnd
, &rect
);
3950 SendMessage(Globals
.hMainWnd
, WM_SIZE
, 0, MAKELONG(rect
.right
, rect
.bottom
));
3954 static BOOL
launch_file(HWND hwnd
, LPCTSTR cmd
, UINT nCmdShow
)
3956 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3958 if ((int)hinst
<= 32) {
3959 display_error(hwnd
, GetLastError());
3967 static BOOL
launch_entry(Entry
* entry
, HWND hwnd
, UINT nCmdShow
)
3969 TCHAR cmd
[MAX_PATH
];
3971 #ifdef _SHELL_FOLDERS
3972 if (entry
->etype
== ET_SHELL
) {
3975 SHELLEXECUTEINFO shexinfo
;
3977 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFO
);
3978 shexinfo
.fMask
= SEE_MASK_IDLIST
;
3979 shexinfo
.hwnd
= hwnd
;
3980 shexinfo
.lpVerb
= NULL
;
3981 shexinfo
.lpFile
= NULL
;
3982 shexinfo
.lpParameters
= NULL
;
3983 shexinfo
.lpDirectory
= NULL
;
3984 shexinfo
.nShow
= nCmdShow
;
3985 shexinfo
.lpIDList
= get_to_absolute_pidl(entry
, hwnd
);
3987 if (!ShellExecuteEx(&shexinfo
)) {
3988 display_error(hwnd
, GetLastError());
3992 if (shexinfo
.lpIDList
!= entry
->pidl
)
3993 IMalloc_Free(Globals
.iMalloc
, shexinfo
.lpIDList
);
3999 get_path(entry
, cmd
);
4001 /* start program, open document... */
4002 return launch_file(hwnd
, cmd
, nCmdShow
);
4006 static void activate_entry(ChildWnd
* child
, Pane
* pane
, HWND hwnd
)
4008 Entry
* entry
= pane
->cur
;
4013 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
4014 int scanned_old
= entry
->scanned
;
4018 int idx
= SendMessage(child
->left
.hwnd
, LB_GETCURSEL
, 0, 0);
4019 scan_entry(child
, entry
, idx
, hwnd
);
4022 #ifndef _NO_EXTENSIONS
4023 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='\0')
4027 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='.' && entry
->data
.cFileName
[2]=='\0') {
4028 entry
= child
->left
.cur
->up
;
4029 collapse_entry(&child
->left
, entry
);
4031 } else if (entry
->expanded
)
4032 collapse_entry(pane
, child
->left
.cur
);
4034 expand_entry(child
, child
->left
.cur
);
4036 if (!pane
->treePane
) focus_entry
: {
4037 int idxstart
= SendMessage(child
->left
.hwnd
, LB_GETCURSEL
, 0, 0);
4038 int idx
= SendMessage(child
->left
.hwnd
, LB_FINDSTRING
, idxstart
, (LPARAM
)entry
);
4039 SendMessage(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
4040 set_curdir(child
, entry
, idx
, hwnd
);
4045 calc_widths(pane
, FALSE
);
4047 #ifndef _NO_EXTENSIONS
4052 if (GetKeyState(VK_MENU
) < 0)
4053 show_properties_dlg(entry
, child
->hwnd
);
4055 launch_entry(entry
, child
->hwnd
, SW_SHOWNORMAL
);
4060 static BOOL
pane_command(Pane
* pane
, UINT cmd
)
4064 if (pane
->visible_cols
) {
4065 pane
->visible_cols
= 0;
4066 calc_widths(pane
, TRUE
);
4067 #ifndef _NO_EXTENSIONS
4070 InvalidateRect(pane
->hwnd
, 0, TRUE
);
4071 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
|MF_CHECKED
);
4072 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
);
4073 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
4077 case ID_VIEW_ALL_ATTRIBUTES
:
4078 if (pane
->visible_cols
!= COL_ALL
) {
4079 pane
->visible_cols
= COL_ALL
;
4080 calc_widths(pane
, TRUE
);
4081 #ifndef _NO_EXTENSIONS
4084 InvalidateRect(pane
->hwnd
, 0, TRUE
);
4085 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
);
4086 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
|MF_CHECKED
);
4087 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
4091 #ifndef _NO_EXTENSIONS
4092 case ID_PREFERRED_SIZES
: {
4093 calc_widths(pane
, TRUE
);
4095 InvalidateRect(pane
->hwnd
, 0, TRUE
);
4099 /* TODO: more command ids... */
4109 static void set_sort_order(ChildWnd
* child
, SORT_ORDER sortOrder
)
4111 if (child
->sortOrder
!= sortOrder
) {
4112 child
->sortOrder
= sortOrder
;
4113 refresh_child(child
);
4117 static void update_view_menu(ChildWnd
* child
)
4119 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_NAME
, child
->sortOrder
==SORT_NAME
? MF_CHECKED
: MF_UNCHECKED
);
4120 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_TYPE
, child
->sortOrder
==SORT_EXT
? MF_CHECKED
: MF_UNCHECKED
);
4121 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_SIZE
, child
->sortOrder
==SORT_SIZE
? MF_CHECKED
: MF_UNCHECKED
);
4122 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_DATE
, child
->sortOrder
==SORT_DATE
? MF_CHECKED
: MF_UNCHECKED
);
4126 static BOOL
is_directory(LPCTSTR target
)
4128 /*TODO correctly handle UNIX paths */
4129 DWORD target_attr
= GetFileAttributes(target
);
4131 if (target_attr
== INVALID_FILE_ATTRIBUTES
)
4134 return target_attr
&FILE_ATTRIBUTE_DIRECTORY
? TRUE
: FALSE
;
4137 static BOOL
prompt_target(Pane
* pane
, LPTSTR source
, LPTSTR target
)
4139 TCHAR path
[MAX_PATH
];
4142 get_path(pane
->cur
, path
);
4144 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_SELECT_DESTINATION
), pane
->hwnd
, DestinationDlgProc
, (LPARAM
)path
) != IDOK
)
4147 get_path(pane
->cur
, source
);
4149 /* convert relative targets to absolute paths */
4150 if (path
[0]!='/' && path
[1]!=':') {
4151 get_path(pane
->cur
->up
, target
);
4152 len
= lstrlen(target
);
4154 if (target
[len
-1]!='\\' && target
[len
-1]!='/')
4155 target
[len
++] = '/';
4157 lstrcpy(target
+len
, path
);
4159 lstrcpy(target
, path
);
4161 /* If the target already exists as directory, create a new target below this. */
4162 if (is_directory(path
)) {
4163 TCHAR fname
[_MAX_FNAME
], ext
[_MAX_EXT
];
4164 static const TCHAR sAppend
[] = {'%','s','/','%','s','%','s','\0'};
4166 _tsplitpath(source
, NULL
, NULL
, fname
, ext
);
4168 wsprintf(target
, sAppend
, path
, fname
, ext
);
4175 static IContextMenu2
* s_pctxmenu2
= NULL
;
4176 static IContextMenu3
* s_pctxmenu3
= NULL
;
4178 static void CtxMenu_reset(void)
4184 static IContextMenu
* CtxMenu_query_interfaces(IContextMenu
* pcm1
)
4186 IContextMenu
* pcm
= NULL
;
4190 if (IContextMenu_QueryInterface(pcm1
, &IID_IContextMenu3
, (void**)&pcm
) == NOERROR
)
4191 s_pctxmenu3
= (LPCONTEXTMENU3
)pcm
;
4192 else if (IContextMenu_QueryInterface(pcm1
, &IID_IContextMenu2
, (void**)&pcm
) == NOERROR
)
4193 s_pctxmenu2
= (LPCONTEXTMENU2
)pcm
;
4196 IContextMenu_Release(pcm1
);
4202 static BOOL
CtxMenu_HandleMenuMsg(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4205 if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3
, nmsg
, wparam
, lparam
)))
4210 if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2
, nmsg
, wparam
, lparam
)))
4217 static HRESULT
ShellFolderContextMenu(IShellFolder
* shell_folder
, HWND hwndParent
, int cidl
, LPCITEMIDLIST
* apidl
, int x
, int y
)
4220 BOOL executed
= FALSE
;
4222 HRESULT hr
= IShellFolder_GetUIObjectOf(shell_folder
, hwndParent
, cidl
, apidl
, &IID_IContextMenu
, NULL
, (LPVOID
*)&pcm
);
4223 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
4225 if (SUCCEEDED(hr
)) {
4226 HMENU hmenu
= CreatePopupMenu();
4228 pcm
= CtxMenu_query_interfaces(pcm
);
4231 hr
= IContextMenu_QueryContextMenu(pcm
, hmenu
, 0, FCIDM_SHVIEWFIRST
, FCIDM_SHVIEWLAST
, CMF_NORMAL
);
4233 if (SUCCEEDED(hr
)) {
4234 UINT idCmd
= TrackPopupMenu(hmenu
, TPM_LEFTALIGN
|TPM_RETURNCMD
|TPM_RIGHTBUTTON
, x
, y
, 0, hwndParent
, NULL
);
4239 CMINVOKECOMMANDINFO cmi
;
4241 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFO
);
4243 cmi
.hwnd
= hwndParent
;
4244 cmi
.lpVerb
= (LPCSTR
)(INT_PTR
)(idCmd
- FCIDM_SHVIEWFIRST
);
4245 cmi
.lpParameters
= NULL
;
4246 cmi
.lpDirectory
= NULL
;
4247 cmi
.nShow
= SW_SHOWNORMAL
;
4251 hr
= IContextMenu_InvokeCommand(pcm
, &cmi
);
4258 IContextMenu_Release(pcm
);
4261 return FAILED(hr
)? hr
: executed
? S_OK
: S_FALSE
;
4265 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4267 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
4272 LPDRAWITEMSTRUCT dis
= (LPDRAWITEMSTRUCT
)lparam
;
4273 Entry
* entry
= (Entry
*) dis
->itemData
;
4275 if (dis
->CtlID
== IDW_TREE_LEFT
)
4276 draw_item(&child
->left
, dis
, entry
, -1);
4277 else if (dis
->CtlID
== IDW_TREE_RIGHT
)
4278 draw_item(&child
->right
, dis
, entry
, -1);
4280 goto draw_menu_item
;
4285 InitChildWindow(child
);
4289 free_child_window(child
);
4290 SetWindowLongPtr(hwnd
, GWLP_USERDATA
, 0);
4297 GetClientRect(hwnd
, &rt
);
4298 BeginPaint(hwnd
, &ps
);
4299 rt
.left
= child
->split_pos
-SPLIT_WIDTH
/2;
4300 rt
.right
= child
->split_pos
+SPLIT_WIDTH
/2+1;
4301 lastBrush
= SelectObject(ps
.hdc
, GetStockObject(COLOR_SPLITBAR
));
4302 Rectangle(ps
.hdc
, rt
.left
, rt
.top
-1, rt
.right
, rt
.bottom
+1);
4303 SelectObject(ps
.hdc
, lastBrush
);
4304 #ifdef _NO_EXTENSIONS
4305 rt
.top
= rt
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
4306 FillRect(ps
.hdc
, &rt
, GetStockObject(BLACK_BRUSH
));
4308 EndPaint(hwnd
, &ps
);
4312 if (LOWORD(lparam
) == HTCLIENT
) {
4315 ScreenToClient(hwnd
, &pt
);
4317 if (pt
.x
>=child
->split_pos
-SPLIT_WIDTH
/2 && pt
.x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
4318 SetCursor(LoadCursor(0, IDC_SIZEWE
));
4324 case WM_LBUTTONDOWN
: {
4326 int x
= (short)LOWORD(lparam
);
4328 GetClientRect(hwnd
, &rt
);
4330 if (x
>=child
->split_pos
-SPLIT_WIDTH
/2 && x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
4331 last_split
= child
->split_pos
;
4332 #ifdef _NO_EXTENSIONS
4333 draw_splitbar(hwnd
, last_split
);
4341 if (GetCapture() == hwnd
) {
4342 #ifdef _NO_EXTENSIONS
4344 int x
= (short)LOWORD(lparam
);
4345 draw_splitbar(hwnd
, last_split
);
4347 GetClientRect(hwnd
, &rt
);
4348 child
->split_pos
= x
;
4349 resize_tree(child
, rt
.right
, rt
.bottom
);
4355 #ifdef _NO_EXTENSIONS
4356 case WM_CAPTURECHANGED
:
4357 if (GetCapture()==hwnd
&& last_split
>=0)
4358 draw_splitbar(hwnd
, last_split
);
4363 if (wparam
== VK_ESCAPE
)
4364 if (GetCapture() == hwnd
) {
4366 #ifdef _NO_EXTENSIONS
4367 draw_splitbar(hwnd
, last_split
);
4369 child
->split_pos
= last_split
;
4371 GetClientRect(hwnd
, &rt
);
4372 resize_tree(child
, rt
.right
, rt
.bottom
);
4375 SetCursor(LoadCursor(0, IDC_ARROW
));
4380 if (GetCapture() == hwnd
) {
4382 int x
= (short)LOWORD(lparam
);
4384 #ifdef _NO_EXTENSIONS
4385 HDC hdc
= GetDC(hwnd
);
4386 GetClientRect(hwnd
, &rt
);
4388 rt
.left
= last_split
-SPLIT_WIDTH
/2;
4389 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
4390 InvertRect(hdc
, &rt
);
4393 rt
.left
= x
-SPLIT_WIDTH
/2;
4394 rt
.right
= x
+SPLIT_WIDTH
/2+1;
4395 InvertRect(hdc
, &rt
);
4397 ReleaseDC(hwnd
, hdc
);
4399 GetClientRect(hwnd
, &rt
);
4401 if (x
>=0 && x
<rt
.right
) {
4402 child
->split_pos
= x
;
4403 resize_tree(child
, rt
.right
, rt
.bottom
);
4404 rt
.left
= x
-SPLIT_WIDTH
/2;
4405 rt
.right
= x
+SPLIT_WIDTH
/2+1;
4406 InvalidateRect(hwnd
, &rt
, FALSE
);
4407 UpdateWindow(child
->left
.hwnd
);
4409 UpdateWindow(child
->right
.hwnd
);
4415 #ifndef _NO_EXTENSIONS
4416 case WM_GETMINMAXINFO
:
4417 DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
4419 {LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
4421 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
4422 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
4424 #endif /* _NO_EXTENSIONS */
4427 if (SetCurrentDirectory(child
->path
))
4429 SetFocus(child
->focus_pane
? child
->right
.hwnd
: child
->left
.hwnd
);
4432 case WM_DISPATCH_COMMAND
: {
4433 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4435 switch(LOWORD(wparam
)) {
4436 case ID_WINDOW_NEW
: {
4437 ChildWnd
* new_child
= alloc_child_window(child
->path
, NULL
, hwnd
);
4439 if (!create_child_window(new_child
))
4440 HeapFree(GetProcessHeap(), 0, new_child
);
4446 refresh_child(child
);
4450 activate_entry(child
, pane
, hwnd
);
4453 case ID_FILE_MOVE
: {
4454 TCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
4456 if (prompt_target(pane
, source
, target
)) {
4457 SHFILEOPSTRUCT shfo
= {hwnd
, FO_MOVE
, source
, target
};
4459 source
[lstrlen(source
)+1] = '\0';
4460 target
[lstrlen(target
)+1] = '\0';
4462 if (!SHFileOperation(&shfo
))
4463 refresh_child(child
);
4467 case ID_FILE_COPY
: {
4468 TCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
4470 if (prompt_target(pane
, source
, target
)) {
4471 SHFILEOPSTRUCT shfo
= {hwnd
, FO_COPY
, source
, target
};
4473 source
[lstrlen(source
)+1] = '\0';
4474 target
[lstrlen(target
)+1] = '\0';
4476 if (!SHFileOperation(&shfo
))
4477 refresh_child(child
);
4481 case ID_FILE_DELETE
: {
4482 TCHAR path
[BUFFER_LEN
];
4483 SHFILEOPSTRUCT shfo
= {hwnd
, FO_DELETE
, path
};
4485 get_path(pane
->cur
, path
);
4487 path
[lstrlen(path
)+1] = '\0';
4489 if (!SHFileOperation(&shfo
))
4490 refresh_child(child
);
4493 case ID_VIEW_SORT_NAME
:
4494 set_sort_order(child
, SORT_NAME
);
4497 case ID_VIEW_SORT_TYPE
:
4498 set_sort_order(child
, SORT_EXT
);
4501 case ID_VIEW_SORT_SIZE
:
4502 set_sort_order(child
, SORT_SIZE
);
4505 case ID_VIEW_SORT_DATE
:
4506 set_sort_order(child
, SORT_DATE
);
4509 case ID_VIEW_FILTER
: {
4510 struct FilterDialog dlg
;
4512 memset(&dlg
, 0, sizeof(struct FilterDialog
));
4513 lstrcpy(dlg
.pattern
, child
->filter_pattern
);
4514 dlg
.flags
= child
->filter_flags
;
4516 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE
), hwnd
, FilterDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
4517 lstrcpy(child
->filter_pattern
, dlg
.pattern
);
4518 child
->filter_flags
= dlg
.flags
;
4519 refresh_right_pane(child
);
4523 case ID_VIEW_SPLIT
: {
4524 last_split
= child
->split_pos
;
4525 #ifdef _NO_EXTENSIONS
4526 draw_splitbar(hwnd
, last_split
);
4531 case ID_EDIT_PROPERTIES
:
4532 show_properties_dlg(pane
->cur
, child
->hwnd
);
4536 return pane_command(pane
, LOWORD(wparam
));
4542 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4544 switch(HIWORD(wparam
)) {
4545 case LBN_SELCHANGE
: {
4546 int idx
= SendMessage(pane
->hwnd
, LB_GETCURSEL
, 0, 0);
4547 Entry
* entry
= (Entry
*) SendMessage(pane
->hwnd
, LB_GETITEMDATA
, idx
, 0);
4549 if (pane
== &child
->left
)
4550 set_curdir(child
, entry
, idx
, hwnd
);
4556 activate_entry(child
, pane
, hwnd
);
4561 #ifndef _NO_EXTENSIONS
4563 NMHDR
* pnmh
= (NMHDR
*) lparam
;
4564 return pane_notify(pnmh
->idFrom
==IDW_HEADER_LEFT
? &child
->left
: &child
->right
, pnmh
);}
4567 #ifdef _SHELL_FOLDERS
4568 case WM_CONTEXTMENU
: {
4573 /* first select the current item in the listbox */
4574 HWND hpanel
= (HWND
) wparam
;
4575 pt_clnt
.x
= pt
.x
= (short)LOWORD(lparam
);
4576 pt_clnt
.y
= pt
.y
= (short)HIWORD(lparam
);
4577 ScreenToClient(hpanel
, &pt_clnt
);
4578 SendMessage(hpanel
, WM_LBUTTONDOWN
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4579 SendMessage(hpanel
, WM_LBUTTONUP
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4581 /* now create the popup menu using shell namespace and IContextMenu */
4582 pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4583 idx
= SendMessage(pane
->hwnd
, LB_GETCURSEL
, 0, 0);
4586 Entry
* entry
= (Entry
*) SendMessage(pane
->hwnd
, LB_GETITEMDATA
, idx
, 0);
4588 LPITEMIDLIST pidl_abs
= get_to_absolute_pidl(entry
, hwnd
);
4591 IShellFolder
* parentFolder
;
4592 LPCITEMIDLIST pidlLast
;
4594 /* get and use the parent folder to display correct context menu in all cases */
4595 if (SUCCEEDED(SHBindToParent(pidl_abs
, &IID_IShellFolder
, (LPVOID
*)&parentFolder
, &pidlLast
))) {
4596 if (ShellFolderContextMenu(parentFolder
, hwnd
, 1, &pidlLast
, pt
.x
, pt
.y
) == S_OK
)
4597 refresh_child(child
);
4599 IShellFolder_Release(parentFolder
);
4602 IMalloc_Free(Globals
.iMalloc
, pidl_abs
);
4608 case WM_MEASUREITEM
:
4610 if (!wparam
) /* Is the message menu-related? */
4611 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4616 case WM_INITMENUPOPUP
:
4617 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4620 update_view_menu(child
);
4623 case WM_MENUCHAR
: /* only supported by IContextMenu3 */
4625 LRESULT lResult
= 0;
4627 IContextMenu3_HandleMenuMsg2(s_pctxmenu3
, nmsg
, wparam
, lparam
, &lResult
);
4635 if (wparam
!= SIZE_MINIMIZED
)
4636 resize_tree(child
, LOWORD(lparam
), HIWORD(lparam
));
4640 return DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
4647 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4649 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(GetParent(hwnd
), GWLP_USERDATA
);
4650 Pane
* pane
= (Pane
*) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
4654 #ifndef _NO_EXTENSIONS
4661 child
->focus_pane
= pane
==&child
->right
? 1: 0;
4662 SendMessage(hwnd
, LB_SETSEL
, TRUE
, 1);
4663 /*TODO: check menu items */
4667 if (wparam
== VK_TAB
) {
4668 /*TODO: SetFocus(Globals.hdrivebar) */
4669 SetFocus(child
->focus_pane
? child
->left
.hwnd
: child
->right
.hwnd
);
4673 return CallWindowProc(g_orgTreeWndProc
, hwnd
, nmsg
, wparam
, lparam
);
4677 static void InitInstance(HINSTANCE hinstance
)
4679 static const TCHAR sFont
[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4686 INITCOMMONCONTROLSEX icc
= {
4687 sizeof(INITCOMMONCONTROLSEX
),
4693 setlocale(LC_COLLATE
, ""); /* set collating rules to local settings for compareName */
4695 InitCommonControlsEx(&icc
);
4698 /* register frame window class */
4700 wcFrame
.cbSize
= sizeof(WNDCLASSEX
);
4702 wcFrame
.lpfnWndProc
= FrameWndProc
;
4703 wcFrame
.cbClsExtra
= 0;
4704 wcFrame
.cbWndExtra
= 0;
4705 wcFrame
.hInstance
= hinstance
;
4706 wcFrame
.hIcon
= LoadIcon(hinstance
, MAKEINTRESOURCE(IDI_WINEFILE
));
4707 wcFrame
.hCursor
= LoadCursor(0, IDC_ARROW
);
4708 wcFrame
.hbrBackground
= 0;
4709 wcFrame
.lpszMenuName
= 0;
4710 wcFrame
.lpszClassName
= sWINEFILEFRAME
;
4711 wcFrame
.hIconSm
= (HICON
)LoadImage(hinstance
,
4712 MAKEINTRESOURCE(IDI_WINEFILE
),
4714 GetSystemMetrics(SM_CXSMICON
),
4715 GetSystemMetrics(SM_CYSMICON
),
4718 Globals
.hframeClass
= RegisterClassEx(&wcFrame
);
4721 /* register tree windows class */
4723 wcChild
.style
= CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
;
4724 wcChild
.lpfnWndProc
= ChildWndProc
;
4725 wcChild
.cbClsExtra
= 0;
4726 wcChild
.cbWndExtra
= 0;
4727 wcChild
.hInstance
= hinstance
;
4729 wcChild
.hCursor
= LoadCursor(0, IDC_ARROW
);
4730 wcChild
.hbrBackground
= 0;
4731 wcChild
.lpszMenuName
= 0;
4732 wcChild
.lpszClassName
= sWINEFILETREE
;
4734 hChildClass
= RegisterClass(&wcChild
);
4737 Globals
.haccel
= LoadAccelerators(hinstance
, MAKEINTRESOURCE(IDA_WINEFILE
));
4739 Globals
.hfont
= CreateFont(-MulDiv(8,GetDeviceCaps(hdc
,LOGPIXELSY
),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont
);
4743 Globals
.hInstance
= hinstance
;
4745 #ifdef _SHELL_FOLDERS
4747 CoGetMalloc(MEMCTX_TASK
, &Globals
.iMalloc
);
4748 SHGetDesktopFolder(&Globals
.iDesktop
);
4750 Globals
.cfStrFName
= RegisterClipboardFormatA(CFSTR_FILENAME
);
4752 Globals
.cfStrFName
= RegisterClipboardFormat(CFSTR_FILENAME
);
4756 /* load column strings */
4759 load_string(g_pos_names
[col
++], IDS_COL_NAME
);
4760 load_string(g_pos_names
[col
++], IDS_COL_SIZE
);
4761 load_string(g_pos_names
[col
++], IDS_COL_CDATE
);
4762 #ifndef _NO_EXTENSIONS
4763 load_string(g_pos_names
[col
++], IDS_COL_ADATE
);
4764 load_string(g_pos_names
[col
++], IDS_COL_MDATE
);
4765 load_string(g_pos_names
[col
++], IDS_COL_IDX
);
4766 load_string(g_pos_names
[col
++], IDS_COL_LINKS
);
4768 load_string(g_pos_names
[col
++], IDS_COL_ATTR
);
4769 #ifndef _NO_EXTENSIONS
4770 load_string(g_pos_names
[col
++], IDS_COL_SEC
);
4775 static void show_frame(HWND hwndParent
, int cmdshow
, LPCTSTR path
)
4777 static const TCHAR sMDICLIENT
[] = {'M','D','I','C','L','I','E','N','T','\0'};
4779 TCHAR buffer
[MAX_PATH
], b1
[BUFFER_LEN
];
4781 HMENU hMenuFrame
, hMenuWindow
;
4784 CLIENTCREATESTRUCT ccs
;
4786 if (Globals
.hMainWnd
)
4789 opts
= load_registry_settings();
4790 hMenuFrame
= LoadMenu(Globals
.hInstance
, MAKEINTRESOURCE(IDM_WINEFILE
));
4791 hMenuWindow
= GetSubMenu(hMenuFrame
, GetMenuItemCount(hMenuFrame
)-2);
4793 Globals
.hMenuFrame
= hMenuFrame
;
4794 Globals
.hMenuView
= GetSubMenu(hMenuFrame
, 3);
4795 Globals
.hMenuOptions
= GetSubMenu(hMenuFrame
, 4);
4797 ccs
.hWindowMenu
= hMenuWindow
;
4798 ccs
.idFirstChild
= IDW_FIRST_CHILD
;
4801 /* create main window */
4802 Globals
.hMainWnd
= CreateWindowEx(0, (LPCTSTR
)(int)Globals
.hframeClass
, RS(b1
,IDS_WINE_FILE
), WS_OVERLAPPEDWINDOW
,
4803 opts
.start_x
, opts
.start_y
, opts
.width
, opts
.height
,
4804 hwndParent
, Globals
.hMenuFrame
, Globals
.hInstance
, 0/*lpParam*/);
4807 Globals
.hmdiclient
= CreateWindowEx(0, sMDICLIENT
, NULL
,
4808 WS_CHILD
|WS_CLIPCHILDREN
|WS_VSCROLL
|WS_HSCROLL
|WS_VISIBLE
|WS_BORDER
,
4810 Globals
.hMainWnd
, 0, Globals
.hInstance
, &ccs
);
4812 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_DRIVE_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4813 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_SAVESETTINGS
, MF_BYCOMMAND
);
4818 TBBUTTON toolbarBtns
[] = {
4819 {0, 0, 0, BTNS_SEP
, {0, 0}, 0, 0},
4820 {0, ID_WINDOW_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4821 {1, ID_WINDOW_CASCADE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4822 {2, ID_WINDOW_TILE_HORZ
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4823 {3, ID_WINDOW_TILE_VERT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4825 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4826 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4829 Globals
.htoolbar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
,
4830 IDW_TOOLBAR
, 2, Globals
.hInstance
, IDB_TOOLBAR
, toolbarBtns
,
4831 sizeof(toolbarBtns
)/sizeof(TBBUTTON
), 16, 15, 16, 15, sizeof(TBBUTTON
));
4832 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_TOOL_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4835 Globals
.hstatusbar
= CreateStatusWindow(WS_CHILD
|WS_VISIBLE
, 0, Globals
.hMainWnd
, IDW_STATUSBAR
);
4836 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
4838 /* CreateStatusWindow does not accept WS_BORDER
4839 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
4840 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
4841 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
4843 /*TODO: read paths from registry */
4845 if (!path
|| !*path
) {
4846 GetCurrentDirectory(MAX_PATH
, buffer
);
4850 ShowWindow(Globals
.hMainWnd
, cmdshow
);
4852 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4853 /* Shell Namespace as default: */
4854 child
= alloc_child_window(path
, get_path_pidl(path
,Globals
.hMainWnd
), Globals
.hMainWnd
);
4856 child
= alloc_child_window(path
, NULL
, Globals
.hMainWnd
);
4859 child
->pos
.showCmd
= SW_SHOWMAXIMIZED
;
4860 child
->pos
.rcNormalPosition
.left
= 0;
4861 child
->pos
.rcNormalPosition
.top
= 0;
4862 child
->pos
.rcNormalPosition
.right
= 320;
4863 child
->pos
.rcNormalPosition
.bottom
= 280;
4865 if (!create_child_window(child
))
4866 HeapFree(GetProcessHeap(), 0, child
);
4868 SetWindowPlacement(child
->hwnd
, &child
->pos
);
4870 Globals
.himl
= ImageList_LoadBitmap(Globals
.hInstance
, MAKEINTRESOURCE(IDB_IMAGES
), 16, 0, RGB(0,255,0));
4872 Globals
.prescan_node
= FALSE
;
4874 UpdateWindow(Globals
.hMainWnd
);
4876 if (path
&& path
[0])
4879 TCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
4880 TCHAR fullname
[_MAX_FNAME
+_MAX_EXT
+1];
4882 memset(name
,0,sizeof(name
));
4883 memset(name
,0,sizeof(ext
));
4884 _tsplitpath(path
, drv
, dir
, name
, ext
);
4887 count
= SendMessage(child
->right
.hwnd
, LB_GETCOUNT
, 0, 0);
4888 lstrcpy(fullname
,name
);
4889 lstrcat(fullname
,ext
);
4891 for (index
= 0; index
< count
; index
++)
4893 Entry
* entry
= (Entry
*) SendMessage(child
->right
.hwnd
, LB_GETITEMDATA
, index
, 0);
4894 if (lstrcmp(entry
->data
.cFileName
,fullname
)==0 ||
4895 lstrcmp(entry
->data
.cAlternateFileName
,fullname
)==0)
4897 SendMessage(child
->right
.hwnd
, LB_SETCURSEL
, index
, 0);
4898 SetFocus(child
->right
.hwnd
);
4906 static void ExitInstance(void)
4908 #ifdef _SHELL_FOLDERS
4909 IShellFolder_Release(Globals
.iDesktop
);
4910 IMalloc_Release(Globals
.iMalloc
);
4914 DeleteObject(Globals
.hfont
);
4915 ImageList_Destroy(Globals
.himl
);
4918 #ifdef _NO_EXTENSIONS
4920 /* search for already running win[e]files */
4922 static int g_foundPrevInstance
= 0;
4924 static BOOL CALLBACK
EnumWndProc(HWND hwnd
, LPARAM lparam
)
4928 GetClassName(hwnd
, cls
, 128);
4930 if (!lstrcmp(cls
, (LPCTSTR
)lparam
)) {
4931 g_foundPrevInstance
++;
4938 /* search for window of given class name to allow only one running instance */
4939 static int find_window_class(LPCTSTR classname
)
4941 EnumWindows(EnumWndProc
, (LPARAM
)classname
);
4943 if (g_foundPrevInstance
)
4951 static int winefile_main(HINSTANCE hinstance
, int cmdshow
, LPCTSTR path
)
4955 InitInstance(hinstance
);
4957 show_frame(0, cmdshow
, path
);
4959 while(GetMessage(&msg
, 0, 0, 0)) {
4960 if (Globals
.hmdiclient
&& TranslateMDISysAccel(Globals
.hmdiclient
, &msg
))
4963 if (Globals
.hMainWnd
&& TranslateAccelerator(Globals
.hMainWnd
, Globals
.haccel
, &msg
))
4966 TranslateMessage(&msg
);
4967 DispatchMessage(&msg
);
4976 #if defined(UNICODE) && defined(_MSC_VER)
4977 int APIENTRY
wWinMain(HINSTANCE hinstance
, HINSTANCE previnstance
, LPWSTR cmdline
, int cmdshow
)
4979 int APIENTRY
WinMain(HINSTANCE hinstance
, HINSTANCE previnstance
, LPSTR cmdline
, int cmdshow
)
4982 #ifdef _NO_EXTENSIONS
4983 if (find_window_class(sWINEFILEFRAME
))
4987 #if defined(UNICODE) && !defined(_MSC_VER)
4988 { /* convert ANSI cmdline into WCS path string */
4989 TCHAR buffer
[MAX_PATH
];
4990 MultiByteToWideChar(CP_ACP
, 0, cmdline
, -1, buffer
, MAX_PATH
);
4991 winefile_main(hinstance
, cmdshow
, buffer
);
4994 winefile_main(hinstance
, cmdshow
, cmdline
);