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>
36 #include "wine/unicode.h"
44 #define _MAX_FNAME 256
45 #define _MAX_DIR _MAX_FNAME
46 #define _MAX_EXT _MAX_FNAME
50 #ifdef NONAMELESSUNION
51 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
53 #define UNION_MEMBER(x) x
58 #define DEFAULT_SPLIT_POS 300
60 #define DEFAULT_SPLIT_POS 200
63 static const WCHAR registry_key
[] = { 'S','o','f','t','w','a','r','e','\\',
65 'W','i','n','e','F','i','l','e','\0'};
66 static const WCHAR reg_start_x
[] = { 's','t','a','r','t','X','\0'};
67 static const WCHAR reg_start_y
[] = { 's','t','a','r','t','Y','\0'};
68 static const WCHAR reg_width
[] = { 'w','i','d','t','h','\0'};
69 static const WCHAR reg_height
[] = { 'h','e','i','g','h','t','\0'};
70 static const WCHAR reg_logfont
[] = { 'l','o','g','f','o','n','t','\0'};
80 typedef struct _Entry
{
91 #ifndef _NO_EXTENSIONS
92 BY_HANDLE_FILE_INFORMATION bhfi
;
94 enum ENTRY_TYPE etype
;
105 TCHAR path
[MAX_PATH
];
106 TCHAR volname
[_MAX_FNAME
];
116 COL_ATTRIBUTES
= 0x08,
118 #ifdef _NO_EXTENSIONS
119 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
123 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
|COL_INDEX
|COL_LINKS
136 #ifndef _NO_EXTENSIONS
140 #ifndef _NO_EXTENSIONS
146 int positions
[COLUMNS
+1];
158 int focus_pane
; /* 0: left 1: right */
161 BOOL header_wdths_ok
;
163 TCHAR path
[MAX_PATH
];
164 TCHAR filter_pattern
[MAX_PATH
];
168 SORT_ORDER sortOrder
;
173 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
);
174 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
);
175 static void refresh_child(ChildWnd
* child
);
176 static void refresh_drives(void);
177 static void get_path(Entry
* dir
, PTSTR path
);
178 static void format_date(const FILETIME
* ft
, TCHAR
* buffer
, int visible_cols
);
180 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
181 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
182 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
186 WINEFILE_GLOBALS Globals
;
188 static int last_split
;
190 /* some common string constants */
191 static const TCHAR sEmpty
[] = {'\0'};
192 static const WCHAR sSpace
[] = {' ', '\0'};
193 static const TCHAR sNumFmt
[] = {'%','d','\0'};
194 static const TCHAR sQMarks
[] = {'?','?','?','\0'};
196 /* window class names */
197 static const TCHAR sWINEFILEFRAME
[] = {'W','F','S','_','F','r','a','m','e','\0'};
198 static const TCHAR sWINEFILETREE
[] = {'W','F','S','_','T','r','e','e','\0'};
200 static void format_longlong(LPWSTR ret
, ULONGLONG val
)
202 WCHAR buffer
[65], *p
= &buffer
[64];
206 *(--p
) = '0' + val
% 10;
213 /* load resource string */
214 static LPTSTR
load_string(LPTSTR buffer
, DWORD size
, UINT id
)
216 LoadString(Globals
.hInstance
, id
, buffer
, size
);
220 #define RS(b, i) load_string(b, sizeof(b)/sizeof(b[0]), i)
223 /* display error message for the specified WIN32 error code */
224 static void display_error(HWND hwnd
, DWORD error
)
226 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
229 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_FROM_SYSTEM
,
230 0, error
, MAKELANGID(LANG_NEUTRAL
,SUBLANG_DEFAULT
), (PTSTR
)&msg
, 0, NULL
))
231 MessageBox(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
233 MessageBox(hwnd
, RS(b1
,IDS_ERROR
), RS(b2
,IDS_WINEFILE
), MB_OK
);
239 /* display network error message using WNetGetLastError() */
240 static void display_network_error(HWND hwnd
)
242 TCHAR msg
[BUFFER_LEN
], provider
[BUFFER_LEN
], b2
[BUFFER_LEN
];
245 if (WNetGetLastError(&error
, msg
, BUFFER_LEN
, provider
, BUFFER_LEN
) == NO_ERROR
)
246 MessageBox(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
249 static inline BOOL
get_check(HWND hwnd
, INT id
)
251 return BST_CHECKED
&SendMessageW(GetDlgItem(hwnd
, id
), BM_GETSTATE
, 0, 0);
254 static inline INT
set_check(HWND hwnd
, INT id
, BOOL on
)
256 return SendMessageW(GetDlgItem(hwnd
, id
), BM_SETCHECK
, on
?BST_CHECKED
:BST_UNCHECKED
, 0);
259 static inline void choose_font(HWND hwnd
)
261 WCHAR dlg_name
[BUFFER_LEN
], dlg_info
[BUFFER_LEN
];
265 HDC hdc
= GetDC(hwnd
);
266 chFont
.lStructSize
= sizeof(CHOOSEFONT
);
267 chFont
.hwndOwner
= hwnd
;
269 chFont
.lpLogFont
= &lFont
;
270 chFont
.Flags
= CF_SCREENFONTS
| CF_FORCEFONTEXIST
| CF_LIMITSIZE
| CF_NOSCRIPTSEL
;
271 chFont
.rgbColors
= RGB(0,0,0);
272 chFont
.lCustData
= 0;
273 chFont
.lpfnHook
= NULL
;
274 chFont
.lpTemplateName
= NULL
;
275 chFont
.hInstance
= Globals
.hInstance
;
276 chFont
.lpszStyle
= NULL
;
277 chFont
.nFontType
= SIMULATED_FONTTYPE
;
279 chFont
.nSizeMax
= 24;
281 if (ChooseFontW(&chFont
)) {
285 DeleteObject(Globals
.hfont
);
286 Globals
.hfont
= CreateFontIndirectW(&lFont
);
287 hFontOld
= SelectObject(hdc
, Globals
.hfont
);
288 GetTextExtentPoint32W(hdc
, sSpace
, 1, &Globals
.spaceSize
);
290 /* change font in all open child windows */
291 for(childWnd
=GetWindow(Globals
.hmdiclient
,GW_CHILD
); childWnd
; childWnd
=GetNextWindow(childWnd
,GW_HWNDNEXT
)) {
292 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtrW(childWnd
, GWLP_USERDATA
);
293 SendMessageW(child
->left
.hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, TRUE
);
294 SendMessageW(child
->right
.hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, TRUE
);
295 SendMessageW(child
->left
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
296 SendMessageW(child
->right
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
297 InvalidateRect(child
->left
.hwnd
, NULL
, TRUE
);
298 InvalidateRect(child
->right
.hwnd
, NULL
, TRUE
);
301 SelectObject(hdc
, hFontOld
);
303 else if (CommDlgExtendedError()) {
304 LoadStringW(Globals
.hInstance
, IDS_FONT_SEL_DLG_NAME
, dlg_name
, BUFFER_LEN
);
305 LoadStringW(Globals
.hInstance
, IDS_FONT_SEL_ERROR
, dlg_info
, BUFFER_LEN
);
306 MessageBoxW(hwnd
, dlg_info
, dlg_name
, MB_OK
);
309 ReleaseDC(hwnd
, hdc
);
313 /* allocate and initialise a directory entry */
314 static Entry
* alloc_entry(void)
316 Entry
* entry
= HeapAlloc(GetProcessHeap(), 0, sizeof(Entry
));
318 #ifdef _SHELL_FOLDERS
320 entry
->folder
= NULL
;
327 /* free a directory entry */
328 static void free_entry(Entry
* entry
)
330 #ifdef _SHELL_FOLDERS
331 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
332 DestroyIcon(entry
->hicon
);
334 if (entry
->folder
&& entry
->folder
!=Globals
.iDesktop
)
335 IShellFolder_Release(entry
->folder
);
338 IMalloc_Free(Globals
.iMalloc
, entry
->pidl
);
341 HeapFree(GetProcessHeap(), 0, entry
);
344 /* recursively free all child entries */
345 static void free_entries(Entry
* dir
)
347 Entry
*entry
, *next
=dir
->down
;
363 static void read_directory_win(Entry
* dir
, LPCTSTR path
)
365 Entry
* first_entry
= NULL
;
369 int level
= dir
->level
+ 1;
370 WIN32_FIND_DATA w32fd
;
372 #ifndef _NO_EXTENSIONS
376 TCHAR buffer
[MAX_PATH
], *p
;
377 for(p
=buffer
; *path
; )
384 hFind
= FindFirstFile(buffer
, &w32fd
);
386 if (hFind
!= INVALID_HANDLE_VALUE
) {
388 #ifdef _NO_EXTENSIONS
389 /* hide directory entry "." */
390 if (w32fd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
391 LPCTSTR name
= w32fd
.cFileName
;
393 if (name
[0]=='.' && name
[1]=='\0')
397 entry
= alloc_entry();
405 memcpy(&entry
->data
, &w32fd
, sizeof(WIN32_FIND_DATA
));
408 entry
->expanded
= FALSE
;
409 entry
->scanned
= FALSE
;
410 entry
->level
= level
;
412 #ifndef _NO_EXTENSIONS
413 entry
->etype
= ET_WINDOWS
;
414 entry
->bhfi_valid
= FALSE
;
416 lstrcpy(p
, entry
->data
.cFileName
);
418 hFile
= CreateFile(buffer
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
419 0, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0);
421 if (hFile
!= INVALID_HANDLE_VALUE
) {
422 if (GetFileInformationByHandle(hFile
, &entry
->bhfi
))
423 entry
->bhfi_valid
= TRUE
;
430 } while(FindNextFile(hFind
, &w32fd
));
438 dir
->down
= first_entry
;
443 static Entry
* find_entry_win(Entry
* dir
, LPCTSTR name
)
447 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
449 LPCTSTR q
= entry
->data
.cFileName
;
452 if (!*p
|| *p
== '\\' || *p
== '/')
454 } while(tolower(*p
++) == tolower(*q
++));
457 q
= entry
->data
.cAlternateFileName
;
460 if (!*p
|| *p
== '\\' || *p
== '/')
462 } while(tolower(*p
++) == tolower(*q
++));
469 static Entry
* read_tree_win(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
471 TCHAR buffer
[MAX_PATH
];
472 Entry
* entry
= &root
->entry
;
476 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
478 #ifndef _NO_EXTENSIONS
479 entry
->etype
= ET_WINDOWS
;
483 while(*s
&& *s
!= '\\' && *s
!= '/')
486 while(*s
== '\\' || *s
== '/')
492 read_directory(entry
, buffer
, sortOrder
, hwnd
);
495 entry
->expanded
= TRUE
;
500 entry
= find_entry_win(entry
, s
);
503 SetCursor(old_cursor
);
509 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
511 static BOOL
time_to_filetime(const time_t* t
, FILETIME
* ftime
)
513 struct tm
* tm
= gmtime(t
);
519 stime
.wYear
= tm
->tm_year
+1900;
520 stime
.wMonth
= tm
->tm_mon
+1;
521 /* stime.wDayOfWeek */
522 stime
.wDay
= tm
->tm_mday
;
523 stime
.wHour
= tm
->tm_hour
;
524 stime
.wMinute
= tm
->tm_min
;
525 stime
.wSecond
= tm
->tm_sec
;
527 return SystemTimeToFileTime(&stime
, ftime
);
530 static void read_directory_unix(Entry
* dir
, LPCTSTR path
)
532 Entry
* first_entry
= NULL
;
537 int level
= dir
->level
+ 1;
539 char cpath
[MAX_PATH
];
541 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, cpath
, MAX_PATH
, NULL
, NULL
);
543 const char* cpath
= path
;
546 pdir
= opendir(cpath
);
551 char buffer
[MAX_PATH
], *p
;
554 for(p
=buffer
,s
=cpath
; *s
; )
557 if (p
==buffer
|| p
[-1]!='/')
560 while((ent
=readdir(pdir
))) {
561 entry
= alloc_entry();
569 entry
->etype
= ET_UNIX
;
571 strcpy(p
, ent
->d_name
);
573 MultiByteToWideChar(CP_UNIXCP
, 0, p
, -1, entry
->data
.cFileName
, MAX_PATH
);
575 lstrcpy(entry
->data
.cFileName
, p
);
578 if (!stat(buffer
, &st
)) {
579 entry
->data
.dwFileAttributes
= p
[0]=='.'? FILE_ATTRIBUTE_HIDDEN
: 0;
581 if (S_ISDIR(st
.st_mode
))
582 entry
->data
.dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
584 entry
->data
.nFileSizeLow
= st
.st_size
& 0xFFFFFFFF;
585 entry
->data
.nFileSizeHigh
= st
.st_size
>> 32;
587 memset(&entry
->data
.ftCreationTime
, 0, sizeof(FILETIME
));
588 time_to_filetime(&st
.st_atime
, &entry
->data
.ftLastAccessTime
);
589 time_to_filetime(&st
.st_mtime
, &entry
->data
.ftLastWriteTime
);
591 entry
->bhfi
.nFileIndexLow
= ent
->d_ino
;
592 entry
->bhfi
.nFileIndexHigh
= 0;
594 entry
->bhfi
.nNumberOfLinks
= st
.st_nlink
;
596 entry
->bhfi_valid
= TRUE
;
598 entry
->data
.nFileSizeLow
= 0;
599 entry
->data
.nFileSizeHigh
= 0;
600 entry
->bhfi_valid
= FALSE
;
605 entry
->expanded
= FALSE
;
606 entry
->scanned
= FALSE
;
607 entry
->level
= level
;
618 dir
->down
= first_entry
;
622 static Entry
* find_entry_unix(Entry
* dir
, LPCTSTR name
)
626 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
628 LPCTSTR q
= entry
->data
.cFileName
;
631 if (!*p
|| *p
== '/')
633 } while(*p
++ == *q
++);
639 static Entry
* read_tree_unix(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
641 TCHAR buffer
[MAX_PATH
];
642 Entry
* entry
= &root
->entry
;
646 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
648 entry
->etype
= ET_UNIX
;
651 while(*s
&& *s
!= '/')
660 read_directory(entry
, buffer
, sortOrder
, hwnd
);
663 entry
->expanded
= TRUE
;
668 entry
= find_entry_unix(entry
, s
);
671 SetCursor(old_cursor
);
676 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
679 #ifdef _SHELL_FOLDERS
682 #define get_strret get_strretW
683 #define path_from_pidl path_from_pidlW
685 #define get_strret get_strretA
686 #define path_from_pidl path_from_pidlA
690 static void free_strret(STRRET
* str
)
692 if (str
->uType
== STRRET_WSTR
)
693 IMalloc_Free(Globals
.iMalloc
, str
->UNION_MEMBER(pOleStr
));
699 static LPSTR
strcpyn(LPSTR dest
, LPCSTR source
, size_t count
)
704 for(s
=source
; count
&&(*d
++=*s
++); )
710 static void get_strretA(STRRET
* str
, const SHITEMID
* shiid
, LPSTR buffer
, int len
)
714 WideCharToMultiByte(CP_ACP
, 0, str
->UNION_MEMBER(pOleStr
), -1, buffer
, len
, NULL
, NULL
);
718 strcpyn(buffer
, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), len
);
722 strcpyn(buffer
, str
->UNION_MEMBER(cStr
), len
);
726 static HRESULT
path_from_pidlA(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPSTR buffer
, int len
)
730 /* SHGDN_FORPARSING: get full path of id list */
731 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, SHGDN_FORPARSING
, &str
);
734 get_strretA(&str
, &pidl
->mkid
, buffer
, len
);
744 static LPWSTR
wcscpyn(LPWSTR dest
, LPCWSTR source
, size_t count
)
749 for(s
=source
; count
&&(*d
++=*s
++); )
755 static void get_strretW(STRRET
* str
, const SHITEMID
* shiid
, LPWSTR buffer
, int len
)
759 wcscpyn(buffer
, str
->UNION_MEMBER(pOleStr
), len
);
763 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), -1, buffer
, len
);
767 MultiByteToWideChar(CP_ACP
, 0, str
->UNION_MEMBER(cStr
), -1, buffer
, len
);
772 static HRESULT
name_from_pidl(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPTSTR buffer
, int len
, SHGDNF flags
)
776 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, flags
, &str
);
779 get_strret(&str
, &pidl
->mkid
, buffer
, len
);
788 static HRESULT
path_from_pidlW(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPWSTR buffer
, int len
)
792 /* SHGDN_FORPARSING: get full path of id list */
793 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, SHGDN_FORPARSING
, &str
);
796 get_strretW(&str
, &pidl
->mkid
, buffer
, len
);
805 /* create an item id list from a file system path */
807 static LPITEMIDLIST
get_path_pidl(LPTSTR path
, HWND hwnd
)
814 LPWSTR buffer
= path
;
816 WCHAR buffer
[MAX_PATH
];
817 MultiByteToWideChar(CP_ACP
, 0, path
, -1, buffer
, MAX_PATH
);
820 hr
= IShellFolder_ParseDisplayName(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
828 /* convert an item id list from relative to absolute (=relative to the desktop) format */
830 static LPITEMIDLIST
get_to_absolute_pidl(Entry
* entry
, HWND hwnd
)
832 if (entry
->up
&& entry
->up
->etype
==ET_SHELL
) {
833 LPITEMIDLIST idl
= NULL
;
836 idl
= ILCombine(ILClone(entry
->pidl
), idl
);
841 } else if (entry
->etype
== ET_WINDOWS
) {
842 TCHAR path
[MAX_PATH
];
844 get_path(entry
, path
);
846 return get_path_pidl(path
, hwnd
);
847 } else if (entry
->pidl
)
848 return ILClone(entry
->pidl
);
854 static HICON
extract_icon(IShellFolder
* folder
, LPCITEMIDLIST pidl
)
856 IExtractIcon
* pExtract
;
858 if (SUCCEEDED(IShellFolder_GetUIObjectOf(folder
, 0, 1, (LPCITEMIDLIST
*)&pidl
, &IID_IExtractIcon
, 0, (LPVOID
*)&pExtract
))) {
859 TCHAR path
[_MAX_PATH
];
864 if (SUCCEEDED(IExtractIconW_GetIconLocation(pExtract
, GIL_FORSHELL
, path
, _MAX_PATH
, &idx
, &flags
))) {
865 if (!(flags
& GIL_NOTFILENAME
)) {
867 idx
= 0; /* special case for some control panel applications */
869 if ((int)ExtractIconEx(path
, idx
, 0, &hicon
, 1) > 0)
870 flags
&= ~GIL_DONTCACHE
;
872 HICON hIconLarge
= 0;
874 HRESULT hr
= IExtractIconW_Extract(pExtract
, path
, idx
, &hIconLarge
, &hicon
, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON
)));
877 DestroyIcon(hIconLarge
);
888 static Entry
* find_entry_shell(Entry
* dir
, LPCITEMIDLIST pidl
)
892 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
893 if (entry
->pidl
->mkid
.cb
== pidl
->mkid
.cb
&&
894 !memcmp(entry
->pidl
, pidl
, entry
->pidl
->mkid
.cb
))
901 static Entry
* read_tree_shell(Root
* root
, LPITEMIDLIST pidl
, SORT_ORDER sortOrder
, HWND hwnd
)
903 Entry
* entry
= &root
->entry
;
905 LPITEMIDLIST next_pidl
= pidl
;
906 IShellFolder
* folder
;
907 IShellFolder
* child
= NULL
;
910 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
912 #ifndef _NO_EXTENSIONS
913 entry
->etype
= ET_SHELL
;
916 folder
= Globals
.iDesktop
;
919 entry
->pidl
= next_pidl
;
920 entry
->folder
= folder
;
925 /* copy first element of item idlist */
926 next_pidl
= IMalloc_Alloc(Globals
.iMalloc
, pidl
->mkid
.cb
+sizeof(USHORT
));
927 memcpy(next_pidl
, pidl
, pidl
->mkid
.cb
);
928 ((LPITEMIDLIST
)((LPBYTE
)next_pidl
+pidl
->mkid
.cb
))->mkid
.cb
= 0;
930 hr
= IShellFolder_BindToObject(folder
, next_pidl
, 0, &IID_IShellFolder
, (void**)&child
);
934 read_directory(entry
, NULL
, sortOrder
, hwnd
);
937 entry
->expanded
= TRUE
;
939 next
= find_entry_shell(entry
, next_pidl
);
946 /* go to next element */
947 pidl
= (LPITEMIDLIST
) ((LPBYTE
)pidl
+pidl
->mkid
.cb
);
950 SetCursor(old_cursor
);
956 static void fill_w32fdata_shell(IShellFolder
* folder
, LPCITEMIDLIST pidl
, SFGAOF attribs
, WIN32_FIND_DATA
* w32fdata
)
958 if (!(attribs
& SFGAO_FILESYSTEM
) ||
959 FAILED(SHGetDataFromIDList(folder
, pidl
, SHGDFIL_FINDDATA
, w32fdata
, sizeof(WIN32_FIND_DATA
)))) {
960 WIN32_FILE_ATTRIBUTE_DATA fad
;
961 IDataObject
* pDataObj
;
963 STGMEDIUM medium
= {0, {0}, 0};
964 FORMATETC fmt
= {Globals
.cfStrFName
, 0, DVASPECT_CONTENT
, -1, TYMED_HGLOBAL
};
966 HRESULT hr
= IShellFolder_GetUIObjectOf(folder
, 0, 1, &pidl
, &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
969 hr
= IDataObject_GetData(pDataObj
, &fmt
, &medium
);
971 IDataObject_Release(pDataObj
);
974 LPCTSTR path
= (LPCTSTR
)GlobalLock(medium
.UNION_MEMBER(hGlobal
));
975 UINT sem_org
= SetErrorMode(SEM_FAILCRITICALERRORS
);
977 if (GetFileAttributesEx(path
, GetFileExInfoStandard
, &fad
)) {
978 w32fdata
->dwFileAttributes
= fad
.dwFileAttributes
;
979 w32fdata
->ftCreationTime
= fad
.ftCreationTime
;
980 w32fdata
->ftLastAccessTime
= fad
.ftLastAccessTime
;
981 w32fdata
->ftLastWriteTime
= fad
.ftLastWriteTime
;
983 if (!(fad
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)) {
984 w32fdata
->nFileSizeLow
= fad
.nFileSizeLow
;
985 w32fdata
->nFileSizeHigh
= fad
.nFileSizeHigh
;
989 SetErrorMode(sem_org
);
991 GlobalUnlock(medium
.UNION_MEMBER(hGlobal
));
992 GlobalFree(medium
.UNION_MEMBER(hGlobal
));
997 if (attribs
& (SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
))
998 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
1000 if (attribs
& SFGAO_READONLY
)
1001 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_READONLY
;
1003 if (attribs
& SFGAO_COMPRESSED
)
1004 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_COMPRESSED
;
1008 static void read_directory_shell(Entry
* dir
, HWND hwnd
)
1010 IShellFolder
* folder
= dir
->folder
;
1011 int level
= dir
->level
+ 1;
1014 IShellFolder
* child
;
1015 IEnumIDList
* idlist
;
1017 Entry
* first_entry
= NULL
;
1024 hr
= IShellFolder_EnumObjects(folder
, hwnd
, SHCONTF_FOLDERS
|SHCONTF_NONFOLDERS
|SHCONTF_INCLUDEHIDDEN
|SHCONTF_SHAREABLE
|SHCONTF_STORAGE
, &idlist
);
1026 if (SUCCEEDED(hr
)) {
1028 #define FETCH_ITEM_COUNT 32
1029 LPITEMIDLIST pidls
[FETCH_ITEM_COUNT
];
1034 memset(pidls
, 0, sizeof(pidls
));
1036 hr
= IEnumIDList_Next(idlist
, FETCH_ITEM_COUNT
, pidls
, &cnt
);
1043 for(n
=0; n
<cnt
; ++n
) {
1044 entry
= alloc_entry();
1047 first_entry
= entry
;
1052 memset(&entry
->data
, 0, sizeof(WIN32_FIND_DATA
));
1053 entry
->bhfi_valid
= FALSE
;
1055 attribs
= ~SFGAO_FILESYSTEM
; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
1057 hr
= IShellFolder_GetAttributesOf(folder
, 1, (LPCITEMIDLIST
*)&pidls
[n
], &attribs
);
1059 if (SUCCEEDED(hr
)) {
1060 if (attribs
!= (SFGAOF
)~SFGAO_FILESYSTEM
) {
1061 fill_w32fdata_shell(folder
, pidls
[n
], attribs
, &entry
->data
);
1063 entry
->bhfi_valid
= TRUE
;
1069 entry
->pidl
= pidls
[n
];
1071 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1072 hr
= IShellFolder_BindToObject(folder
, pidls
[n
], 0, &IID_IShellFolder
, (void**)&child
);
1075 entry
->folder
= child
;
1077 entry
->folder
= NULL
;
1080 entry
->folder
= NULL
;
1082 if (!entry
->data
.cFileName
[0])
1083 /*hr = */name_from_pidl(folder
, pidls
[n
], entry
->data
.cFileName
, MAX_PATH
, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1085 /* get display icons for files and virtual objects */
1086 if (!(entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ||
1087 !(attribs
& SFGAO_FILESYSTEM
)) {
1088 entry
->hicon
= extract_icon(folder
, pidls
[n
]);
1091 entry
->hicon
= (HICON
)-1; /* don't try again later */
1096 entry
->expanded
= FALSE
;
1097 entry
->scanned
= FALSE
;
1098 entry
->level
= level
;
1100 #ifndef _NO_EXTENSIONS
1101 entry
->etype
= ET_SHELL
;
1102 entry
->bhfi_valid
= FALSE
;
1109 IEnumIDList_Release(idlist
);
1115 dir
->down
= first_entry
;
1116 dir
->scanned
= TRUE
;
1119 #endif /* _SHELL_FOLDERS */
1122 /* sort order for different directory/file types */
1131 /* distinguish between ".", ".." and any other directory names */
1132 static int TypeOrderFromDirname(LPCTSTR name
)
1134 if (name
[0] == '.') {
1135 if (name
[1] == '\0')
1136 return TO_DOT
; /* "." */
1138 if (name
[1]=='.' && name
[2]=='\0')
1139 return TO_DOTDOT
; /* ".." */
1142 return TO_OTHER_DIR
; /* anything else */
1145 /* directories first... */
1146 static int compareType(const WIN32_FIND_DATA
* fd1
, const WIN32_FIND_DATA
* fd2
)
1148 int order1
= fd1
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1149 int order2
= fd2
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1151 /* Handle "." and ".." as special case and move them at the very first beginning. */
1152 if (order1
==TO_DIR
&& order2
==TO_DIR
) {
1153 order1
= TypeOrderFromDirname(fd1
->cFileName
);
1154 order2
= TypeOrderFromDirname(fd2
->cFileName
);
1157 return order2
==order1
? 0: order1
<order2
? -1: 1;
1161 static int compareName(const void* arg1
, const void* arg2
)
1163 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1164 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1166 int cmp
= compareType(fd1
, fd2
);
1170 return lstrcmpi(fd1
->cFileName
, fd2
->cFileName
);
1173 static int compareExt(const void* arg1
, const void* arg2
)
1175 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1176 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1177 const TCHAR
*name1
, *name2
, *ext1
, *ext2
;
1179 int cmp
= compareType(fd1
, fd2
);
1183 name1
= fd1
->cFileName
;
1184 name2
= fd2
->cFileName
;
1186 ext1
= strrchrW(name1
, '.');
1187 ext2
= strrchrW(name2
, '.');
1199 cmp
= lstrcmpi(ext1
, ext2
);
1203 return lstrcmpi(name1
, name2
);
1206 static int compareSize(const void* arg1
, const void* arg2
)
1208 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1209 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1211 int cmp
= compareType(fd1
, fd2
);
1215 cmp
= fd2
->nFileSizeHigh
- fd1
->nFileSizeHigh
;
1222 cmp
= fd2
->nFileSizeLow
- fd1
->nFileSizeLow
;
1224 return cmp
<0? -1: cmp
>0? 1: 0;
1227 static int compareDate(const void* arg1
, const void* arg2
)
1229 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1230 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1232 int cmp
= compareType(fd1
, fd2
);
1236 return CompareFileTime(&fd2
->ftLastWriteTime
, &fd1
->ftLastWriteTime
);
1240 static int (*sortFunctions
[])(const void* arg1
, const void* arg2
) = {
1241 compareName
, /* SORT_NAME */
1242 compareExt
, /* SORT_EXT */
1243 compareSize
, /* SORT_SIZE */
1244 compareDate
/* SORT_DATE */
1248 static void SortDirectory(Entry
* dir
, SORT_ORDER sortOrder
)
1250 Entry
* entry
= dir
->down
;
1255 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1259 array
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(Entry
*));
1262 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1265 /* call qsort with the appropriate compare function */
1266 qsort(array
, len
, sizeof(array
[0]), sortFunctions
[sortOrder
]);
1268 dir
->down
= array
[0];
1270 for(p
=array
; --len
; p
++)
1275 HeapFree(GetProcessHeap(), 0, array
);
1280 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
1282 TCHAR buffer
[MAX_PATH
];
1287 #ifdef _SHELL_FOLDERS
1288 if (dir
->etype
== ET_SHELL
)
1290 read_directory_shell(dir
, hwnd
);
1292 if (Globals
.prescan_node
) {
1301 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1302 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1303 read_directory_shell(entry
, hwnd
);
1304 SortDirectory(entry
, sortOrder
);
1310 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1311 if (dir
->etype
== ET_UNIX
)
1313 read_directory_unix(dir
, path
);
1315 if (Globals
.prescan_node
) {
1324 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1325 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1326 lstrcpy(d
, entry
->data
.cFileName
);
1327 read_directory_unix(entry
, buffer
);
1328 SortDirectory(entry
, sortOrder
);
1335 read_directory_win(dir
, path
);
1337 if (Globals
.prescan_node
) {
1346 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1347 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1348 lstrcpy(d
, entry
->data
.cFileName
);
1349 read_directory_win(entry
, buffer
);
1350 SortDirectory(entry
, sortOrder
);
1355 SortDirectory(dir
, sortOrder
);
1359 static Entry
* read_tree(Root
* root
, LPCTSTR path
, LPITEMIDLIST pidl
, LPTSTR drv
, SORT_ORDER sortOrder
, HWND hwnd
)
1361 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1362 static const TCHAR sSlash
[] = {'/', '\0'};
1364 static const TCHAR sBackslash
[] = {'\\', '\0'};
1366 #ifdef _SHELL_FOLDERS
1369 /* read shell namespace tree */
1370 root
->drive_type
= DRIVE_UNKNOWN
;
1373 load_string(root
->volname
, sizeof(root
->volname
)/sizeof(root
->volname
[0]), IDS_DESKTOP
);
1375 load_string(root
->fs
, sizeof(root
->fs
)/sizeof(root
->fs
[0]), IDS_SHELL
);
1377 return read_tree_shell(root
, pidl
, sortOrder
, hwnd
);
1381 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1384 /* read unix file system tree */
1385 root
->drive_type
= GetDriveType(path
);
1387 lstrcat(drv
, sSlash
);
1388 load_string(root
->volname
, sizeof(root
->volname
)/sizeof(root
->volname
[0]), IDS_ROOT_FS
);
1390 load_string(root
->fs
, sizeof(root
->fs
)/sizeof(root
->fs
[0]), IDS_UNIXFS
);
1392 lstrcpy(root
->path
, sSlash
);
1394 return read_tree_unix(root
, path
, sortOrder
, hwnd
);
1398 /* read WIN32 file system tree */
1399 root
->drive_type
= GetDriveType(path
);
1401 lstrcat(drv
, sBackslash
);
1402 GetVolumeInformation(drv
, root
->volname
, _MAX_FNAME
, 0, 0, &root
->fs_flags
, root
->fs
, _MAX_DIR
);
1404 lstrcpy(root
->path
, drv
);
1406 return read_tree_win(root
, path
, sortOrder
, hwnd
);
1410 /* flags to filter different file types */
1412 TF_DIRECTORIES
= 0x01,
1414 TF_DOCUMENTS
= 0x04,
1421 static ChildWnd
* alloc_child_window(LPCTSTR path
, LPITEMIDLIST pidl
, HWND hwnd
)
1423 TCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
1424 TCHAR dir_path
[MAX_PATH
];
1425 TCHAR b1
[BUFFER_LEN
];
1426 static const TCHAR sAsterics
[] = {'*', '\0'};
1428 ChildWnd
* child
= HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd
));
1429 Root
* root
= &child
->root
;
1432 memset(child
, 0, sizeof(ChildWnd
));
1434 child
->left
.treePane
= TRUE
;
1435 child
->left
.visible_cols
= 0;
1437 child
->right
.treePane
= FALSE
;
1438 #ifndef _NO_EXTENSIONS
1439 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_INDEX
|COL_LINKS
;
1441 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
;
1444 child
->pos
.length
= sizeof(WINDOWPLACEMENT
);
1445 child
->pos
.flags
= 0;
1446 child
->pos
.showCmd
= SW_SHOWNORMAL
;
1447 child
->pos
.rcNormalPosition
.left
= CW_USEDEFAULT
;
1448 child
->pos
.rcNormalPosition
.top
= CW_USEDEFAULT
;
1449 child
->pos
.rcNormalPosition
.right
= CW_USEDEFAULT
;
1450 child
->pos
.rcNormalPosition
.bottom
= CW_USEDEFAULT
;
1452 child
->focus_pane
= 0;
1453 child
->split_pos
= DEFAULT_SPLIT_POS
;
1454 child
->sortOrder
= SORT_NAME
;
1455 child
->header_wdths_ok
= FALSE
;
1459 lstrcpy(child
->path
, path
);
1461 _tsplitpath(path
, drv
, dir
, name
, ext
);
1464 lstrcpy(child
->filter_pattern
, sAsterics
);
1465 child
->filter_flags
= TF_ALL
;
1467 root
->entry
.level
= 0;
1469 lstrcpy(dir_path
, drv
);
1470 lstrcat(dir_path
, dir
);
1471 entry
= read_tree(root
, dir_path
, pidl
, drv
, child
->sortOrder
, hwnd
);
1473 #ifdef _SHELL_FOLDERS
1474 if (root
->entry
.etype
== ET_SHELL
)
1475 load_string(root
->entry
.data
.cFileName
, sizeof(root
->entry
.data
.cFileName
)/sizeof(root
->entry
.data
.cFileName
[0]), IDS_DESKTOP
);
1478 wsprintf(root
->entry
.data
.cFileName
, RS(b1
,IDS_TITLEFMT
), drv
, root
->fs
);
1480 root
->entry
.data
.dwFileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1482 child
->left
.root
= &root
->entry
;
1483 child
->right
.root
= NULL
;
1485 set_curdir(child
, entry
, 0, hwnd
);
1491 /* free all memory associated with a child window */
1492 static void free_child_window(ChildWnd
* child
)
1494 free_entries(&child
->root
.entry
);
1495 HeapFree(GetProcessHeap(), 0, child
);
1499 /* get full path of specified directory entry */
1500 static void get_path(Entry
* dir
, PTSTR path
)
1506 #ifdef _SHELL_FOLDERS
1507 if (dir
->etype
== ET_SHELL
)
1517 hr
= IShellFolder_GetAttributesOf(dir
->folder
, 1, (LPCITEMIDLIST
*)&dir
->pidl
, &attribs
);
1519 if (SUCCEEDED(hr
) && (attribs
&SFGAO_FILESYSTEM
)) {
1520 IShellFolder
* parent
= dir
->up
? dir
->up
->folder
: Globals
.iDesktop
;
1522 hr
= path_from_pidl(parent
, dir
->pidl
, path
, MAX_PATH
);
1528 for(entry
=dir
; entry
; level
++) {
1534 name
= entry
->data
.cFileName
;
1537 for(l
=0; *s
&& *s
!= '/' && *s
!= '\\'; s
++)
1543 memmove(path
+l
+1, path
, len
*sizeof(TCHAR
));
1544 memcpy(path
+1, name
, l
*sizeof(TCHAR
));
1547 #ifndef _NO_EXTENSIONS
1548 if (entry
->etype
== ET_UNIX
)
1557 memmove(path
+l
, path
, len
*sizeof(TCHAR
));
1558 memcpy(path
, name
, l
*sizeof(TCHAR
));
1565 #ifndef _NO_EXTENSIONS
1566 if (entry
->etype
== ET_UNIX
)
1577 static windowOptions
load_registry_settings(void)
1585 RegOpenKeyExW( HKEY_CURRENT_USER
, registry_key
,
1586 0, KEY_QUERY_VALUE
, &hKey
);
1588 size
= sizeof(DWORD
);
1590 if( RegQueryValueExW( hKey
, reg_start_x
, NULL
, &type
,
1591 (LPBYTE
) &opts
.start_x
, &size
) != ERROR_SUCCESS
)
1592 opts
.start_x
= CW_USEDEFAULT
;
1594 if( RegQueryValueExW( hKey
, reg_start_y
, NULL
, &type
,
1595 (LPBYTE
) &opts
.start_y
, &size
) != ERROR_SUCCESS
)
1596 opts
.start_y
= CW_USEDEFAULT
;
1598 if( RegQueryValueExW( hKey
, reg_width
, NULL
, &type
,
1599 (LPBYTE
) &opts
.width
, &size
) != ERROR_SUCCESS
)
1600 opts
.width
= CW_USEDEFAULT
;
1602 if( RegQueryValueExW( hKey
, reg_height
, NULL
, &type
,
1603 (LPBYTE
) &opts
.height
, &size
) != ERROR_SUCCESS
)
1604 opts
.height
= CW_USEDEFAULT
;
1605 size
=sizeof(logfont
);
1606 if( RegQueryValueExW( hKey
, reg_logfont
, NULL
, &type
,
1607 (LPBYTE
) &logfont
, &size
) != ERROR_SUCCESS
)
1608 GetObject(GetStockObject(DEFAULT_GUI_FONT
),sizeof(logfont
),&logfont
);
1610 RegCloseKey( hKey
);
1612 Globals
.hfont
= CreateFontIndirect(&logfont
);
1616 static void save_registry_settings(void)
1623 wi
.cbSize
= sizeof( WINDOWINFO
);
1624 GetWindowInfo(Globals
.hMainWnd
, &wi
);
1625 width
= wi
.rcWindow
.right
- wi
.rcWindow
.left
;
1626 height
= wi
.rcWindow
.bottom
- wi
.rcWindow
.top
;
1628 if ( RegOpenKeyExW( HKEY_CURRENT_USER
, registry_key
,
1629 0, KEY_SET_VALUE
, &hKey
) != ERROR_SUCCESS
)
1631 /* Unable to save registry settings - try to create key */
1632 if ( RegCreateKeyExW( HKEY_CURRENT_USER
, registry_key
,
1633 0, NULL
, REG_OPTION_NON_VOLATILE
,
1634 KEY_SET_VALUE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
1636 /* FIXME: Cannot create key */
1640 /* Save all of the settings */
1641 RegSetValueExW( hKey
, reg_start_x
, 0, REG_DWORD
,
1642 (LPBYTE
) &wi
.rcWindow
.left
, sizeof(DWORD
) );
1643 RegSetValueExW( hKey
, reg_start_y
, 0, REG_DWORD
,
1644 (LPBYTE
) &wi
.rcWindow
.top
, sizeof(DWORD
) );
1645 RegSetValueExW( hKey
, reg_width
, 0, REG_DWORD
,
1646 (LPBYTE
) &width
, sizeof(DWORD
) );
1647 RegSetValueExW( hKey
, reg_height
, 0, REG_DWORD
,
1648 (LPBYTE
) &height
, sizeof(DWORD
) );
1649 GetObject(Globals
.hfont
, sizeof(logfont
), &logfont
);
1650 RegSetValueExW( hKey
, reg_logfont
, 0, REG_BINARY
,
1651 (LPBYTE
) &logfont
, sizeof(LOGFONT
) );
1653 /* TODO: Save more settings here (List vs. Detailed View, etc.) */
1654 RegCloseKey( hKey
);
1657 static void resize_frame_rect(HWND hwnd
, PRECT prect
)
1662 if (IsWindowVisible(Globals
.htoolbar
)) {
1663 SendMessage(Globals
.htoolbar
, WM_SIZE
, 0, 0);
1664 GetClientRect(Globals
.htoolbar
, &rt
);
1665 prect
->top
= rt
.bottom
+3;
1666 prect
->bottom
-= rt
.bottom
+3;
1669 if (IsWindowVisible(Globals
.hdrivebar
)) {
1670 SendMessage(Globals
.hdrivebar
, WM_SIZE
, 0, 0);
1671 GetClientRect(Globals
.hdrivebar
, &rt
);
1672 new_top
= --prect
->top
+ rt
.bottom
+3;
1673 MoveWindow(Globals
.hdrivebar
, 0, prect
->top
, rt
.right
, new_top
, TRUE
);
1674 prect
->top
= new_top
;
1675 prect
->bottom
-= rt
.bottom
+2;
1678 if (IsWindowVisible(Globals
.hstatusbar
)) {
1679 int parts
[] = {300, 500};
1681 SendMessage(Globals
.hstatusbar
, WM_SIZE
, 0, 0);
1682 SendMessage(Globals
.hstatusbar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
1683 GetClientRect(Globals
.hstatusbar
, &rt
);
1684 prect
->bottom
-= rt
.bottom
;
1687 MoveWindow(Globals
.hmdiclient
, prect
->left
-1,prect
->top
-1,prect
->right
+2,prect
->bottom
+1, TRUE
);
1690 static void resize_frame(HWND hwnd
, int cx
, int cy
)
1699 resize_frame_rect(hwnd
, &rect
);
1702 static void resize_frame_client(HWND hwnd
)
1706 GetClientRect(hwnd
, &rect
);
1708 resize_frame_rect(hwnd
, &rect
);
1712 static HHOOK hcbthook
;
1713 static ChildWnd
* newchild
= NULL
;
1715 static LRESULT CALLBACK
CBTProc(int code
, WPARAM wparam
, LPARAM lparam
)
1717 if (code
==HCBT_CREATEWND
&& newchild
) {
1718 ChildWnd
* child
= newchild
;
1721 child
->hwnd
= (HWND
) wparam
;
1722 SetWindowLongPtr(child
->hwnd
, GWLP_USERDATA
, (LPARAM
)child
);
1725 return CallNextHookEx(hcbthook
, code
, wparam
, lparam
);
1728 static HWND
create_child_window(ChildWnd
* child
)
1730 MDICREATESTRUCT mcs
;
1733 mcs
.szClass
= sWINEFILETREE
;
1734 mcs
.szTitle
= (LPTSTR
)child
->path
;
1735 mcs
.hOwner
= Globals
.hInstance
;
1736 mcs
.x
= child
->pos
.rcNormalPosition
.left
;
1737 mcs
.y
= child
->pos
.rcNormalPosition
.top
;
1738 mcs
.cx
= child
->pos
.rcNormalPosition
.right
-child
->pos
.rcNormalPosition
.left
;
1739 mcs
.cy
= child
->pos
.rcNormalPosition
.bottom
-child
->pos
.rcNormalPosition
.top
;
1743 hcbthook
= SetWindowsHookEx(WH_CBT
, CBTProc
, 0, GetCurrentThreadId());
1746 child
->hwnd
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDICREATE
, 0, (LPARAM
)&mcs
);
1748 UnhookWindowsHookEx(hcbthook
);
1752 UnhookWindowsHookEx(hcbthook
);
1754 SendMessage(child
->left
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1755 SendMessage(child
->right
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1757 idx
= SendMessage(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)child
->left
.cur
);
1758 SendMessage(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
1764 struct ExecuteDialog
{
1765 TCHAR cmd
[MAX_PATH
];
1769 static INT_PTR CALLBACK
ExecuteDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1771 static struct ExecuteDialog
* dlg
;
1775 dlg
= (struct ExecuteDialog
*) lparam
;
1779 int id
= (int)wparam
;
1782 GetWindowText(GetDlgItem(hwnd
, 201), dlg
->cmd
, MAX_PATH
);
1783 dlg
->cmdshow
= get_check(hwnd
,214) ? SW_SHOWMINIMIZED
: SW_SHOWNORMAL
;
1784 EndDialog(hwnd
, id
);
1785 } else if (id
== IDCANCEL
)
1786 EndDialog(hwnd
, id
);
1795 static INT_PTR CALLBACK
DestinationDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1797 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1801 SetWindowLongPtr(hwnd
, GWLP_USERDATA
, lparam
);
1802 SetWindowText(GetDlgItem(hwnd
, 201), (LPCTSTR
)lparam
);
1806 int id
= (int)wparam
;
1810 LPTSTR dest
= (LPTSTR
) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
1811 GetWindowText(GetDlgItem(hwnd
, 201), dest
, MAX_PATH
);
1812 EndDialog(hwnd
, id
);
1816 EndDialog(hwnd
, id
);
1820 MessageBox(hwnd
, RS(b1
,IDS_NO_IMPL
), RS(b2
,IDS_WINEFILE
), MB_OK
);
1832 struct FilterDialog
{
1833 TCHAR pattern
[MAX_PATH
];
1837 static INT_PTR CALLBACK
FilterDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1839 static struct FilterDialog
* dlg
;
1843 dlg
= (struct FilterDialog
*) lparam
;
1844 SetWindowText(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
);
1845 set_check(hwnd
, IDC_VIEW_TYPE_DIRECTORIES
, dlg
->flags
&TF_DIRECTORIES
);
1846 set_check(hwnd
, IDC_VIEW_TYPE_PROGRAMS
, dlg
->flags
&TF_PROGRAMS
);
1847 set_check(hwnd
, IDC_VIEW_TYPE_DOCUMENTS
, dlg
->flags
&TF_DOCUMENTS
);
1848 set_check(hwnd
, IDC_VIEW_TYPE_OTHERS
, dlg
->flags
&TF_OTHERS
);
1849 set_check(hwnd
, IDC_VIEW_TYPE_HIDDEN
, dlg
->flags
&TF_HIDDEN
);
1853 int id
= (int)wparam
;
1858 GetWindowText(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
, MAX_PATH
);
1860 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_DIRECTORIES
) ? TF_DIRECTORIES
: 0;
1861 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_PROGRAMS
) ? TF_PROGRAMS
: 0;
1862 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_DOCUMENTS
) ? TF_DOCUMENTS
: 0;
1863 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_OTHERS
) ? TF_OTHERS
: 0;
1864 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_HIDDEN
) ? TF_HIDDEN
: 0;
1868 EndDialog(hwnd
, id
);
1869 } else if (id
== IDCANCEL
)
1870 EndDialog(hwnd
, id
);
1879 struct PropertiesDialog
{
1880 TCHAR path
[MAX_PATH
];
1885 /* Structure used to store enumerated languages and code pages. */
1886 struct LANGANDCODEPAGE
{
1891 static LPCSTR InfoStrings
[] = {
1907 static void PropDlg_DisplayValue(HWND hlbox
, HWND hedit
)
1909 int idx
= SendMessage(hlbox
, LB_GETCURSEL
, 0, 0);
1911 if (idx
!= LB_ERR
) {
1912 LPCTSTR pValue
= (LPCTSTR
) SendMessage(hlbox
, LB_GETITEMDATA
, idx
, 0);
1915 SetWindowText(hedit
, pValue
);
1919 static void CheckForFileInfo(struct PropertiesDialog
* dlg
, HWND hwnd
, LPCTSTR strFilename
)
1921 static TCHAR sBackSlash
[] = {'\\','\0'};
1922 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'};
1923 static TCHAR sStringFileInfo
[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1924 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1925 DWORD dwVersionDataLen
= GetFileVersionInfoSize(strFilename
, NULL
);
1927 if (dwVersionDataLen
) {
1928 dlg
->pVersionData
= HeapAlloc(GetProcessHeap(), 0, dwVersionDataLen
);
1930 if (GetFileVersionInfo(strFilename
, 0, dwVersionDataLen
, dlg
->pVersionData
)) {
1934 if (VerQueryValue(dlg
->pVersionData
, sBackSlash
, &pVal
, &nValLen
)) {
1935 if (nValLen
== sizeof(VS_FIXEDFILEINFO
)) {
1936 VS_FIXEDFILEINFO
* pFixedFileInfo
= (VS_FIXEDFILEINFO
*)pVal
;
1937 char buffer
[BUFFER_LEN
];
1939 sprintf(buffer
, "%d.%d.%d.%d",
1940 HIWORD(pFixedFileInfo
->dwFileVersionMS
), LOWORD(pFixedFileInfo
->dwFileVersionMS
),
1941 HIWORD(pFixedFileInfo
->dwFileVersionLS
), LOWORD(pFixedFileInfo
->dwFileVersionLS
));
1943 SetDlgItemTextA(hwnd
, IDC_STATIC_PROP_VERSION
, buffer
);
1947 /* Read the list of languages and code pages. */
1948 if (VerQueryValue(dlg
->pVersionData
, sTranslation
, &pVal
, &nValLen
)) {
1949 struct LANGANDCODEPAGE
* pTranslate
= (struct LANGANDCODEPAGE
*)pVal
;
1950 struct LANGANDCODEPAGE
* pEnd
= (struct LANGANDCODEPAGE
*)((LPBYTE
)pVal
+nValLen
);
1952 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
1954 /* Read the file description for each language and code page. */
1955 for(; pTranslate
<pEnd
; ++pTranslate
) {
1958 for(p
=InfoStrings
; *p
; ++p
) {
1959 TCHAR subblock
[200];
1966 LPCSTR pInfoString
= *p
;
1968 MultiByteToWideChar(CP_ACP
, 0, pInfoString
, -1, infoStr
, 100);
1970 #define infoStr pInfoString
1972 wsprintf(subblock
, sStringFileInfo
, pTranslate
->wLanguage
, pTranslate
->wCodePage
, infoStr
);
1974 /* Retrieve file description for language and code page */
1975 if (VerQueryValue(dlg
->pVersionData
, subblock
, (PVOID
)&pTxt
, &nValLen
)) {
1976 int idx
= SendMessage(hlbox
, LB_ADDSTRING
, 0L, (LPARAM
)infoStr
);
1977 SendMessage(hlbox
, LB_SETITEMDATA
, idx
, (LPARAM
) pTxt
);
1982 SendMessage(hlbox
, LB_SETCURSEL
, 0, 0);
1984 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
1990 static INT_PTR CALLBACK
PropertiesDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1992 static struct PropertiesDialog
* dlg
;
1995 case WM_INITDIALOG
: {
1996 static const TCHAR sByteFmt
[] = {'%','s',' ','B','y','t','e','s','\0'};
1997 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1998 LPWIN32_FIND_DATA pWFD
;
2000 dlg
= (struct PropertiesDialog
*) lparam
;
2001 pWFD
= (LPWIN32_FIND_DATA
) &dlg
->entry
.data
;
2003 GetWindowText(hwnd
, b1
, MAX_PATH
);
2004 wsprintf(b2
, b1
, pWFD
->cFileName
);
2005 SetWindowText(hwnd
, b2
);
2007 format_date(&pWFD
->ftLastWriteTime
, b1
, COL_DATE
|COL_TIME
);
2008 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_LASTCHANGE
), b1
);
2010 format_longlong( b1
, ((ULONGLONG
)pWFD
->nFileSizeHigh
<< 32) | pWFD
->nFileSizeLow
);
2011 wsprintf(b2
, sByteFmt
, b1
);
2012 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_SIZE
), b2
);
2014 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_FILENAME
), pWFD
->cFileName
);
2015 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_PATH
), dlg
->path
);
2017 set_check(hwnd
, IDC_CHECK_READONLY
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_READONLY
);
2018 set_check(hwnd
, IDC_CHECK_ARCHIVE
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_ARCHIVE
);
2019 set_check(hwnd
, IDC_CHECK_COMPRESSED
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_COMPRESSED
);
2020 set_check(hwnd
, IDC_CHECK_HIDDEN
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_HIDDEN
);
2021 set_check(hwnd
, IDC_CHECK_SYSTEM
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_SYSTEM
);
2023 CheckForFileInfo(dlg
, hwnd
, dlg
->path
);
2027 int id
= (int)wparam
;
2029 switch(HIWORD(wparam
)) {
2030 case LBN_SELCHANGE
: {
2031 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
2032 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
2037 if (id
==IDOK
|| id
==IDCANCEL
)
2038 EndDialog(hwnd
, id
);
2044 HeapFree(GetProcessHeap(), 0, dlg
->pVersionData
);
2045 dlg
->pVersionData
= NULL
;
2052 static void show_properties_dlg(Entry
* entry
, HWND hwnd
)
2054 struct PropertiesDialog dlg
;
2056 memset(&dlg
, 0, sizeof(struct PropertiesDialog
));
2057 get_path(entry
, dlg
.path
);
2058 memcpy(&dlg
.entry
, entry
, sizeof(Entry
));
2060 DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_DIALOG_PROPERTIES
), hwnd
, PropertiesDialogDlgProc
, (LPARAM
)&dlg
);
2064 #ifndef _NO_EXTENSIONS
2066 static struct FullScreenParameters
{
2076 static void frame_get_clientspace(HWND hwnd
, PRECT prect
)
2080 if (!IsIconic(hwnd
))
2081 GetClientRect(hwnd
, prect
);
2085 GetWindowPlacement(hwnd
, &wp
);
2087 prect
->left
= prect
->top
= 0;
2088 prect
->right
= wp
.rcNormalPosition
.right
-wp
.rcNormalPosition
.left
-
2089 2*(GetSystemMetrics(SM_CXSIZEFRAME
)+GetSystemMetrics(SM_CXEDGE
));
2090 prect
->bottom
= wp
.rcNormalPosition
.bottom
-wp
.rcNormalPosition
.top
-
2091 2*(GetSystemMetrics(SM_CYSIZEFRAME
)+GetSystemMetrics(SM_CYEDGE
))-
2092 GetSystemMetrics(SM_CYCAPTION
)-GetSystemMetrics(SM_CYMENUSIZE
);
2095 if (IsWindowVisible(Globals
.htoolbar
)) {
2096 GetClientRect(Globals
.htoolbar
, &rt
);
2097 prect
->top
+= rt
.bottom
+2;
2100 if (IsWindowVisible(Globals
.hdrivebar
)) {
2101 GetClientRect(Globals
.hdrivebar
, &rt
);
2102 prect
->top
+= rt
.bottom
+2;
2105 if (IsWindowVisible(Globals
.hstatusbar
)) {
2106 GetClientRect(Globals
.hstatusbar
, &rt
);
2107 prect
->bottom
-= rt
.bottom
;
2111 static BOOL
toggle_fullscreen(HWND hwnd
)
2115 if ((g_fullscreen
.mode
=!g_fullscreen
.mode
)) {
2116 GetWindowRect(hwnd
, &g_fullscreen
.orgPos
);
2117 g_fullscreen
.wasZoomed
= IsZoomed(hwnd
);
2119 Frame_CalcFrameClient(hwnd
, &rt
);
2120 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
2121 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
2123 rt
.left
= g_fullscreen
.orgPos
.left
-rt
.left
;
2124 rt
.top
= g_fullscreen
.orgPos
.top
-rt
.top
;
2125 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+g_fullscreen
.orgPos
.right
-rt
.right
;
2126 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+g_fullscreen
.orgPos
.bottom
-rt
.bottom
;
2128 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
2130 MoveWindow(hwnd
, g_fullscreen
.orgPos
.left
, g_fullscreen
.orgPos
.top
,
2131 g_fullscreen
.orgPos
.right
-g_fullscreen
.orgPos
.left
,
2132 g_fullscreen
.orgPos
.bottom
-g_fullscreen
.orgPos
.top
, TRUE
);
2134 if (g_fullscreen
.wasZoomed
)
2135 ShowWindow(hwnd
, WS_MAXIMIZE
);
2138 return g_fullscreen
.mode
;
2141 static void fullscreen_move(HWND hwnd
)
2144 GetWindowRect(hwnd
, &pos
);
2146 Frame_CalcFrameClient(hwnd
, &rt
);
2147 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
2148 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
2150 rt
.left
= pos
.left
-rt
.left
;
2151 rt
.top
= pos
.top
-rt
.top
;
2152 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+pos
.right
-rt
.right
;
2153 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+pos
.bottom
-rt
.bottom
;
2155 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
2161 static void toggle_child(HWND hwnd
, UINT cmd
, HWND hchild
)
2163 BOOL vis
= IsWindowVisible(hchild
);
2165 CheckMenuItem(Globals
.hMenuOptions
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
2167 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
2169 #ifndef _NO_EXTENSIONS
2170 if (g_fullscreen
.mode
)
2171 fullscreen_move(hwnd
);
2174 resize_frame_client(hwnd
);
2177 static BOOL
activate_drive_window(LPCTSTR path
)
2179 TCHAR drv1
[_MAX_DRIVE
], drv2
[_MAX_DRIVE
];
2182 _tsplitpath(path
, drv1
, 0, 0, 0);
2184 /* search for a already open window for the same drive */
2185 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2186 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(child_wnd
, GWLP_USERDATA
);
2189 _tsplitpath(child
->root
.path
, drv2
, 0, 0, 0);
2191 if (!lstrcmpi(drv2
, drv1
)) {
2192 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2194 if (IsIconic(child_wnd
))
2195 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2205 static BOOL
activate_fs_window(LPCTSTR filesys
)
2209 /* search for a already open window of the given file system name */
2210 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2211 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(child_wnd
, GWLP_USERDATA
);
2214 if (!lstrcmpi(child
->root
.fs
, filesys
)) {
2215 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2217 if (IsIconic(child_wnd
))
2218 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2228 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
2230 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2234 if (Globals
.saveSettings
)
2235 save_registry_settings();
2237 DestroyWindow(hwnd
);
2239 /* clear handle variables */
2240 Globals
.hMenuFrame
= 0;
2241 Globals
.hMenuView
= 0;
2242 Globals
.hMenuOptions
= 0;
2243 Globals
.hMainWnd
= 0;
2244 Globals
.hmdiclient
= 0;
2245 Globals
.hdrivebar
= 0;
2252 case WM_INITMENUPOPUP
: {
2253 HWND hwndClient
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2255 if (!SendMessage(hwndClient
, WM_INITMENUPOPUP
, wparam
, lparam
))
2260 UINT cmd
= LOWORD(wparam
);
2261 HWND hwndClient
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2263 if (SendMessage(hwndClient
, WM_DISPATCH_COMMAND
, wparam
, lparam
))
2266 if (cmd
>=ID_DRIVE_FIRST
&& cmd
<=ID_DRIVE_FIRST
+0xFF) {
2267 TCHAR drv
[_MAX_DRIVE
], path
[MAX_PATH
];
2269 LPCTSTR root
= Globals
.drives
;
2272 for(i
=cmd
-ID_DRIVE_FIRST
; i
--; root
++)
2276 if (activate_drive_window(root
))
2279 _tsplitpath(root
, drv
, 0, 0, 0);
2281 if (!SetCurrentDirectory(drv
)) {
2282 display_error(hwnd
, GetLastError());
2286 GetCurrentDirectory(MAX_PATH
, path
); /*TODO: store last directory per drive */
2287 child
= alloc_child_window(path
, NULL
, hwnd
);
2289 if (!create_child_window(child
))
2290 HeapFree(GetProcessHeap(), 0, child
);
2291 } else switch(cmd
) {
2293 SendMessage(hwnd
, WM_CLOSE
, 0, 0);
2296 case ID_WINDOW_NEW
: {
2297 TCHAR path
[MAX_PATH
];
2300 GetCurrentDirectory(MAX_PATH
, path
);
2301 child
= alloc_child_window(path
, NULL
, hwnd
);
2303 if (!create_child_window(child
))
2304 HeapFree(GetProcessHeap(), 0, child
);
2311 case ID_WINDOW_CASCADE
:
2312 SendMessage(Globals
.hmdiclient
, WM_MDICASCADE
, 0, 0);
2315 case ID_WINDOW_TILE_HORZ
:
2316 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
2319 case ID_WINDOW_TILE_VERT
:
2320 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
2323 case ID_WINDOW_ARRANGE
:
2324 SendMessage(Globals
.hmdiclient
, WM_MDIICONARRANGE
, 0, 0);
2327 case ID_SELECT_FONT
:
2331 case ID_VIEW_TOOL_BAR
:
2332 toggle_child(hwnd
, cmd
, Globals
.htoolbar
);
2335 case ID_VIEW_DRIVE_BAR
:
2336 toggle_child(hwnd
, cmd
, Globals
.hdrivebar
);
2339 case ID_VIEW_STATUSBAR
:
2340 toggle_child(hwnd
, cmd
, Globals
.hstatusbar
);
2343 case ID_VIEW_SAVESETTINGS
:
2344 Globals
.saveSettings
= !Globals
.saveSettings
;
2345 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_SAVESETTINGS
,
2346 Globals
.saveSettings
? MF_CHECKED
: MF_UNCHECKED
);
2350 struct ExecuteDialog dlg
;
2352 memset(&dlg
, 0, sizeof(struct ExecuteDialog
));
2354 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_EXECUTE
), hwnd
, ExecuteDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
2355 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, dlg
.cmd
/*file*/, NULL
/*parameters*/, NULL
/*dir*/, dlg
.cmdshow
);
2357 if (PtrToUlong(hinst
) <= 32)
2358 display_error(hwnd
, GetLastError());
2362 case ID_CONNECT_NETWORK_DRIVE
: {
2363 DWORD ret
= WNetConnectionDialog(hwnd
, RESOURCETYPE_DISK
);
2364 if (ret
== NO_ERROR
)
2366 else if (ret
!= (DWORD
)-1) {
2367 if (ret
== ERROR_EXTENDED_ERROR
)
2368 display_network_error(hwnd
);
2370 display_error(hwnd
, ret
);
2374 case ID_DISCONNECT_NETWORK_DRIVE
: {
2375 DWORD ret
= WNetDisconnectDialog(hwnd
, RESOURCETYPE_DISK
);
2376 if (ret
== NO_ERROR
)
2378 else if (ret
!= (DWORD
)-1) {
2379 if (ret
== ERROR_EXTENDED_ERROR
)
2380 display_network_error(hwnd
);
2382 display_error(hwnd
, ret
);
2386 case ID_FORMAT_DISK
: {
2387 UINT sem_org
= SetErrorMode(0); /* Get the current Error Mode settings. */
2388 SetErrorMode(sem_org
& ~SEM_FAILCRITICALERRORS
); /* Force O/S to handle */
2389 SHFormatDrive(hwnd
, 0 /* A: */, SHFMT_ID_DEFAULT
, 0);
2390 SetErrorMode(sem_org
); /* Put it back the way it was. */
2394 WinHelp(hwnd
, RS(b1
,IDS_WINEFILE
), HELP_INDEX
, 0);
2397 #ifndef _NO_EXTENSIONS
2398 case ID_VIEW_FULLSCREEN
:
2399 CheckMenuItem(Globals
.hMenuOptions
, cmd
, toggle_fullscreen(hwnd
)?MF_CHECKED
:0);
2403 case ID_DRIVE_UNIX_FS
: {
2404 TCHAR path
[MAX_PATH
];
2406 char cpath
[MAX_PATH
];
2410 if (activate_fs_window(RS(b1
,IDS_UNIXFS
)))
2414 getcwd(cpath
, MAX_PATH
);
2415 MultiByteToWideChar(CP_UNIXCP
, 0, cpath
, -1, path
, MAX_PATH
);
2417 getcwd(path
, MAX_PATH
);
2419 child
= alloc_child_window(path
, NULL
, hwnd
);
2421 if (!create_child_window(child
))
2422 HeapFree(GetProcessHeap(), 0, child
);
2425 #ifdef _SHELL_FOLDERS
2426 case ID_DRIVE_SHELL_NS
: {
2427 TCHAR path
[MAX_PATH
];
2430 if (activate_fs_window(RS(b1
,IDS_SHELL
)))
2433 GetCurrentDirectory(MAX_PATH
, path
);
2434 child
= alloc_child_window(path
, get_path_pidl(path
,hwnd
), hwnd
);
2436 if (!create_child_window(child
))
2437 HeapFree(GetProcessHeap(), 0, child
);
2442 /*TODO: There are even more menu items! */
2445 ShellAbout(hwnd
, RS(b1
,IDS_WINEFILE
), NULL
,
2446 LoadImage( Globals
.hInstance
, MAKEINTRESOURCE(IDI_WINEFILE
),
2447 IMAGE_ICON
, 48, 48, LR_SHARED
));
2451 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2452 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2453 else */if ((cmd
<IDW_FIRST_CHILD
|| cmd
>=IDW_FIRST_CHILD
+0x100) &&
2454 (cmd
<SC_SIZE
|| cmd
>SC_RESTORE
))
2455 MessageBox(hwnd
, RS(b2
,IDS_NO_IMPL
), RS(b1
,IDS_WINEFILE
), MB_OK
);
2457 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2462 resize_frame(hwnd
, LOWORD(lparam
), HIWORD(lparam
));
2463 break; /* do not pass message to DefFrameProc */
2465 case WM_DEVICECHANGE
:
2466 SendMessage(hwnd
, WM_COMMAND
, MAKELONG(ID_REFRESH
,0), 0);
2469 #ifndef _NO_EXTENSIONS
2470 case WM_GETMINMAXINFO
: {
2471 LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
2473 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2474 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2477 case FRM_CALC_CLIENT
:
2478 frame_get_clientspace(hwnd
, (PRECT
)lparam
);
2480 #endif /* _NO_EXTENSIONS */
2483 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2490 static TCHAR g_pos_names
[COLUMNS
][20] = {
2494 static const int g_pos_align
[] = {
2496 HDF_LEFT
, /* Name */
2497 HDF_RIGHT
, /* Size */
2498 HDF_LEFT
, /* CDate */
2499 #ifndef _NO_EXTENSIONS
2500 HDF_LEFT
, /* ADate */
2501 HDF_LEFT
, /* MDate */
2502 HDF_LEFT
, /* Index */
2503 HDF_CENTER
, /* Links */
2505 HDF_CENTER
, /* Attributes */
2506 #ifndef _NO_EXTENSIONS
2507 HDF_LEFT
/* Security */
2511 static void resize_tree(ChildWnd
* child
, int cx
, int cy
)
2513 HDWP hdwp
= BeginDeferWindowPos(4);
2521 cx
= child
->split_pos
+ SPLIT_WIDTH
/2;
2523 #ifndef _NO_EXTENSIONS
2531 SendMessage(child
->left
.hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hdl
);
2533 DeferWindowPos(hdwp
, child
->left
.hwndHeader
, wp
.hwndInsertAfter
,
2534 wp
.x
-1, wp
.y
, child
->split_pos
-SPLIT_WIDTH
/2+1, wp
.cy
, wp
.flags
);
2535 DeferWindowPos(hdwp
, child
->right
.hwndHeader
, wp
.hwndInsertAfter
,
2536 rt
.left
+cx
+1, wp
.y
, wp
.cx
-cx
+2, wp
.cy
, wp
.flags
);
2538 #endif /* _NO_EXTENSIONS */
2540 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
);
2541 DeferWindowPos(hdwp
, child
->right
.hwnd
, 0, rt
.left
+cx
+1, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
2543 EndDeferWindowPos(hdwp
);
2547 #ifndef _NO_EXTENSIONS
2549 static HWND
create_header(HWND parent
, Pane
* pane
, UINT id
)
2554 HWND hwnd
= CreateWindow(WC_HEADER
, 0, WS_CHILD
|WS_VISIBLE
|HDS_HORZ
|HDS_FULLDRAG
/*TODO: |HDS_BUTTONS + sort orders*/,
2555 0, 0, 0, 0, parent
, (HMENU
)ULongToHandle(id
), Globals
.hInstance
, 0);
2559 SendMessage(hwnd
, WM_SETFONT
, (WPARAM
)GetStockObject(DEFAULT_GUI_FONT
), FALSE
);
2561 hdi
.mask
= HDI_TEXT
|HDI_WIDTH
|HDI_FORMAT
;
2563 for(idx
=0; idx
<COLUMNS
; idx
++) {
2564 hdi
.pszText
= g_pos_names
[idx
];
2565 hdi
.fmt
= HDF_STRING
| g_pos_align
[idx
];
2566 hdi
.cxy
= pane
->widths
[idx
];
2567 SendMessage(hwnd
, HDM_INSERTITEM
, idx
, (LPARAM
) &hdi
);
2573 #endif /* _NO_EXTENSIONS */
2576 static void init_output(HWND hwnd
)
2578 static const WCHAR s1000
[] = {'1','0','0','0','\0'};
2581 HDC hdc
= GetDC(hwnd
);
2583 if (GetNumberFormatW(LOCALE_USER_DEFAULT
, 0, s1000
, 0, b
, 16) > 4)
2584 Globals
.num_sep
= b
[1];
2586 Globals
.num_sep
= '.';
2588 old_font
= SelectObject(hdc
, Globals
.hfont
);
2589 GetTextExtentPoint32W(hdc
, sSpace
, 1, &Globals
.spaceSize
);
2590 SelectObject(hdc
, old_font
);
2591 ReleaseDC(hwnd
, hdc
);
2594 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
);
2597 /* calculate preferred width for all visible columns */
2599 static BOOL
calc_widths(Pane
* pane
, BOOL anyway
)
2601 int col
, x
, cx
, spc
=3*Globals
.spaceSize
.cx
;
2602 int entries
= SendMessage(pane
->hwnd
, LB_GETCOUNT
, 0, 0);
2603 int orgWidths
[COLUMNS
];
2604 int orgPositions
[COLUMNS
+1];
2610 memcpy(orgWidths
, pane
->widths
, sizeof(orgWidths
));
2611 memcpy(orgPositions
, pane
->positions
, sizeof(orgPositions
));
2614 for(col
=0; col
<COLUMNS
; col
++)
2615 pane
->widths
[col
] = 0;
2617 hdc
= GetDC(pane
->hwnd
);
2618 hfontOld
= SelectObject(hdc
, Globals
.hfont
);
2620 for(cnt
=0; cnt
<entries
; cnt
++) {
2621 Entry
* entry
= (Entry
*) SendMessage(pane
->hwnd
, LB_GETITEMDATA
, cnt
, 0);
2630 dis
.hwndItem
= pane
->hwnd
;
2632 dis
.rcItem
.left
= 0;
2634 dis
.rcItem
.right
= 0;
2635 dis
.rcItem
.bottom
= 0;
2636 /*dis.itemData = 0; */
2638 draw_item(pane
, &dis
, entry
, COLUMNS
);
2641 SelectObject(hdc
, hfontOld
);
2642 ReleaseDC(pane
->hwnd
, hdc
);
2645 for(col
=0; col
<COLUMNS
; col
++) {
2646 pane
->positions
[col
] = x
;
2647 cx
= pane
->widths
[col
];
2652 if (cx
< IMAGE_WIDTH
)
2655 pane
->widths
[col
] = cx
;
2661 pane
->positions
[COLUMNS
] = x
;
2663 SendMessage(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, x
, 0);
2666 if (!anyway
&& !memcmp(orgWidths
, pane
->widths
, sizeof(orgWidths
)))
2669 /* don't move, if only collapsing an entry */
2670 if (!anyway
&& pane
->widths
[0]<orgWidths
[0] &&
2671 !memcmp(orgWidths
+1, pane
->widths
+1, sizeof(orgWidths
)-sizeof(int))) {
2672 pane
->widths
[0] = orgWidths
[0];
2673 memcpy(pane
->positions
, orgPositions
, sizeof(orgPositions
));
2678 InvalidateRect(pane
->hwnd
, 0, TRUE
);
2684 /* calculate one preferred column width */
2686 static void calc_single_width(Pane
* pane
, int col
)
2690 int entries
= SendMessage(pane
->hwnd
, LB_GETCOUNT
, 0, 0);
2694 pane
->widths
[col
] = 0;
2696 hdc
= GetDC(pane
->hwnd
);
2697 hfontOld
= SelectObject(hdc
, Globals
.hfont
);
2699 for(cnt
=0; cnt
<entries
; cnt
++) {
2700 Entry
* entry
= (Entry
*) SendMessage(pane
->hwnd
, LB_GETITEMDATA
, cnt
, 0);
2708 dis
.hwndItem
= pane
->hwnd
;
2710 dis
.rcItem
.left
= 0;
2712 dis
.rcItem
.right
= 0;
2713 dis
.rcItem
.bottom
= 0;
2714 /*dis.itemData = 0; */
2716 draw_item(pane
, &dis
, entry
, col
);
2719 SelectObject(hdc
, hfontOld
);
2720 ReleaseDC(pane
->hwnd
, hdc
);
2722 cx
= pane
->widths
[col
];
2725 cx
+= 3*Globals
.spaceSize
.cx
;
2727 if (cx
< IMAGE_WIDTH
)
2731 pane
->widths
[col
] = cx
;
2733 x
= pane
->positions
[col
] + cx
;
2735 for(; col
<COLUMNS
-1; ) {
2736 pane
->positions
[++col
] = x
;
2737 x
+= pane
->widths
[col
];
2740 SendMessage(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, x
, 0);
2744 static BOOL
pattern_match(LPCTSTR str
, LPCTSTR pattern
)
2746 for( ; *str
&&*pattern
; str
++,pattern
++) {
2747 if (*pattern
== '*') {
2749 while(*pattern
== '*');
2755 if (*str
==*pattern
&& pattern_match(str
, pattern
))
2760 else if (*str
!=*pattern
&& *pattern
!='?')
2764 if (*str
|| *pattern
)
2765 if (*pattern
!='*' || pattern
[1]!='\0')
2771 static BOOL
pattern_imatch(LPCTSTR str
, LPCTSTR pattern
)
2773 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2776 lstrcpy(b2
, pattern
);
2780 return pattern_match(b1
, b2
);
2790 static enum FILE_TYPE
get_file_type(LPCTSTR filename
);
2793 /* insert listbox entries after index idx */
2795 static int insert_entries(Pane
* pane
, Entry
* dir
, LPCTSTR pattern
, int filter_flags
, int idx
)
2802 ShowWindow(pane
->hwnd
, SW_HIDE
);
2804 for(; entry
; entry
=entry
->next
) {
2806 if (pane
->treePane
&& !(entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
2810 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
2811 /* don't display entries "." and ".." in the left pane */
2812 if (pane
->treePane
&& entry
->data
.cFileName
[0] == '.')
2814 #ifndef _NO_EXTENSIONS
2815 entry
->data
.cFileName
[1] == '\0' ||
2817 (entry
->data
.cFileName
[1] == '.' && entry
->data
.cFileName
[2] == '\0'))
2820 /* filter directories in right pane */
2821 if (!pane
->treePane
&& !(filter_flags
&TF_DIRECTORIES
))
2825 /* filter using the file name pattern */
2827 if (!pattern_imatch(entry
->data
.cFileName
, pattern
))
2830 /* filter system and hidden files */
2831 if (!(filter_flags
&TF_HIDDEN
) && (entry
->data
.dwFileAttributes
&(FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
)))
2834 /* filter looking at the file type */
2835 if ((filter_flags
&(TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
)) != (TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
))
2836 switch(get_file_type(entry
->data
.cFileName
)) {
2838 if (!(filter_flags
& TF_PROGRAMS
))
2843 if (!(filter_flags
& TF_DOCUMENTS
))
2847 default: /* TF_OTHERS */
2848 if (!(filter_flags
& TF_OTHERS
))
2855 SendMessage(pane
->hwnd
, LB_INSERTSTRING
, idx
, (LPARAM
) entry
);
2857 if (pane
->treePane
&& entry
->expanded
)
2858 idx
= insert_entries(pane
, entry
->down
, pattern
, filter_flags
, idx
);
2861 ShowWindow(pane
->hwnd
, SW_SHOW
);
2867 static void format_bytes(LPTSTR buffer
, LONGLONG bytes
)
2869 static const TCHAR sFmtGB
[] = {'%', '.', '1', 'f', ' ', 'G', 'B', '\0'};
2870 static const TCHAR sFmtMB
[] = {'%', '.', '1', 'f', ' ', 'M', 'B', '\0'};
2871 static const TCHAR sFmtkB
[] = {'%', '.', '1', 'f', ' ', 'k', 'B', '\0'};
2872 static const TCHAR sFmtB
[] = {'%', 'u', 0};
2874 float fBytes
= (float)bytes
;
2876 if (bytes
>= 1073741824) /* 1 GB */
2877 sprintfW(buffer
, sFmtGB
, fBytes
/1073741824.f
+.5f
);
2878 else if (bytes
>= 1048576) /* 1 MB */
2879 sprintfW(buffer
, sFmtMB
, fBytes
/1048576.f
+.5f
);
2880 else if (bytes
>= 1024) /* 1 kB */
2881 sprintfW(buffer
, sFmtkB
, fBytes
/1024.f
+.5f
);
2883 sprintfW(buffer
, sFmtB
, (DWORD
)bytes
);
2886 static void set_space_status(void)
2888 ULARGE_INTEGER ulFreeBytesToCaller
, ulTotalBytes
, ulFreeBytes
;
2889 TCHAR fmt
[64], b1
[64], b2
[64], buffer
[BUFFER_LEN
];
2891 if (GetDiskFreeSpaceEx(NULL
, &ulFreeBytesToCaller
, &ulTotalBytes
, &ulFreeBytes
)) {
2892 format_bytes(b1
, ulFreeBytesToCaller
.QuadPart
);
2893 format_bytes(b2
, ulTotalBytes
.QuadPart
);
2894 wsprintf(buffer
, RS(fmt
,IDS_FREE_SPACE_FMT
), b1
, b2
);
2896 lstrcpy(buffer
, sQMarks
);
2898 SendMessage(Globals
.hstatusbar
, SB_SETTEXT
, 0, (LPARAM
)buffer
);
2902 static WNDPROC g_orgTreeWndProc
;
2904 static void create_tree_window(HWND parent
, Pane
* pane
, UINT id
, UINT id_header
, LPCTSTR pattern
, int filter_flags
)
2906 static const TCHAR sListBox
[] = {'L','i','s','t','B','o','x','\0'};
2908 static int s_init
= 0;
2909 Entry
* entry
= pane
->root
;
2911 pane
->hwnd
= CreateWindow(sListBox
, sEmpty
, WS_CHILD
|WS_VISIBLE
|WS_HSCROLL
|WS_VSCROLL
|
2912 LBS_DISABLENOSCROLL
|LBS_NOINTEGRALHEIGHT
|LBS_OWNERDRAWFIXED
|LBS_NOTIFY
,
2913 0, 0, 0, 0, parent
, (HMENU
)ULongToHandle(id
), Globals
.hInstance
, 0);
2915 SetWindowLongPtr(pane
->hwnd
, GWLP_USERDATA
, (LPARAM
)pane
);
2916 g_orgTreeWndProc
= (WNDPROC
) SetWindowLongPtr(pane
->hwnd
, GWLP_WNDPROC
, (LPARAM
)TreeWndProc
);
2918 SendMessage(pane
->hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, FALSE
);
2920 /* insert entries into listbox */
2922 insert_entries(pane
, entry
, pattern
, filter_flags
, -1);
2924 /* calculate column widths */
2927 init_output(pane
->hwnd
);
2930 calc_widths(pane
, TRUE
);
2932 #ifndef _NO_EXTENSIONS
2933 pane
->hwndHeader
= create_header(parent
, pane
, id_header
);
2938 static void InitChildWindow(ChildWnd
* child
)
2940 create_tree_window(child
->hwnd
, &child
->left
, IDW_TREE_LEFT
, IDW_HEADER_LEFT
, NULL
, TF_ALL
);
2941 create_tree_window(child
->hwnd
, &child
->right
, IDW_TREE_RIGHT
, IDW_HEADER_RIGHT
, child
->filter_pattern
, child
->filter_flags
);
2945 static void format_date(const FILETIME
* ft
, TCHAR
* buffer
, int visible_cols
)
2953 if (!ft
->dwLowDateTime
&& !ft
->dwHighDateTime
)
2956 if (!FileTimeToLocalFileTime(ft
, &lft
))
2957 {err
: lstrcpy(buffer
,sQMarks
); return;}
2959 if (!FileTimeToSystemTime(&lft
, &systime
))
2962 if (visible_cols
& COL_DATE
) {
2963 len
= GetDateFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
, BUFFER_LEN
);
2968 if (visible_cols
& COL_TIME
) {
2970 buffer
[len
-1] = ' ';
2972 buffer
[len
++] = ' ';
2974 if (!GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
+len
, BUFFER_LEN
-len
))
2980 static void calc_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2982 RECT rt
= {0, 0, 0, 0};
2984 DrawText(dis
->hDC
, str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
2986 if (rt
.right
> pane
->widths
[col
])
2987 pane
->widths
[col
] = rt
.right
;
2990 static void calc_tabbed_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2992 RECT rt
= {0, 0, 0, 0};
2994 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2995 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2997 DrawText(dis
->hDC
, str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2998 /*FIXME rt (0,0) ??? */
3000 if (rt
.right
> pane
->widths
[col
])
3001 pane
->widths
[col
] = rt
.right
;
3005 static void output_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
, DWORD flags
)
3007 int x
= dis
->rcItem
.left
;
3010 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
3011 rt
.top
= dis
->rcItem
.top
;
3012 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
3013 rt
.bottom
= dis
->rcItem
.bottom
;
3015 DrawText(dis
->hDC
, str
, -1, &rt
, DT_SINGLELINE
|DT_NOPREFIX
|flags
);
3018 static void output_tabbed_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3020 int x
= dis
->rcItem
.left
;
3023 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
3024 rt
.top
= dis
->rcItem
.top
;
3025 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
3026 rt
.bottom
= dis
->rcItem
.bottom
;
3028 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
3029 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
3031 DrawText(dis
->hDC
, str
, -1, &rt
, DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
3034 static void output_number(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3036 int x
= dis
->rcItem
.left
;
3043 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
3044 rt
.top
= dis
->rcItem
.top
;
3045 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
3046 rt
.bottom
= dis
->rcItem
.bottom
;
3051 /* insert number separator characters */
3052 pos
= lstrlen(s
) % 3;
3058 *d
++ = Globals
.num_sep
;
3062 DrawText(dis
->hDC
, b
, d
-b
, &rt
, DT_RIGHT
|DT_SINGLELINE
|DT_NOPREFIX
|DT_END_ELLIPSIS
);
3066 static BOOL
is_exe_file(LPCTSTR ext
)
3068 static const TCHAR executable_extensions
[][4] = {
3073 #ifndef _NO_EXTENSIONS
3077 #endif /* _NO_EXTENSIONS */
3081 TCHAR ext_buffer
[_MAX_EXT
];
3082 const TCHAR (*p
)[4];
3086 for(s
=ext
+1,d
=ext_buffer
; (*d
=tolower(*s
)); s
++)
3089 for(p
=executable_extensions
; (*p
)[0]; p
++)
3090 if (!lstrcmpi(ext_buffer
, *p
))
3096 static BOOL
is_registered_type(LPCTSTR ext
)
3098 /* check if there exists a classname for this file extension in the registry */
3099 if (!RegQueryValue(HKEY_CLASSES_ROOT
, ext
, NULL
, NULL
))
3105 static enum FILE_TYPE
get_file_type(LPCTSTR filename
)
3107 LPCTSTR ext
= strrchrW(filename
, '.');
3111 if (is_exe_file(ext
))
3112 return FT_EXECUTABLE
;
3113 else if (is_registered_type(ext
))
3120 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
)
3122 TCHAR buffer
[BUFFER_LEN
];
3124 int visible_cols
= pane
->visible_cols
;
3125 COLORREF bkcolor
, textcolor
;
3126 RECT focusRect
= dis
->rcItem
;
3133 attrs
= entry
->data
.dwFileAttributes
;
3135 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) {
3136 if (entry
->data
.cFileName
[0] == '.' && entry
->data
.cFileName
[1] == '.'
3137 && entry
->data
.cFileName
[2] == '\0')
3138 img
= IMG_FOLDER_UP
;
3139 #ifndef _NO_EXTENSIONS
3140 else if (entry
->data
.cFileName
[0] == '.' && entry
->data
.cFileName
[1] == '\0')
3141 img
= IMG_FOLDER_CUR
;
3144 #ifdef _NO_EXTENSIONS
3147 (pane
->treePane
&& (dis
->itemState
&ODS_FOCUS
)))
3148 img
= IMG_OPEN_FOLDER
;
3152 switch(get_file_type(entry
->data
.cFileName
)) {
3153 case FT_EXECUTABLE
: img
= IMG_EXECUTABLE
; break;
3154 case FT_DOCUMENT
: img
= IMG_DOCUMENT
; break;
3155 default: img
= IMG_FILE
;
3163 if (pane
->treePane
) {
3165 img_pos
= dis
->rcItem
.left
+ entry
->level
*(IMAGE_WIDTH
+TREE_LINE_DX
);
3167 if (calcWidthCol
== -1) {
3169 int y
= dis
->rcItem
.top
+ IMAGE_HEIGHT
/2;
3172 HRGN hrgn_org
= CreateRectRgn(0, 0, 0, 0);
3175 rt_clip
.left
= dis
->rcItem
.left
;
3176 rt_clip
.top
= dis
->rcItem
.top
;
3177 rt_clip
.right
= dis
->rcItem
.left
+pane
->widths
[col
];
3178 rt_clip
.bottom
= dis
->rcItem
.bottom
;
3180 hrgn
= CreateRectRgnIndirect(&rt_clip
);
3182 if (!GetClipRgn(dis
->hDC
, hrgn_org
)) {
3183 DeleteObject(hrgn_org
);
3187 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
3188 ExtSelectClipRgn(dis
->hDC
, hrgn
, RGN_AND
);
3191 if ((up
=entry
->up
) != NULL
) {
3192 MoveToEx(dis
->hDC
, img_pos
-IMAGE_WIDTH
/2, y
, 0);
3193 LineTo(dis
->hDC
, img_pos
-2, y
);
3195 x
= img_pos
- IMAGE_WIDTH
/2;
3198 x
-= IMAGE_WIDTH
+TREE_LINE_DX
;
3202 && (up
->next
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
3205 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
3206 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
3208 } while((up
=up
->up
) != NULL
);
3211 x
= img_pos
- IMAGE_WIDTH
/2;
3213 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
3214 LineTo(dis
->hDC
, x
, y
);
3218 && (entry
->next
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
)
3221 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
3223 SelectClipRgn(dis
->hDC
, hrgn_org
);
3224 if (hrgn_org
) DeleteObject(hrgn_org
);
3225 /* SelectObject(dis->hDC, holdPen); */
3226 } else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
) {
3227 int right
= img_pos
+ IMAGE_WIDTH
- TREE_LINE_DX
;
3229 if (right
> pane
->widths
[col
])
3230 pane
->widths
[col
] = right
;
3233 img_pos
= dis
->rcItem
.left
;
3236 img_pos
= dis
->rcItem
.left
;
3238 if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3239 pane
->widths
[col
] = IMAGE_WIDTH
;
3242 if (calcWidthCol
== -1) {
3243 focusRect
.left
= img_pos
-2;
3245 #ifdef _NO_EXTENSIONS
3246 if (pane
->treePane
&& entry
) {
3249 DrawText(dis
->hDC
, entry
->data
.cFileName
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
3251 focusRect
.right
= dis
->rcItem
.left
+pane
->positions
[col
+1]+TREE_LINE_DX
+ rt
.right
+2;
3255 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
)
3256 textcolor
= COLOR_COMPRESSED
;
3258 #endif /* _NO_EXTENSIONS */
3259 textcolor
= RGB(0,0,0);
3261 if (dis
->itemState
& ODS_FOCUS
) {
3262 textcolor
= RGB(255,255,255);
3263 bkcolor
= COLOR_SELECTION
;
3265 bkcolor
= RGB(255,255,255);
3268 hbrush
= CreateSolidBrush(bkcolor
);
3269 FillRect(dis
->hDC
, &focusRect
, hbrush
);
3270 DeleteObject(hbrush
);
3272 SetBkMode(dis
->hDC
, TRANSPARENT
);
3273 SetTextColor(dis
->hDC
, textcolor
);
3275 cx
= pane
->widths
[col
];
3277 if (cx
&& img
!=IMG_NONE
) {
3278 if (cx
> IMAGE_WIDTH
)
3281 #ifdef _SHELL_FOLDERS
3282 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
3283 DrawIconEx(dis
->hDC
, img_pos
, dis
->rcItem
.top
, entry
->hicon
, cx
, GetSystemMetrics(SM_CYSMICON
), 0, 0, DI_NORMAL
);
3286 ImageList_DrawEx(Globals
.himl
, img
, dis
->hDC
,
3287 img_pos
, dis
->rcItem
.top
, cx
,
3288 IMAGE_HEIGHT
, bkcolor
, CLR_DEFAULT
, ILD_NORMAL
);
3295 #ifdef _NO_EXTENSIONS
3296 if (img
>= IMG_FOLDER_UP
)
3302 /* ouput file name */
3303 if (calcWidthCol
== -1)
3304 output_text(pane
, dis
, col
, entry
->data
.cFileName
, 0);
3305 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3306 calc_width(pane
, dis
, col
, entry
->data
.cFileName
);
3310 #ifdef _NO_EXTENSIONS
3311 if (!pane
->treePane
) {
3314 /* display file size */
3315 if (visible_cols
& COL_SIZE
) {
3316 #ifdef _NO_EXTENSIONS
3317 if (!(attrs
&FILE_ATTRIBUTE_DIRECTORY
))
3320 format_longlong( buffer
, ((ULONGLONG
)entry
->data
.nFileSizeHigh
<< 32) | entry
->data
.nFileSizeLow
);
3322 if (calcWidthCol
== -1)
3323 output_number(pane
, dis
, col
, buffer
);
3324 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3325 calc_width(pane
, dis
, col
, buffer
);/*TODO: not ever time enough */
3331 /* display file date */
3332 if (visible_cols
& (COL_DATE
|COL_TIME
)) {
3333 #ifndef _NO_EXTENSIONS
3334 format_date(&entry
->data
.ftCreationTime
, buffer
, visible_cols
);
3335 if (calcWidthCol
== -1)
3336 output_text(pane
, dis
, col
, buffer
, 0);
3337 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3338 calc_width(pane
, dis
, col
, buffer
);
3341 format_date(&entry
->data
.ftLastAccessTime
, buffer
, visible_cols
);
3342 if (calcWidthCol
== -1)
3343 output_text(pane
, dis
, col
, buffer
, 0);
3344 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3345 calc_width(pane
, dis
, col
, buffer
);
3347 #endif /* _NO_EXTENSIONS */
3349 format_date(&entry
->data
.ftLastWriteTime
, buffer
, visible_cols
);
3350 if (calcWidthCol
== -1)
3351 output_text(pane
, dis
, col
, buffer
, 0);
3352 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3353 calc_width(pane
, dis
, col
, buffer
);
3357 #ifndef _NO_EXTENSIONS
3358 if (entry
->bhfi_valid
) {
3359 if (visible_cols
& COL_INDEX
) {
3360 static const TCHAR fmtlow
[] = {'%','X',0};
3361 static const TCHAR fmthigh
[] = {'%','X','%','0','8','X',0};
3363 if (entry
->bhfi
.nFileIndexHigh
)
3364 wsprintf(buffer
, fmthigh
,
3365 entry
->bhfi
.nFileIndexHigh
, entry
->bhfi
.nFileIndexLow
);
3367 wsprintf(buffer
, fmtlow
, entry
->bhfi
.nFileIndexLow
);
3369 if (calcWidthCol
== -1)
3370 output_text(pane
, dis
, col
, buffer
, DT_RIGHT
);
3371 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3372 calc_width(pane
, dis
, col
, buffer
);
3377 if (visible_cols
& COL_LINKS
) {
3378 wsprintf(buffer
, sNumFmt
, entry
->bhfi
.nNumberOfLinks
);
3380 if (calcWidthCol
== -1)
3381 output_text(pane
, dis
, col
, buffer
, DT_CENTER
);
3382 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3383 calc_width(pane
, dis
, col
, buffer
);
3389 #endif /* _NO_EXTENSIONS */
3391 /* show file attributes */
3392 if (visible_cols
& COL_ATTRIBUTES
) {
3393 #ifdef _NO_EXTENSIONS
3394 static const TCHAR s4Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3395 lstrcpy(buffer
, s4Tabs
);
3397 static const TCHAR s11Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3398 lstrcpy(buffer
, s11Tabs
);
3401 if (attrs
& FILE_ATTRIBUTE_NORMAL
) buffer
[ 0] = 'N';
3403 if (attrs
& FILE_ATTRIBUTE_READONLY
) buffer
[ 2] = 'R';
3404 if (attrs
& FILE_ATTRIBUTE_HIDDEN
) buffer
[ 4] = 'H';
3405 if (attrs
& FILE_ATTRIBUTE_SYSTEM
) buffer
[ 6] = 'S';
3406 if (attrs
& FILE_ATTRIBUTE_ARCHIVE
) buffer
[ 8] = 'A';
3407 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
) buffer
[10] = 'C';
3408 #ifndef _NO_EXTENSIONS
3409 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) buffer
[12] = 'D';
3410 if (attrs
& FILE_ATTRIBUTE_ENCRYPTED
) buffer
[14] = 'E';
3411 if (attrs
& FILE_ATTRIBUTE_TEMPORARY
) buffer
[16] = 'T';
3412 if (attrs
& FILE_ATTRIBUTE_SPARSE_FILE
) buffer
[18] = 'P';
3413 if (attrs
& FILE_ATTRIBUTE_REPARSE_POINT
) buffer
[20] = 'Q';
3414 if (attrs
& FILE_ATTRIBUTE_OFFLINE
) buffer
[22] = 'O';
3415 if (attrs
& FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
) buffer
[24] = 'X';
3416 #endif /* _NO_EXTENSIONS */
3419 if (calcWidthCol
== -1)
3420 output_tabbed_text(pane
, dis
, col
, buffer
);
3421 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3422 calc_tabbed_width(pane
, dis
, col
, buffer
);
3428 if (flags.security) {
3429 static const TCHAR sSecTabs[] = {
3430 ' ','\t',' ','\t',' ','\t',' ',
3432 ' ','\t',' ','\t',' ','\t',' ',
3434 ' ','\t',' ','\t',' ','\t',' ',
3438 DWORD rights = get_access_mask();
3440 lstrcpy(buffer, sSecTabs);
3442 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
3443 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
3444 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
3445 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
3446 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
3447 if (rights & FILE_EXECUTE) buffer[12] = 'X';
3448 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
3449 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
3450 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
3451 if (rights & WRITE_DAC) buffer[22] = 'C';
3452 if (rights & WRITE_OWNER) buffer[24] = 'O';
3453 if (rights & SYNCHRONIZE) buffer[26] = 'S';
3455 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
3458 if (flags.description) {
3459 get_description(buffer);
3460 output_text(dis, col++, buffer, 0, psize);
3464 #ifdef _NO_EXTENSIONS
3467 /* draw focus frame */
3468 if ((dis
->itemState
&ODS_FOCUS
) && calcWidthCol
==-1) {
3469 /* Currently [04/2000] Wine neither behaves exactly the same */
3470 /* way as WIN 95 nor like Windows NT... */
3475 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
3476 LOGBRUSH lb
= {PS_SOLID
, RGB(255,255,255)};
3477 hpen
= ExtCreatePen(PS_COSMETIC
|PS_ALTERNATE
, 1, &lb
, 0, 0);
3479 hpen
= CreatePen(PS_DOT
, 0, RGB(255,255,255));
3481 lastPen
= SelectPen(dis
->hDC
, hpen
);
3482 lastBrush
= SelectObject(dis
->hDC
, GetStockObject(HOLLOW_BRUSH
));
3483 SetROP2(dis
->hDC
, R2_XORPEN
);
3484 Rectangle(dis
->hDC
, focusRect
.left
, focusRect
.top
, focusRect
.right
, focusRect
.bottom
);
3485 SelectObject(dis
->hDC
, lastBrush
);
3486 SelectObject(dis
->hDC
, lastPen
);
3489 #endif /* _NO_EXTENSIONS */
3493 #ifdef _NO_EXTENSIONS
3495 static void draw_splitbar(HWND hwnd
, int x
)
3498 HDC hdc
= GetDC(hwnd
);
3500 GetClientRect(hwnd
, &rt
);
3502 rt
.left
= x
- SPLIT_WIDTH
/2;
3503 rt
.right
= x
+ SPLIT_WIDTH
/2+1;
3505 InvertRect(hdc
, &rt
);
3507 ReleaseDC(hwnd
, hdc
);
3510 #endif /* _NO_EXTENSIONS */
3513 #ifndef _NO_EXTENSIONS
3515 static void set_header(Pane
* pane
)
3518 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3521 item
.mask
= HDI_WIDTH
;
3524 for(; x
+pane
->widths
[i
]<scroll_pos
&& i
<COLUMNS
; i
++) {
3525 x
+= pane
->widths
[i
];
3526 SendMessage(pane
->hwndHeader
, HDM_SETITEM
, i
, (LPARAM
) &item
);
3530 x
+= pane
->widths
[i
];
3531 item
.cxy
= x
- scroll_pos
;
3532 SendMessage(pane
->hwndHeader
, HDM_SETITEM
, i
++, (LPARAM
) &item
);
3534 for(; i
<COLUMNS
; i
++) {
3535 item
.cxy
= pane
->widths
[i
];
3536 x
+= pane
->widths
[i
];
3537 SendMessage(pane
->hwndHeader
, HDM_SETITEM
, i
, (LPARAM
) &item
);
3542 static LRESULT
pane_notify(Pane
* pane
, NMHDR
* pnmh
)
3544 switch(pnmh
->code
) {
3545 case HDN_ITEMCHANGED
: {
3546 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3547 int idx
= phdn
->iItem
;
3548 int dx
= phdn
->pitem
->cxy
- pane
->widths
[idx
];
3552 GetClientRect(pane
->hwnd
, &clnt
);
3554 pane
->widths
[idx
] += dx
;
3556 for(i
=idx
; ++i
<=COLUMNS
; )
3557 pane
->positions
[i
] += dx
;
3560 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3564 rt_scr
.left
= pane
->positions
[idx
+1]-scroll_pos
;
3566 rt_scr
.right
= clnt
.right
;
3567 rt_scr
.bottom
= clnt
.bottom
;
3569 rt_clip
.left
= pane
->positions
[idx
]-scroll_pos
;
3571 rt_clip
.right
= clnt
.right
;
3572 rt_clip
.bottom
= clnt
.bottom
;
3574 if (rt_scr
.left
< 0) rt_scr
.left
= 0;
3575 if (rt_clip
.left
< 0) rt_clip
.left
= 0;
3577 ScrollWindowEx(pane
->hwnd
, dx
, 0, &rt_scr
, &rt_clip
, 0, 0, SW_INVALIDATE
);
3579 rt_clip
.right
= pane
->positions
[idx
+1];
3580 RedrawWindow(pane
->hwnd
, &rt_clip
, 0, RDW_INVALIDATE
|RDW_UPDATENOW
);
3582 if (pnmh
->code
== HDN_ENDTRACK
) {
3583 SendMessage(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, pane
->positions
[COLUMNS
], 0);
3585 if (GetScrollPos(pane
->hwnd
, SB_HORZ
) != scroll_pos
)
3593 case HDN_DIVIDERDBLCLICK
: {
3594 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3597 calc_single_width(pane
, phdn
->iItem
);
3598 item
.mask
= HDI_WIDTH
;
3599 item
.cxy
= pane
->widths
[phdn
->iItem
];
3601 SendMessage(pane
->hwndHeader
, HDM_SETITEM
, phdn
->iItem
, (LPARAM
) &item
);
3602 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3609 #endif /* _NO_EXTENSIONS */
3612 static void scan_entry(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3614 TCHAR path
[MAX_PATH
];
3615 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
3617 /* delete sub entries in left pane */
3619 LRESULT res
= SendMessage(child
->left
.hwnd
, LB_GETITEMDATA
, idx
+1, 0);
3620 Entry
* sub
= (Entry
*) res
;
3622 if (res
==LB_ERR
|| !sub
|| sub
->level
<=entry
->level
)
3625 SendMessage(child
->left
.hwnd
, LB_DELETESTRING
, idx
+1, 0);
3628 /* empty right pane */
3629 SendMessage(child
->right
.hwnd
, LB_RESETCONTENT
, 0, 0);
3631 /* release memory */
3632 free_entries(entry
);
3634 /* read contents from disk */
3635 #ifdef _SHELL_FOLDERS
3636 if (entry
->etype
== ET_SHELL
)
3638 read_directory(entry
, NULL
, child
->sortOrder
, hwnd
);
3643 get_path(entry
, path
);
3644 read_directory(entry
, path
, child
->sortOrder
, hwnd
);
3647 /* insert found entries in right pane */
3648 insert_entries(&child
->right
, entry
->down
, child
->filter_pattern
, child
->filter_flags
, -1);
3649 calc_widths(&child
->right
, FALSE
);
3650 #ifndef _NO_EXTENSIONS
3651 set_header(&child
->right
);
3654 child
->header_wdths_ok
= FALSE
;
3656 SetCursor(old_cursor
);
3660 /* expand a directory entry */
3662 static BOOL
expand_entry(ChildWnd
* child
, Entry
* dir
)
3667 if (!dir
|| dir
->expanded
|| !dir
->down
)
3672 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='\0' && p
->next
) {
3675 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='.' &&
3676 p
->data
.cFileName
[2]=='\0' && p
->next
)
3680 /* no subdirectories ? */
3681 if (!(p
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
3684 idx
= SendMessage(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)dir
);
3686 dir
->expanded
= TRUE
;
3688 /* insert entries in left pane */
3689 insert_entries(&child
->left
, p
, NULL
, TF_ALL
, idx
);
3691 if (!child
->header_wdths_ok
) {
3692 if (calc_widths(&child
->left
, FALSE
)) {
3693 #ifndef _NO_EXTENSIONS
3694 set_header(&child
->left
);
3697 child
->header_wdths_ok
= TRUE
;
3705 static void collapse_entry(Pane
* pane
, Entry
* dir
)
3707 int idx
= SendMessage(pane
->hwnd
, LB_FINDSTRING
, 0, (LPARAM
)dir
);
3709 ShowWindow(pane
->hwnd
, SW_HIDE
);
3711 /* hide sub entries */
3713 LRESULT res
= SendMessage(pane
->hwnd
, LB_GETITEMDATA
, idx
+1, 0);
3714 Entry
* sub
= (Entry
*) res
;
3716 if (res
==LB_ERR
|| !sub
|| sub
->level
<=dir
->level
)
3719 SendMessage(pane
->hwnd
, LB_DELETESTRING
, idx
+1, 0);
3722 dir
->expanded
= FALSE
;
3724 ShowWindow(pane
->hwnd
, SW_SHOW
);
3728 static void refresh_right_pane(ChildWnd
* child
)
3730 SendMessage(child
->right
.hwnd
, LB_RESETCONTENT
, 0, 0);
3731 insert_entries(&child
->right
, child
->right
.root
, child
->filter_pattern
, child
->filter_flags
, -1);
3732 calc_widths(&child
->right
, FALSE
);
3734 #ifndef _NO_EXTENSIONS
3735 set_header(&child
->right
);
3739 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3741 TCHAR path
[MAX_PATH
];
3748 child
->left
.cur
= entry
;
3750 child
->right
.root
= entry
->down
? entry
->down
: entry
;
3751 child
->right
.cur
= entry
;
3753 if (!entry
->scanned
)
3754 scan_entry(child
, entry
, idx
, hwnd
);
3756 refresh_right_pane(child
);
3758 get_path(entry
, path
);
3759 lstrcpy(child
->path
, path
);
3761 if (child
->hwnd
) /* only change window title, if the window already exists */
3762 SetWindowText(child
->hwnd
, path
);
3765 if (SetCurrentDirectory(path
))
3770 static void refresh_child(ChildWnd
* child
)
3772 TCHAR path
[MAX_PATH
], drv
[_MAX_DRIVE
+1];
3776 get_path(child
->left
.cur
, path
);
3777 _tsplitpath(path
, drv
, NULL
, NULL
, NULL
);
3779 child
->right
.root
= NULL
;
3781 scan_entry(child
, &child
->root
.entry
, 0, child
->hwnd
);
3783 #ifdef _SHELL_FOLDERS
3785 if (child
->root
.entry
.etype
== ET_SHELL
)
3787 LPITEMIDLIST local_pidl
= get_path_pidl(path
,child
->hwnd
);
3789 entry
= read_tree(&child
->root
, NULL
, local_pidl
, drv
, child
->sortOrder
, child
->hwnd
);
3795 entry
= read_tree(&child
->root
, path
, NULL
, drv
, child
->sortOrder
, child
->hwnd
);
3798 entry
= &child
->root
.entry
;
3800 insert_entries(&child
->left
, child
->root
.entry
.down
, NULL
, TF_ALL
, 0);
3802 set_curdir(child
, entry
, 0, child
->hwnd
);
3804 idx
= SendMessage(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)child
->left
.cur
);
3805 SendMessage(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
3809 static void create_drive_bar(void)
3811 TBBUTTON drivebarBtn
= {0, 0, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0};
3812 #ifndef _NO_EXTENSIONS
3813 TCHAR b1
[BUFFER_LEN
];
3818 GetLogicalDriveStrings(BUFFER_LEN
, Globals
.drives
);
3820 Globals
.hdrivebar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
,
3821 IDW_DRIVEBAR
, 2, Globals
.hInstance
, IDB_DRIVEBAR
, &drivebarBtn
,
3822 0, 16, 13, 16, 13, sizeof(TBBUTTON
));
3824 #ifndef _NO_EXTENSIONS
3826 /* insert unix file system button */
3830 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
3832 drivebarBtn
.idCommand
= ID_DRIVE_UNIX_FS
;
3833 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3834 drivebarBtn
.iString
++;
3836 #ifdef _SHELL_FOLDERS
3837 /* insert shell namespace button */
3838 load_string(b1
, sizeof(b1
)/sizeof(b1
[0]), IDS_SHELL
);
3839 b1
[lstrlen(b1
)+1] = '\0';
3840 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
3842 drivebarBtn
.idCommand
= ID_DRIVE_SHELL_NS
;
3843 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3844 drivebarBtn
.iString
++;
3847 /* register windows drive root strings */
3848 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)Globals
.drives
);
3851 drivebarBtn
.idCommand
= ID_DRIVE_FIRST
;
3853 for(p
=Globals
.drives
; *p
; ) {
3854 #ifdef _NO_EXTENSIONS
3855 /* insert drive letter */
3856 TCHAR b
[3] = {tolower(*p
)};
3857 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b
);
3859 switch(GetDriveType(p
)) {
3860 case DRIVE_REMOVABLE
: drivebarBtn
.iBitmap
= 1; break;
3861 case DRIVE_CDROM
: drivebarBtn
.iBitmap
= 3; break;
3862 case DRIVE_REMOTE
: drivebarBtn
.iBitmap
= 4; break;
3863 case DRIVE_RAMDISK
: drivebarBtn
.iBitmap
= 5; break;
3864 default:/*DRIVE_FIXED*/ drivebarBtn
.iBitmap
= 2;
3867 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3868 drivebarBtn
.idCommand
++;
3869 drivebarBtn
.iString
++;
3875 static void refresh_drives(void)
3879 /* destroy drive bar */
3880 DestroyWindow(Globals
.hdrivebar
);
3881 Globals
.hdrivebar
= 0;
3883 /* re-create drive bar */
3886 /* update window layout */
3887 GetClientRect(Globals
.hMainWnd
, &rect
);
3888 SendMessage(Globals
.hMainWnd
, WM_SIZE
, 0, MAKELONG(rect
.right
, rect
.bottom
));
3892 static BOOL
launch_file(HWND hwnd
, LPCTSTR cmd
, UINT nCmdShow
)
3894 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3896 if (PtrToUlong(hinst
) <= 32) {
3897 display_error(hwnd
, GetLastError());
3905 static BOOL
launch_entry(Entry
* entry
, HWND hwnd
, UINT nCmdShow
)
3907 TCHAR cmd
[MAX_PATH
];
3909 #ifdef _SHELL_FOLDERS
3910 if (entry
->etype
== ET_SHELL
) {
3913 SHELLEXECUTEINFO shexinfo
;
3915 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFO
);
3916 shexinfo
.fMask
= SEE_MASK_IDLIST
;
3917 shexinfo
.hwnd
= hwnd
;
3918 shexinfo
.lpVerb
= NULL
;
3919 shexinfo
.lpFile
= NULL
;
3920 shexinfo
.lpParameters
= NULL
;
3921 shexinfo
.lpDirectory
= NULL
;
3922 shexinfo
.nShow
= nCmdShow
;
3923 shexinfo
.lpIDList
= get_to_absolute_pidl(entry
, hwnd
);
3925 if (!ShellExecuteEx(&shexinfo
)) {
3926 display_error(hwnd
, GetLastError());
3930 if (shexinfo
.lpIDList
!= entry
->pidl
)
3931 IMalloc_Free(Globals
.iMalloc
, shexinfo
.lpIDList
);
3937 get_path(entry
, cmd
);
3939 /* start program, open document... */
3940 return launch_file(hwnd
, cmd
, nCmdShow
);
3944 static void activate_entry(ChildWnd
* child
, Pane
* pane
, HWND hwnd
)
3946 Entry
* entry
= pane
->cur
;
3951 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
3952 int scanned_old
= entry
->scanned
;
3956 int idx
= SendMessage(child
->left
.hwnd
, LB_GETCURSEL
, 0, 0);
3957 scan_entry(child
, entry
, idx
, hwnd
);
3960 #ifndef _NO_EXTENSIONS
3961 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='\0')
3965 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='.' && entry
->data
.cFileName
[2]=='\0') {
3966 entry
= child
->left
.cur
->up
;
3967 collapse_entry(&child
->left
, entry
);
3969 } else if (entry
->expanded
)
3970 collapse_entry(pane
, child
->left
.cur
);
3972 expand_entry(child
, child
->left
.cur
);
3974 if (!pane
->treePane
) focus_entry
: {
3975 int idxstart
= SendMessage(child
->left
.hwnd
, LB_GETCURSEL
, 0, 0);
3976 int idx
= SendMessage(child
->left
.hwnd
, LB_FINDSTRING
, idxstart
, (LPARAM
)entry
);
3977 SendMessage(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
3978 set_curdir(child
, entry
, idx
, hwnd
);
3983 calc_widths(pane
, FALSE
);
3985 #ifndef _NO_EXTENSIONS
3990 if (GetKeyState(VK_MENU
) < 0)
3991 show_properties_dlg(entry
, child
->hwnd
);
3993 launch_entry(entry
, child
->hwnd
, SW_SHOWNORMAL
);
3998 static BOOL
pane_command(Pane
* pane
, UINT cmd
)
4002 if (pane
->visible_cols
) {
4003 pane
->visible_cols
= 0;
4004 calc_widths(pane
, TRUE
);
4005 #ifndef _NO_EXTENSIONS
4008 InvalidateRect(pane
->hwnd
, 0, TRUE
);
4009 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
|MF_CHECKED
);
4010 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
);
4011 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
4015 case ID_VIEW_ALL_ATTRIBUTES
:
4016 if (pane
->visible_cols
!= COL_ALL
) {
4017 pane
->visible_cols
= COL_ALL
;
4018 calc_widths(pane
, TRUE
);
4019 #ifndef _NO_EXTENSIONS
4022 InvalidateRect(pane
->hwnd
, 0, TRUE
);
4023 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
);
4024 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
|MF_CHECKED
);
4025 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
4029 #ifndef _NO_EXTENSIONS
4030 case ID_PREFERRED_SIZES
: {
4031 calc_widths(pane
, TRUE
);
4033 InvalidateRect(pane
->hwnd
, 0, TRUE
);
4037 /* TODO: more command ids... */
4047 static void set_sort_order(ChildWnd
* child
, SORT_ORDER sortOrder
)
4049 if (child
->sortOrder
!= sortOrder
) {
4050 child
->sortOrder
= sortOrder
;
4051 refresh_child(child
);
4055 static void update_view_menu(ChildWnd
* child
)
4057 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_NAME
, child
->sortOrder
==SORT_NAME
? MF_CHECKED
: MF_UNCHECKED
);
4058 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_TYPE
, child
->sortOrder
==SORT_EXT
? MF_CHECKED
: MF_UNCHECKED
);
4059 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_SIZE
, child
->sortOrder
==SORT_SIZE
? MF_CHECKED
: MF_UNCHECKED
);
4060 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_DATE
, child
->sortOrder
==SORT_DATE
? MF_CHECKED
: MF_UNCHECKED
);
4064 static BOOL
is_directory(LPCTSTR target
)
4066 /*TODO correctly handle UNIX paths */
4067 DWORD target_attr
= GetFileAttributes(target
);
4069 if (target_attr
== INVALID_FILE_ATTRIBUTES
)
4072 return target_attr
&FILE_ATTRIBUTE_DIRECTORY
? TRUE
: FALSE
;
4075 static BOOL
prompt_target(Pane
* pane
, LPTSTR source
, LPTSTR target
)
4077 TCHAR path
[MAX_PATH
];
4080 get_path(pane
->cur
, path
);
4082 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_SELECT_DESTINATION
), pane
->hwnd
, DestinationDlgProc
, (LPARAM
)path
) != IDOK
)
4085 get_path(pane
->cur
, source
);
4087 /* convert relative targets to absolute paths */
4088 if (path
[0]!='/' && path
[1]!=':') {
4089 get_path(pane
->cur
->up
, target
);
4090 len
= lstrlen(target
);
4092 if (target
[len
-1]!='\\' && target
[len
-1]!='/')
4093 target
[len
++] = '/';
4095 lstrcpy(target
+len
, path
);
4097 lstrcpy(target
, path
);
4099 /* If the target already exists as directory, create a new target below this. */
4100 if (is_directory(path
)) {
4101 TCHAR fname
[_MAX_FNAME
], ext
[_MAX_EXT
];
4102 static const TCHAR sAppend
[] = {'%','s','/','%','s','%','s','\0'};
4104 _tsplitpath(source
, NULL
, NULL
, fname
, ext
);
4106 wsprintf(target
, sAppend
, path
, fname
, ext
);
4113 static IContextMenu2
* s_pctxmenu2
= NULL
;
4114 static IContextMenu3
* s_pctxmenu3
= NULL
;
4116 static void CtxMenu_reset(void)
4122 static IContextMenu
* CtxMenu_query_interfaces(IContextMenu
* pcm1
)
4124 IContextMenu
* pcm
= NULL
;
4128 if (IContextMenu_QueryInterface(pcm1
, &IID_IContextMenu3
, (void**)&pcm
) == NOERROR
)
4129 s_pctxmenu3
= (LPCONTEXTMENU3
)pcm
;
4130 else if (IContextMenu_QueryInterface(pcm1
, &IID_IContextMenu2
, (void**)&pcm
) == NOERROR
)
4131 s_pctxmenu2
= (LPCONTEXTMENU2
)pcm
;
4134 IContextMenu_Release(pcm1
);
4140 static BOOL
CtxMenu_HandleMenuMsg(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4143 if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3
, nmsg
, wparam
, lparam
)))
4148 if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2
, nmsg
, wparam
, lparam
)))
4155 static HRESULT
ShellFolderContextMenu(IShellFolder
* shell_folder
, HWND hwndParent
, int cidl
, LPCITEMIDLIST
* apidl
, int x
, int y
)
4158 BOOL executed
= FALSE
;
4160 HRESULT hr
= IShellFolder_GetUIObjectOf(shell_folder
, hwndParent
, cidl
, apidl
, &IID_IContextMenu
, NULL
, (LPVOID
*)&pcm
);
4161 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
4163 if (SUCCEEDED(hr
)) {
4164 HMENU hmenu
= CreatePopupMenu();
4166 pcm
= CtxMenu_query_interfaces(pcm
);
4169 hr
= IContextMenu_QueryContextMenu(pcm
, hmenu
, 0, FCIDM_SHVIEWFIRST
, FCIDM_SHVIEWLAST
, CMF_NORMAL
);
4171 if (SUCCEEDED(hr
)) {
4172 UINT idCmd
= TrackPopupMenu(hmenu
, TPM_LEFTALIGN
|TPM_RETURNCMD
|TPM_RIGHTBUTTON
, x
, y
, 0, hwndParent
, NULL
);
4177 CMINVOKECOMMANDINFO cmi
;
4179 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFO
);
4181 cmi
.hwnd
= hwndParent
;
4182 cmi
.lpVerb
= (LPCSTR
)(INT_PTR
)(idCmd
- FCIDM_SHVIEWFIRST
);
4183 cmi
.lpParameters
= NULL
;
4184 cmi
.lpDirectory
= NULL
;
4185 cmi
.nShow
= SW_SHOWNORMAL
;
4189 hr
= IContextMenu_InvokeCommand(pcm
, &cmi
);
4196 IContextMenu_Release(pcm
);
4199 return FAILED(hr
)? hr
: executed
? S_OK
: S_FALSE
;
4203 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4205 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
4210 LPDRAWITEMSTRUCT dis
= (LPDRAWITEMSTRUCT
)lparam
;
4211 Entry
* entry
= (Entry
*) dis
->itemData
;
4213 if (dis
->CtlID
== IDW_TREE_LEFT
)
4214 draw_item(&child
->left
, dis
, entry
, -1);
4215 else if (dis
->CtlID
== IDW_TREE_RIGHT
)
4216 draw_item(&child
->right
, dis
, entry
, -1);
4218 goto draw_menu_item
;
4223 InitChildWindow(child
);
4227 free_child_window(child
);
4228 SetWindowLongPtr(hwnd
, GWLP_USERDATA
, 0);
4235 GetClientRect(hwnd
, &rt
);
4236 BeginPaint(hwnd
, &ps
);
4237 rt
.left
= child
->split_pos
-SPLIT_WIDTH
/2;
4238 rt
.right
= child
->split_pos
+SPLIT_WIDTH
/2+1;
4239 lastBrush
= SelectObject(ps
.hdc
, GetStockObject(COLOR_SPLITBAR
));
4240 Rectangle(ps
.hdc
, rt
.left
, rt
.top
-1, rt
.right
, rt
.bottom
+1);
4241 SelectObject(ps
.hdc
, lastBrush
);
4242 #ifdef _NO_EXTENSIONS
4243 rt
.top
= rt
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
4244 FillRect(ps
.hdc
, &rt
, GetStockObject(BLACK_BRUSH
));
4246 EndPaint(hwnd
, &ps
);
4250 if (LOWORD(lparam
) == HTCLIENT
) {
4253 ScreenToClient(hwnd
, &pt
);
4255 if (pt
.x
>=child
->split_pos
-SPLIT_WIDTH
/2 && pt
.x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
4256 SetCursor(LoadCursor(0, IDC_SIZEWE
));
4262 case WM_LBUTTONDOWN
: {
4264 int x
= (short)LOWORD(lparam
);
4266 GetClientRect(hwnd
, &rt
);
4268 if (x
>=child
->split_pos
-SPLIT_WIDTH
/2 && x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
4269 last_split
= child
->split_pos
;
4270 #ifdef _NO_EXTENSIONS
4271 draw_splitbar(hwnd
, last_split
);
4279 if (GetCapture() == hwnd
) {
4280 #ifdef _NO_EXTENSIONS
4282 int x
= (short)LOWORD(lparam
);
4283 draw_splitbar(hwnd
, last_split
);
4285 GetClientRect(hwnd
, &rt
);
4286 child
->split_pos
= x
;
4287 resize_tree(child
, rt
.right
, rt
.bottom
);
4293 #ifdef _NO_EXTENSIONS
4294 case WM_CAPTURECHANGED
:
4295 if (GetCapture()==hwnd
&& last_split
>=0)
4296 draw_splitbar(hwnd
, last_split
);
4301 if (wparam
== VK_ESCAPE
)
4302 if (GetCapture() == hwnd
) {
4304 #ifdef _NO_EXTENSIONS
4305 draw_splitbar(hwnd
, last_split
);
4307 child
->split_pos
= last_split
;
4309 GetClientRect(hwnd
, &rt
);
4310 resize_tree(child
, rt
.right
, rt
.bottom
);
4313 SetCursor(LoadCursor(0, IDC_ARROW
));
4318 if (GetCapture() == hwnd
) {
4320 int x
= (short)LOWORD(lparam
);
4322 #ifdef _NO_EXTENSIONS
4323 HDC hdc
= GetDC(hwnd
);
4324 GetClientRect(hwnd
, &rt
);
4326 rt
.left
= last_split
-SPLIT_WIDTH
/2;
4327 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
4328 InvertRect(hdc
, &rt
);
4331 rt
.left
= x
-SPLIT_WIDTH
/2;
4332 rt
.right
= x
+SPLIT_WIDTH
/2+1;
4333 InvertRect(hdc
, &rt
);
4335 ReleaseDC(hwnd
, hdc
);
4337 GetClientRect(hwnd
, &rt
);
4339 if (x
>=0 && x
<rt
.right
) {
4340 child
->split_pos
= x
;
4341 resize_tree(child
, rt
.right
, rt
.bottom
);
4342 rt
.left
= x
-SPLIT_WIDTH
/2;
4343 rt
.right
= x
+SPLIT_WIDTH
/2+1;
4344 InvalidateRect(hwnd
, &rt
, FALSE
);
4345 UpdateWindow(child
->left
.hwnd
);
4347 UpdateWindow(child
->right
.hwnd
);
4353 #ifndef _NO_EXTENSIONS
4354 case WM_GETMINMAXINFO
:
4355 DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
4357 {LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
4359 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
4360 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
4362 #endif /* _NO_EXTENSIONS */
4365 if (SetCurrentDirectory(child
->path
))
4367 SetFocus(child
->focus_pane
? child
->right
.hwnd
: child
->left
.hwnd
);
4370 case WM_DISPATCH_COMMAND
: {
4371 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4373 switch(LOWORD(wparam
)) {
4374 case ID_WINDOW_NEW
: {
4375 ChildWnd
* new_child
= alloc_child_window(child
->path
, NULL
, hwnd
);
4377 if (!create_child_window(new_child
))
4378 HeapFree(GetProcessHeap(), 0, new_child
);
4384 refresh_child(child
);
4388 activate_entry(child
, pane
, hwnd
);
4391 case ID_FILE_MOVE
: {
4392 TCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
4394 if (prompt_target(pane
, source
, target
)) {
4395 SHFILEOPSTRUCT shfo
= {hwnd
, FO_MOVE
, source
, target
};
4397 source
[lstrlen(source
)+1] = '\0';
4398 target
[lstrlen(target
)+1] = '\0';
4400 if (!SHFileOperation(&shfo
))
4401 refresh_child(child
);
4405 case ID_FILE_COPY
: {
4406 TCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
4408 if (prompt_target(pane
, source
, target
)) {
4409 SHFILEOPSTRUCT shfo
= {hwnd
, FO_COPY
, source
, target
};
4411 source
[lstrlen(source
)+1] = '\0';
4412 target
[lstrlen(target
)+1] = '\0';
4414 if (!SHFileOperation(&shfo
))
4415 refresh_child(child
);
4419 case ID_FILE_DELETE
: {
4420 TCHAR path
[BUFFER_LEN
];
4421 SHFILEOPSTRUCT shfo
= {hwnd
, FO_DELETE
, path
, NULL
, FOF_ALLOWUNDO
};
4423 get_path(pane
->cur
, path
);
4425 path
[lstrlen(path
)+1] = '\0';
4427 if (!SHFileOperation(&shfo
))
4428 refresh_child(child
);
4431 case ID_VIEW_SORT_NAME
:
4432 set_sort_order(child
, SORT_NAME
);
4435 case ID_VIEW_SORT_TYPE
:
4436 set_sort_order(child
, SORT_EXT
);
4439 case ID_VIEW_SORT_SIZE
:
4440 set_sort_order(child
, SORT_SIZE
);
4443 case ID_VIEW_SORT_DATE
:
4444 set_sort_order(child
, SORT_DATE
);
4447 case ID_VIEW_FILTER
: {
4448 struct FilterDialog dlg
;
4450 memset(&dlg
, 0, sizeof(struct FilterDialog
));
4451 lstrcpy(dlg
.pattern
, child
->filter_pattern
);
4452 dlg
.flags
= child
->filter_flags
;
4454 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE
), hwnd
, FilterDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
4455 lstrcpy(child
->filter_pattern
, dlg
.pattern
);
4456 child
->filter_flags
= dlg
.flags
;
4457 refresh_right_pane(child
);
4461 case ID_VIEW_SPLIT
: {
4462 last_split
= child
->split_pos
;
4463 #ifdef _NO_EXTENSIONS
4464 draw_splitbar(hwnd
, last_split
);
4469 case ID_EDIT_PROPERTIES
:
4470 show_properties_dlg(pane
->cur
, child
->hwnd
);
4474 return pane_command(pane
, LOWORD(wparam
));
4480 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4482 switch(HIWORD(wparam
)) {
4483 case LBN_SELCHANGE
: {
4484 int idx
= SendMessage(pane
->hwnd
, LB_GETCURSEL
, 0, 0);
4485 Entry
* entry
= (Entry
*) SendMessage(pane
->hwnd
, LB_GETITEMDATA
, idx
, 0);
4487 if (pane
== &child
->left
)
4488 set_curdir(child
, entry
, idx
, hwnd
);
4494 activate_entry(child
, pane
, hwnd
);
4499 #ifndef _NO_EXTENSIONS
4501 NMHDR
* pnmh
= (NMHDR
*) lparam
;
4502 return pane_notify(pnmh
->idFrom
==IDW_HEADER_LEFT
? &child
->left
: &child
->right
, pnmh
);}
4505 #ifdef _SHELL_FOLDERS
4506 case WM_CONTEXTMENU
: {
4511 /* first select the current item in the listbox */
4512 HWND hpanel
= (HWND
) wparam
;
4513 pt_clnt
.x
= pt
.x
= (short)LOWORD(lparam
);
4514 pt_clnt
.y
= pt
.y
= (short)HIWORD(lparam
);
4515 ScreenToClient(hpanel
, &pt_clnt
);
4516 SendMessage(hpanel
, WM_LBUTTONDOWN
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4517 SendMessage(hpanel
, WM_LBUTTONUP
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4519 /* now create the popup menu using shell namespace and IContextMenu */
4520 pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4521 idx
= SendMessage(pane
->hwnd
, LB_GETCURSEL
, 0, 0);
4524 Entry
* entry
= (Entry
*) SendMessage(pane
->hwnd
, LB_GETITEMDATA
, idx
, 0);
4526 LPITEMIDLIST pidl_abs
= get_to_absolute_pidl(entry
, hwnd
);
4529 IShellFolder
* parentFolder
;
4530 LPCITEMIDLIST pidlLast
;
4532 /* get and use the parent folder to display correct context menu in all cases */
4533 if (SUCCEEDED(SHBindToParent(pidl_abs
, &IID_IShellFolder
, (LPVOID
*)&parentFolder
, &pidlLast
))) {
4534 if (ShellFolderContextMenu(parentFolder
, hwnd
, 1, &pidlLast
, pt
.x
, pt
.y
) == S_OK
)
4535 refresh_child(child
);
4537 IShellFolder_Release(parentFolder
);
4540 IMalloc_Free(Globals
.iMalloc
, pidl_abs
);
4546 case WM_MEASUREITEM
:
4548 if (!wparam
) /* Is the message menu-related? */
4549 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4554 case WM_INITMENUPOPUP
:
4555 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4558 update_view_menu(child
);
4561 case WM_MENUCHAR
: /* only supported by IContextMenu3 */
4563 LRESULT lResult
= 0;
4565 IContextMenu3_HandleMenuMsg2(s_pctxmenu3
, nmsg
, wparam
, lparam
, &lResult
);
4573 if (wparam
!= SIZE_MINIMIZED
)
4574 resize_tree(child
, LOWORD(lparam
), HIWORD(lparam
));
4578 return DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
4585 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4587 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(GetParent(hwnd
), GWLP_USERDATA
);
4588 Pane
* pane
= (Pane
*) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
4592 #ifndef _NO_EXTENSIONS
4599 child
->focus_pane
= pane
==&child
->right
? 1: 0;
4600 SendMessage(hwnd
, LB_SETSEL
, TRUE
, 1);
4601 /*TODO: check menu items */
4605 if (wparam
== VK_TAB
) {
4606 /*TODO: SetFocus(Globals.hdrivebar) */
4607 SetFocus(child
->focus_pane
? child
->left
.hwnd
: child
->right
.hwnd
);
4611 return CallWindowProc(g_orgTreeWndProc
, hwnd
, nmsg
, wparam
, lparam
);
4615 static void InitInstance(HINSTANCE hinstance
)
4617 static const TCHAR sFont
[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4624 INITCOMMONCONTROLSEX icc
= {
4625 sizeof(INITCOMMONCONTROLSEX
),
4631 setlocale(LC_COLLATE
, ""); /* set collating rules to local settings for compareName */
4633 InitCommonControlsEx(&icc
);
4636 /* register frame window class */
4638 wcFrame
.cbSize
= sizeof(WNDCLASSEX
);
4640 wcFrame
.lpfnWndProc
= FrameWndProc
;
4641 wcFrame
.cbClsExtra
= 0;
4642 wcFrame
.cbWndExtra
= 0;
4643 wcFrame
.hInstance
= hinstance
;
4644 wcFrame
.hIcon
= LoadIcon(hinstance
, MAKEINTRESOURCE(IDI_WINEFILE
));
4645 wcFrame
.hCursor
= LoadCursor(0, IDC_ARROW
);
4646 wcFrame
.hbrBackground
= 0;
4647 wcFrame
.lpszMenuName
= 0;
4648 wcFrame
.lpszClassName
= sWINEFILEFRAME
;
4649 wcFrame
.hIconSm
= (HICON
)LoadImage(hinstance
,
4650 MAKEINTRESOURCE(IDI_WINEFILE
),
4652 GetSystemMetrics(SM_CXSMICON
),
4653 GetSystemMetrics(SM_CYSMICON
),
4656 Globals
.hframeClass
= RegisterClassEx(&wcFrame
);
4659 /* register tree windows class */
4661 wcChild
.style
= CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
;
4662 wcChild
.lpfnWndProc
= ChildWndProc
;
4663 wcChild
.cbClsExtra
= 0;
4664 wcChild
.cbWndExtra
= 0;
4665 wcChild
.hInstance
= hinstance
;
4667 wcChild
.hCursor
= LoadCursor(0, IDC_ARROW
);
4668 wcChild
.hbrBackground
= 0;
4669 wcChild
.lpszMenuName
= 0;
4670 wcChild
.lpszClassName
= sWINEFILETREE
;
4672 hChildClass
= RegisterClass(&wcChild
);
4675 Globals
.haccel
= LoadAccelerators(hinstance
, MAKEINTRESOURCE(IDA_WINEFILE
));
4677 Globals
.hfont
= CreateFont(-MulDiv(8,GetDeviceCaps(hdc
,LOGPIXELSY
),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont
);
4681 Globals
.hInstance
= hinstance
;
4683 #ifdef _SHELL_FOLDERS
4685 CoGetMalloc(MEMCTX_TASK
, &Globals
.iMalloc
);
4686 SHGetDesktopFolder(&Globals
.iDesktop
);
4687 Globals
.cfStrFName
= RegisterClipboardFormat(CFSTR_FILENAME
);
4690 /* load column strings */
4693 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_NAME
);
4694 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_SIZE
);
4695 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_CDATE
);
4696 #ifndef _NO_EXTENSIONS
4697 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_ADATE
);
4698 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_MDATE
);
4699 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_IDX
);
4700 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_LINKS
);
4702 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_ATTR
);
4703 #ifndef _NO_EXTENSIONS
4704 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_SEC
);
4709 static void show_frame(HWND hwndParent
, int cmdshow
, LPCTSTR path
)
4711 static const TCHAR sMDICLIENT
[] = {'M','D','I','C','L','I','E','N','T','\0'};
4713 TCHAR buffer
[MAX_PATH
], b1
[BUFFER_LEN
];
4715 HMENU hMenuFrame
, hMenuWindow
;
4718 CLIENTCREATESTRUCT ccs
;
4720 if (Globals
.hMainWnd
)
4723 opts
= load_registry_settings();
4724 hMenuFrame
= LoadMenu(Globals
.hInstance
, MAKEINTRESOURCE(IDM_WINEFILE
));
4725 hMenuWindow
= GetSubMenu(hMenuFrame
, GetMenuItemCount(hMenuFrame
)-2);
4727 Globals
.hMenuFrame
= hMenuFrame
;
4728 Globals
.hMenuView
= GetSubMenu(hMenuFrame
, 3);
4729 Globals
.hMenuOptions
= GetSubMenu(hMenuFrame
, 4);
4731 ccs
.hWindowMenu
= hMenuWindow
;
4732 ccs
.idFirstChild
= IDW_FIRST_CHILD
;
4735 /* create main window */
4736 Globals
.hMainWnd
= CreateWindowEx(0, MAKEINTRESOURCE(Globals
.hframeClass
), RS(b1
,IDS_WINE_FILE
), WS_OVERLAPPEDWINDOW
,
4737 opts
.start_x
, opts
.start_y
, opts
.width
, opts
.height
,
4738 hwndParent
, Globals
.hMenuFrame
, Globals
.hInstance
, 0/*lpParam*/);
4741 Globals
.hmdiclient
= CreateWindowEx(0, sMDICLIENT
, NULL
,
4742 WS_CHILD
|WS_CLIPCHILDREN
|WS_VSCROLL
|WS_HSCROLL
|WS_VISIBLE
|WS_BORDER
,
4744 Globals
.hMainWnd
, 0, Globals
.hInstance
, &ccs
);
4746 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_DRIVE_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4747 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_SAVESETTINGS
, MF_BYCOMMAND
);
4752 TBBUTTON toolbarBtns
[] = {
4753 {0, 0, 0, BTNS_SEP
, {0, 0}, 0, 0},
4754 {0, ID_WINDOW_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4755 {1, ID_WINDOW_CASCADE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4756 {2, ID_WINDOW_TILE_HORZ
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4757 {3, ID_WINDOW_TILE_VERT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4759 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4760 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4763 Globals
.htoolbar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
,
4764 IDW_TOOLBAR
, 2, Globals
.hInstance
, IDB_TOOLBAR
, toolbarBtns
,
4765 sizeof(toolbarBtns
)/sizeof(TBBUTTON
), 16, 15, 16, 15, sizeof(TBBUTTON
));
4766 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_TOOL_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4769 Globals
.hstatusbar
= CreateStatusWindow(WS_CHILD
|WS_VISIBLE
, 0, Globals
.hMainWnd
, IDW_STATUSBAR
);
4770 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
4772 /* CreateStatusWindow does not accept WS_BORDER
4773 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
4774 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
4775 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
4777 /*TODO: read paths from registry */
4779 if (!path
|| !*path
) {
4780 GetCurrentDirectory(MAX_PATH
, buffer
);
4784 ShowWindow(Globals
.hMainWnd
, cmdshow
);
4786 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4787 /* Shell Namespace as default: */
4788 child
= alloc_child_window(path
, get_path_pidl(path
,Globals
.hMainWnd
), Globals
.hMainWnd
);
4790 child
= alloc_child_window(path
, NULL
, Globals
.hMainWnd
);
4793 child
->pos
.showCmd
= SW_SHOWMAXIMIZED
;
4794 child
->pos
.rcNormalPosition
.left
= 0;
4795 child
->pos
.rcNormalPosition
.top
= 0;
4796 child
->pos
.rcNormalPosition
.right
= 320;
4797 child
->pos
.rcNormalPosition
.bottom
= 280;
4799 if (!create_child_window(child
))
4800 HeapFree(GetProcessHeap(), 0, child
);
4802 SetWindowPlacement(child
->hwnd
, &child
->pos
);
4804 Globals
.himl
= ImageList_LoadBitmap(Globals
.hInstance
, MAKEINTRESOURCE(IDB_IMAGES
), 16, 0, RGB(0,255,0));
4806 Globals
.prescan_node
= FALSE
;
4808 UpdateWindow(Globals
.hMainWnd
);
4810 if (path
&& path
[0])
4813 TCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
4814 TCHAR fullname
[_MAX_FNAME
+_MAX_EXT
+1];
4816 memset(name
,0,sizeof(name
));
4817 memset(name
,0,sizeof(ext
));
4818 _tsplitpath(path
, drv
, dir
, name
, ext
);
4821 count
= SendMessage(child
->right
.hwnd
, LB_GETCOUNT
, 0, 0);
4822 lstrcpy(fullname
,name
);
4823 lstrcat(fullname
,ext
);
4825 for (index
= 0; index
< count
; index
++)
4827 Entry
* entry
= (Entry
*) SendMessage(child
->right
.hwnd
, LB_GETITEMDATA
, index
, 0);
4828 if (lstrcmp(entry
->data
.cFileName
,fullname
)==0 ||
4829 lstrcmp(entry
->data
.cAlternateFileName
,fullname
)==0)
4831 SendMessage(child
->right
.hwnd
, LB_SETCURSEL
, index
, 0);
4832 SetFocus(child
->right
.hwnd
);
4840 static void ExitInstance(void)
4842 #ifdef _SHELL_FOLDERS
4843 IShellFolder_Release(Globals
.iDesktop
);
4844 IMalloc_Release(Globals
.iMalloc
);
4848 DeleteObject(Globals
.hfont
);
4849 ImageList_Destroy(Globals
.himl
);
4852 #ifdef _NO_EXTENSIONS
4854 /* search for already running win[e]files */
4856 static int g_foundPrevInstance
= 0;
4858 static BOOL CALLBACK
EnumWndProc(HWND hwnd
, LPARAM lparam
)
4862 GetClassName(hwnd
, cls
, 128);
4864 if (!lstrcmp(cls
, (LPCTSTR
)lparam
)) {
4865 g_foundPrevInstance
++;
4872 /* search for window of given class name to allow only one running instance */
4873 static int find_window_class(LPCTSTR classname
)
4875 EnumWindows(EnumWndProc
, (LPARAM
)classname
);
4877 if (g_foundPrevInstance
)
4885 static int winefile_main(HINSTANCE hinstance
, int cmdshow
, LPCTSTR path
)
4889 InitInstance(hinstance
);
4891 show_frame(0, cmdshow
, path
);
4893 while(GetMessage(&msg
, 0, 0, 0)) {
4894 if (Globals
.hmdiclient
&& TranslateMDISysAccel(Globals
.hmdiclient
, &msg
))
4897 if (Globals
.hMainWnd
&& TranslateAccelerator(Globals
.hMainWnd
, Globals
.haccel
, &msg
))
4900 TranslateMessage(&msg
);
4901 DispatchMessage(&msg
);
4910 #if defined(UNICODE) && defined(_MSC_VER)
4911 int APIENTRY
wWinMain(HINSTANCE hinstance
, HINSTANCE previnstance
, LPWSTR cmdline
, int cmdshow
)
4913 int APIENTRY
WinMain(HINSTANCE hinstance
, HINSTANCE previnstance
, LPSTR cmdline
, int cmdshow
)
4916 #ifdef _NO_EXTENSIONS
4917 if (find_window_class(sWINEFILEFRAME
))
4921 #if defined(UNICODE) && !defined(_MSC_VER)
4922 { /* convert ANSI cmdline into WCS path string */
4923 TCHAR buffer
[MAX_PATH
];
4924 MultiByteToWideChar(CP_ACP
, 0, cmdline
, -1, buffer
, MAX_PATH
);
4925 winefile_main(hinstance
, cmdshow
, buffer
);
4928 winefile_main(hinstance
, cmdshow
, cmdline
);