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
; ) {
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';