4 * Copyright 2000, 2003, 2004, 2005 Martin Fuchs
5 * Copyright 2006 Jason Green
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
26 /* for unix filesystem function calls */
28 #include <sys/types.h>
43 #define _MAX_FNAME 256
44 #define _MAX_DIR _MAX_FNAME
45 #define _MAX_EXT _MAX_FNAME
49 #ifdef NONAMELESSUNION
50 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
52 #define UNION_MEMBER(x) x
57 #define DEFAULT_SPLIT_POS 300
59 #define DEFAULT_SPLIT_POS 200
62 static const WCHAR registry_key
[] = { 'S','o','f','t','w','a','r','e','\\',
64 'W','i','n','e','F','i','l','e','\0'};
65 static const WCHAR reg_start_x
[] = { 's','t','a','r','t','X','\0'};
66 static const WCHAR reg_start_y
[] = { 's','t','a','r','t','Y','\0'};
67 static const WCHAR reg_width
[] = { 'w','i','d','t','h','\0'};
68 static const WCHAR reg_height
[] = { 'h','e','i','g','h','t','\0'};
69 static const WCHAR reg_logfont
[] = { 'l','o','g','f','o','n','t','\0'};
79 typedef struct _Entry
{
90 #ifndef _NO_EXTENSIONS
91 BY_HANDLE_FILE_INFORMATION bhfi
;
93 enum ENTRY_TYPE etype
;
104 TCHAR path
[MAX_PATH
];
105 TCHAR volname
[_MAX_FNAME
];
115 COL_ATTRIBUTES
= 0x08,
117 #ifdef _NO_EXTENSIONS
118 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
122 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
|COL_INDEX
|COL_LINKS
135 #ifndef _NO_EXTENSIONS
139 #ifndef _NO_EXTENSIONS
145 int positions
[COLUMNS
+1];
157 int focus_pane
; /* 0: left 1: right */
160 BOOL header_wdths_ok
;
162 TCHAR path
[MAX_PATH
];
163 TCHAR filter_pattern
[MAX_PATH
];
167 SORT_ORDER sortOrder
;
172 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
);
173 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
);
174 static void refresh_child(ChildWnd
* child
);
175 static void refresh_drives(void);
176 static void get_path(Entry
* dir
, PTSTR path
);
177 static void format_date(const FILETIME
* ft
, TCHAR
* buffer
, int visible_cols
);
179 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
180 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
181 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
185 WINEFILE_GLOBALS Globals
;
187 static int last_split
;
189 /* some common string constants */
190 static const TCHAR sEmpty
[] = {'\0'};
191 static const WCHAR sSpace
[] = {' ', '\0'};
192 static const TCHAR sNumFmt
[] = {'%','d','\0'};
193 static const TCHAR sQMarks
[] = {'?','?','?','\0'};
195 /* window class names */
196 static const TCHAR sWINEFILEFRAME
[] = {'W','F','S','_','F','r','a','m','e','\0'};
197 static const TCHAR sWINEFILETREE
[] = {'W','F','S','_','T','r','e','e','\0'};
199 static const TCHAR sLongHexFmt
[] = {'%','I','6','4','X','\0'};
200 static const TCHAR sLongNumFmt
[] = {'%','I','6','4','u','\0'};
203 /* load resource string */
204 static LPTSTR
load_string(LPTSTR buffer
, DWORD size
, UINT id
)
206 LoadString(Globals
.hInstance
, id
, buffer
, size
);
210 #define RS(b, i) load_string(b, sizeof(b)/sizeof(b[0]), i)
213 /* display error message for the specified WIN32 error code */
214 static void display_error(HWND hwnd
, DWORD error
)
216 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
219 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_FROM_SYSTEM
,
220 0, error
, MAKELANGID(LANG_NEUTRAL
,SUBLANG_DEFAULT
), (PTSTR
)&msg
, 0, NULL
))
221 MessageBox(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
223 MessageBox(hwnd
, RS(b1
,IDS_ERROR
), RS(b2
,IDS_WINEFILE
), MB_OK
);
229 /* display network error message using WNetGetLastError() */
230 static void display_network_error(HWND hwnd
)
232 TCHAR msg
[BUFFER_LEN
], provider
[BUFFER_LEN
], b2
[BUFFER_LEN
];
235 if (WNetGetLastError(&error
, msg
, BUFFER_LEN
, provider
, BUFFER_LEN
) == NO_ERROR
)
236 MessageBox(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
239 static inline BOOL
get_check(HWND hwnd
, INT id
)
241 return BST_CHECKED
&SendMessageW(GetDlgItem(hwnd
, id
), BM_GETSTATE
, 0, 0);
244 static inline INT
set_check(HWND hwnd
, INT id
, BOOL on
)
246 return SendMessageW(GetDlgItem(hwnd
, id
), BM_SETCHECK
, on
?BST_CHECKED
:BST_UNCHECKED
, 0);
249 static inline void choose_font(HWND hwnd
)
251 WCHAR dlg_name
[BUFFER_LEN
], dlg_info
[BUFFER_LEN
];
255 HDC hdc
= GetDC(hwnd
);
256 chFont
.lStructSize
= sizeof(CHOOSEFONT
);
257 chFont
.hwndOwner
= hwnd
;
259 chFont
.lpLogFont
= &lFont
;
260 chFont
.Flags
= CF_SCREENFONTS
| CF_FORCEFONTEXIST
| CF_LIMITSIZE
| CF_NOSCRIPTSEL
;
261 chFont
.rgbColors
= RGB(0,0,0);
262 chFont
.lCustData
= 0;
263 chFont
.lpfnHook
= NULL
;
264 chFont
.lpTemplateName
= NULL
;
265 chFont
.hInstance
= Globals
.hInstance
;
266 chFont
.lpszStyle
= NULL
;
267 chFont
.nFontType
= SIMULATED_FONTTYPE
;
269 chFont
.nSizeMax
= 24;
271 if (ChooseFontW(&chFont
)) {
275 DeleteObject(Globals
.hfont
);
276 Globals
.hfont
= CreateFontIndirectW(&lFont
);
277 hFontOld
= SelectObject(hdc
, Globals
.hfont
);
278 GetTextExtentPoint32W(hdc
, sSpace
, 1, &Globals
.spaceSize
);
280 /* change font in all open child windows */
281 for(childWnd
=GetWindow(Globals
.hmdiclient
,GW_CHILD
); childWnd
; childWnd
=GetNextWindow(childWnd
,GW_HWNDNEXT
)) {
282 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtrW(childWnd
, GWLP_USERDATA
);
283 SendMessageW(child
->left
.hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, TRUE
);
284 SendMessageW(child
->right
.hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, TRUE
);
285 SendMessageW(child
->left
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
286 SendMessageW(child
->right
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
287 InvalidateRect(child
->left
.hwnd
, NULL
, TRUE
);
288 InvalidateRect(child
->right
.hwnd
, NULL
, TRUE
);
291 SelectObject(hdc
, hFontOld
);
293 else if (CommDlgExtendedError()) {
294 LoadStringW(Globals
.hInstance
, IDS_FONT_SEL_DLG_NAME
, dlg_name
, BUFFER_LEN
);
295 LoadStringW(Globals
.hInstance
, IDS_FONT_SEL_ERROR
, dlg_info
, BUFFER_LEN
);
296 MessageBoxW(hwnd
, dlg_info
, dlg_name
, MB_OK
);
299 ReleaseDC(hwnd
, hdc
);
306 /* call vswprintf() in msvcrt.dll */
307 /*TODO: fix swprintf() in non-msvcrt mode, so that this dynamic linking function can be removed */
308 static int msvcrt_swprintf(WCHAR
* buffer
, const WCHAR
* fmt
, ...)
310 static int (__cdecl
*pvswprintf
)(WCHAR
*, const WCHAR
*, va_list) = NULL
;
315 HMODULE hModMsvcrt
= LoadLibraryA("msvcrt");
316 pvswprintf
= (int(__cdecl
*)(WCHAR
*,const WCHAR
*,va_list)) GetProcAddress(hModMsvcrt
, "vswprintf");
320 ret
= (*pvswprintf
)(buffer
, fmt
, ap
);
326 static LPCWSTR
my_wcsrchr(LPCWSTR str
, WCHAR c
)
341 #define _tcsrchr my_wcsrchr
343 #define _tcsrchr strrchr
346 #endif /* __WINE__ */
349 /* allocate and initialise a directory entry */
350 static Entry
* alloc_entry(void)
352 Entry
* entry
= HeapAlloc(GetProcessHeap(), 0, sizeof(Entry
));
354 #ifdef _SHELL_FOLDERS
356 entry
->folder
= NULL
;
363 /* free a directory entry */
364 static void free_entry(Entry
* entry
)
366 #ifdef _SHELL_FOLDERS
367 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
368 DestroyIcon(entry
->hicon
);
370 if (entry
->folder
&& entry
->folder
!=Globals
.iDesktop
)
371 IShellFolder_Release(entry
->folder
);
374 IMalloc_Free(Globals
.iMalloc
, entry
->pidl
);
377 HeapFree(GetProcessHeap(), 0, entry
);
380 /* recursively free all child entries */
381 static void free_entries(Entry
* dir
)
383 Entry
*entry
, *next
=dir
->down
;
399 static void read_directory_win(Entry
* dir
, LPCTSTR path
)
401 Entry
* first_entry
= NULL
;
405 int level
= dir
->level
+ 1;
406 WIN32_FIND_DATA w32fd
;
408 #ifndef _NO_EXTENSIONS
412 TCHAR buffer
[MAX_PATH
], *p
;
413 for(p
=buffer
; *path
; )
420 hFind
= FindFirstFile(buffer
, &w32fd
);
422 if (hFind
!= INVALID_HANDLE_VALUE
) {
424 #ifdef _NO_EXTENSIONS
425 /* hide directory entry "." */
426 if (w32fd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
427 LPCTSTR name
= w32fd
.cFileName
;
429 if (name
[0]=='.' && name
[1]=='\0')
433 entry
= alloc_entry();
441 memcpy(&entry
->data
, &w32fd
, sizeof(WIN32_FIND_DATA
));
444 entry
->expanded
= FALSE
;
445 entry
->scanned
= FALSE
;
446 entry
->level
= level
;
448 #ifndef _NO_EXTENSIONS
449 entry
->etype
= ET_WINDOWS
;
450 entry
->bhfi_valid
= FALSE
;
452 lstrcpy(p
, entry
->data
.cFileName
);
454 hFile
= CreateFile(buffer
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
455 0, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0);
457 if (hFile
!= INVALID_HANDLE_VALUE
) {
458 if (GetFileInformationByHandle(hFile
, &entry
->bhfi
))
459 entry
->bhfi_valid
= TRUE
;
466 } while(FindNextFile(hFind
, &w32fd
));
474 dir
->down
= first_entry
;
479 static Entry
* find_entry_win(Entry
* dir
, LPCTSTR name
)
483 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
485 LPCTSTR q
= entry
->data
.cFileName
;
488 if (!*p
|| *p
== '\\' || *p
== '/')
490 } while(tolower(*p
++) == tolower(*q
++));
493 q
= entry
->data
.cAlternateFileName
;
496 if (!*p
|| *p
== '\\' || *p
== '/')
498 } while(tolower(*p
++) == tolower(*q
++));
505 static Entry
* read_tree_win(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
507 TCHAR buffer
[MAX_PATH
];
508 Entry
* entry
= &root
->entry
;
512 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
514 #ifndef _NO_EXTENSIONS
515 entry
->etype
= ET_WINDOWS
;
519 while(*s
&& *s
!= '\\' && *s
!= '/')
522 while(*s
== '\\' || *s
== '/')
528 read_directory(entry
, buffer
, sortOrder
, hwnd
);
531 entry
->expanded
= TRUE
;
536 entry
= find_entry_win(entry
, s
);
539 SetCursor(old_cursor
);
545 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
547 static BOOL
time_to_filetime(const time_t* t
, FILETIME
* ftime
)
549 struct tm
* tm
= gmtime(t
);
555 stime
.wYear
= tm
->tm_year
+1900;
556 stime
.wMonth
= tm
->tm_mon
+1;
557 /* stime.wDayOfWeek */
558 stime
.wDay
= tm
->tm_mday
;
559 stime
.wHour
= tm
->tm_hour
;
560 stime
.wMinute
= tm
->tm_min
;
561 stime
.wSecond
= tm
->tm_sec
;
563 return SystemTimeToFileTime(&stime
, ftime
);
566 static void read_directory_unix(Entry
* dir
, LPCTSTR path
)
568 Entry
* first_entry
= NULL
;
573 int level
= dir
->level
+ 1;
575 char cpath
[MAX_PATH
];
577 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, cpath
, MAX_PATH
, NULL
, NULL
);
579 const char* cpath
= path
;
582 pdir
= opendir(cpath
);
587 char buffer
[MAX_PATH
], *p
;
590 for(p
=buffer
,s
=cpath
; *s
; )
593 if (p
==buffer
|| p
[-1]!='/')
596 while((ent
=readdir(pdir
))) {
597 entry
= alloc_entry();
605 entry
->etype
= ET_UNIX
;
607 strcpy(p
, ent
->d_name
);
609 MultiByteToWideChar(CP_UNIXCP
, 0, p
, -1, entry
->data
.cFileName
, MAX_PATH
);
611 lstrcpy(entry
->data
.cFileName
, p
);
614 if (!stat(buffer
, &st
)) {
615 entry
->data
.dwFileAttributes
= p
[0]=='.'? FILE_ATTRIBUTE_HIDDEN
: 0;
617 if (S_ISDIR(st
.st_mode
))
618 entry
->data
.dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
620 entry
->data
.nFileSizeLow
= st
.st_size
& 0xFFFFFFFF;
621 entry
->data
.nFileSizeHigh
= st
.st_size
>> 32;
623 memset(&entry
->data
.ftCreationTime
, 0, sizeof(FILETIME
));
624 time_to_filetime(&st
.st_atime
, &entry
->data
.ftLastAccessTime
);
625 time_to_filetime(&st
.st_mtime
, &entry
->data
.ftLastWriteTime
);
627 entry
->bhfi
.nFileIndexLow
= ent
->d_ino
;
628 entry
->bhfi
.nFileIndexHigh
= 0;
630 entry
->bhfi
.nNumberOfLinks
= st
.st_nlink
;
632 entry
->bhfi_valid
= TRUE
;
634 entry
->data
.nFileSizeLow
= 0;
635 entry
->data
.nFileSizeHigh
= 0;
636 entry
->bhfi_valid
= FALSE
;
641 entry
->expanded
= FALSE
;
642 entry
->scanned
= FALSE
;
643 entry
->level
= level
;
654 dir
->down
= first_entry
;
658 static Entry
* find_entry_unix(Entry
* dir
, LPCTSTR name
)
662 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
664 LPCTSTR q
= entry
->data
.cFileName
;
667 if (!*p
|| *p
== '/')
669 } while(*p
++ == *q
++);
675 static Entry
* read_tree_unix(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
677 TCHAR buffer
[MAX_PATH
];
678 Entry
* entry
= &root
->entry
;
682 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
684 entry
->etype
= ET_UNIX
;
687 while(*s
&& *s
!= '/')
696 read_directory(entry
, buffer
, sortOrder
, hwnd
);
699 entry
->expanded
= TRUE
;
704 entry
= find_entry_unix(entry
, s
);
707 SetCursor(old_cursor
);
712 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
715 #ifdef _SHELL_FOLDERS
718 #define get_strret get_strretW
719 #define path_from_pidl path_from_pidlW
721 #define get_strret get_strretA
722 #define path_from_pidl path_from_pidlA
726 static void free_strret(STRRET
* str
)
728 if (str
->uType
== STRRET_WSTR
)
729 IMalloc_Free(Globals
.iMalloc
, str
->UNION_MEMBER(pOleStr
));
735 static LPSTR
strcpyn(LPSTR dest
, LPCSTR source
, size_t count
)
740 for(s
=source
; count
&&(*d
++=*s
++); )
746 static void get_strretA(STRRET
* str
, const SHITEMID
* shiid
, LPSTR buffer
, int len
)
750 WideCharToMultiByte(CP_ACP
, 0, str
->UNION_MEMBER(pOleStr
), -1, buffer
, len
, NULL
, NULL
);
754 strcpyn(buffer
, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), len
);
758 strcpyn(buffer
, str
->UNION_MEMBER(cStr
), len
);
762 static HRESULT
path_from_pidlA(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPSTR buffer
, int len
)
766 /* SHGDN_FORPARSING: get full path of id list */
767 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, SHGDN_FORPARSING
, &str
);
770 get_strretA(&str
, &pidl
->mkid
, buffer
, len
);
780 static LPWSTR
wcscpyn(LPWSTR dest
, LPCWSTR source
, size_t count
)
785 for(s
=source
; count
&&(*d
++=*s
++); )
791 static void get_strretW(STRRET
* str
, const SHITEMID
* shiid
, LPWSTR buffer
, int len
)
795 wcscpyn(buffer
, str
->UNION_MEMBER(pOleStr
), len
);
799 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), -1, buffer
, len
);
803 MultiByteToWideChar(CP_ACP
, 0, str
->UNION_MEMBER(cStr
), -1, buffer
, len
);
808 static HRESULT
name_from_pidl(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPTSTR buffer
, int len
, SHGDNF flags
)
812 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, flags
, &str
);
815 get_strret(&str
, &pidl
->mkid
, buffer
, len
);
824 static HRESULT
path_from_pidlW(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPWSTR buffer
, int len
)
828 /* SHGDN_FORPARSING: get full path of id list */
829 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, SHGDN_FORPARSING
, &str
);
832 get_strretW(&str
, &pidl
->mkid
, buffer
, len
);
841 /* create an item id list from a file system path */
843 static LPITEMIDLIST
get_path_pidl(LPTSTR path
, HWND hwnd
)
850 LPWSTR buffer
= path
;
852 WCHAR buffer
[MAX_PATH
];
853 MultiByteToWideChar(CP_ACP
, 0, path
, -1, buffer
, MAX_PATH
);
856 hr
= IShellFolder_ParseDisplayName(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
864 /* convert an item id list from relative to absolute (=relative to the desktop) format */
866 static LPITEMIDLIST
get_to_absolute_pidl(Entry
* entry
, HWND hwnd
)
868 if (entry
->up
&& entry
->up
->etype
==ET_SHELL
) {
869 LPITEMIDLIST idl
= NULL
;
872 idl
= ILCombine(ILClone(entry
->pidl
), idl
);
877 } else if (entry
->etype
== ET_WINDOWS
) {
878 TCHAR path
[MAX_PATH
];
880 get_path(entry
, path
);
882 return get_path_pidl(path
, hwnd
);
883 } else if (entry
->pidl
)
884 return ILClone(entry
->pidl
);
890 static HICON
extract_icon(IShellFolder
* folder
, LPCITEMIDLIST pidl
)
892 IExtractIcon
* pExtract
;
894 if (SUCCEEDED(IShellFolder_GetUIObjectOf(folder
, 0, 1, (LPCITEMIDLIST
*)&pidl
, &IID_IExtractIcon
, 0, (LPVOID
*)&pExtract
))) {
895 TCHAR path
[_MAX_PATH
];
900 if (SUCCEEDED(IExtractIconW_GetIconLocation(pExtract
, GIL_FORSHELL
, path
, _MAX_PATH
, &idx
, &flags
))) {
901 if (!(flags
& GIL_NOTFILENAME
)) {
903 idx
= 0; /* special case for some control panel applications */
905 if ((int)ExtractIconEx(path
, idx
, 0, &hicon
, 1) > 0)
906 flags
&= ~GIL_DONTCACHE
;
908 HICON hIconLarge
= 0;
910 HRESULT hr
= IExtractIconW_Extract(pExtract
, path
, idx
, &hIconLarge
, &hicon
, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON
)));
913 DestroyIcon(hIconLarge
);
924 static Entry
* find_entry_shell(Entry
* dir
, LPCITEMIDLIST pidl
)
928 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
929 if (entry
->pidl
->mkid
.cb
== pidl
->mkid
.cb
&&
930 !memcmp(entry
->pidl
, pidl
, entry
->pidl
->mkid
.cb
))
937 static Entry
* read_tree_shell(Root
* root
, LPITEMIDLIST pidl
, SORT_ORDER sortOrder
, HWND hwnd
)
939 Entry
* entry
= &root
->entry
;
941 LPITEMIDLIST next_pidl
= pidl
;
942 IShellFolder
* folder
;
943 IShellFolder
* child
= NULL
;
946 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
948 #ifndef _NO_EXTENSIONS
949 entry
->etype
= ET_SHELL
;
952 folder
= Globals
.iDesktop
;
955 entry
->pidl
= next_pidl
;
956 entry
->folder
= folder
;
961 /* copy first element of item idlist */
962 next_pidl
= IMalloc_Alloc(Globals
.iMalloc
, pidl
->mkid
.cb
+sizeof(USHORT
));
963 memcpy(next_pidl
, pidl
, pidl
->mkid
.cb
);
964 ((LPITEMIDLIST
)((LPBYTE
)next_pidl
+pidl
->mkid
.cb
))->mkid
.cb
= 0;
966 hr
= IShellFolder_BindToObject(folder
, next_pidl
, 0, &IID_IShellFolder
, (void**)&child
);
970 read_directory(entry
, NULL
, sortOrder
, hwnd
);
973 entry
->expanded
= TRUE
;
975 next
= find_entry_shell(entry
, next_pidl
);
982 /* go to next element */
983 pidl
= (LPITEMIDLIST
) ((LPBYTE
)pidl
+pidl
->mkid
.cb
);
986 SetCursor(old_cursor
);
992 static void fill_w32fdata_shell(IShellFolder
* folder
, LPCITEMIDLIST pidl
, SFGAOF attribs
, WIN32_FIND_DATA
* w32fdata
)
994 if (!(attribs
& SFGAO_FILESYSTEM
) ||
995 FAILED(SHGetDataFromIDList(folder
, pidl
, SHGDFIL_FINDDATA
, w32fdata
, sizeof(WIN32_FIND_DATA
)))) {
996 WIN32_FILE_ATTRIBUTE_DATA fad
;
997 IDataObject
* pDataObj
;
999 STGMEDIUM medium
= {0, {0}, 0};
1000 FORMATETC fmt
= {Globals
.cfStrFName
, 0, DVASPECT_CONTENT
, -1, TYMED_HGLOBAL
};
1002 HRESULT hr
= IShellFolder_GetUIObjectOf(folder
, 0, 1, &pidl
, &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
1004 if (SUCCEEDED(hr
)) {
1005 hr
= IDataObject_GetData(pDataObj
, &fmt
, &medium
);
1007 IDataObject_Release(pDataObj
);
1009 if (SUCCEEDED(hr
)) {
1010 LPCTSTR path
= (LPCTSTR
)GlobalLock(medium
.UNION_MEMBER(hGlobal
));
1011 UINT sem_org
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1013 if (GetFileAttributesEx(path
, GetFileExInfoStandard
, &fad
)) {
1014 w32fdata
->dwFileAttributes
= fad
.dwFileAttributes
;
1015 w32fdata
->ftCreationTime
= fad
.ftCreationTime
;
1016 w32fdata
->ftLastAccessTime
= fad
.ftLastAccessTime
;
1017 w32fdata
->ftLastWriteTime
= fad
.ftLastWriteTime
;
1019 if (!(fad
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)) {
1020 w32fdata
->nFileSizeLow
= fad
.nFileSizeLow
;
1021 w32fdata
->nFileSizeHigh
= fad
.nFileSizeHigh
;
1025 SetErrorMode(sem_org
);
1027 GlobalUnlock(medium
.UNION_MEMBER(hGlobal
));
1028 GlobalFree(medium
.UNION_MEMBER(hGlobal
));
1033 if (attribs
& (SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
))
1034 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
1036 if (attribs
& SFGAO_READONLY
)
1037 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_READONLY
;
1039 if (attribs
& SFGAO_COMPRESSED
)
1040 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_COMPRESSED
;
1044 static void read_directory_shell(Entry
* dir
, HWND hwnd
)
1046 IShellFolder
* folder
= dir
->folder
;
1047 int level
= dir
->level
+ 1;
1050 IShellFolder
* child
;
1051 IEnumIDList
* idlist
;
1053 Entry
* first_entry
= NULL
;
1060 hr
= IShellFolder_EnumObjects(folder
, hwnd
, SHCONTF_FOLDERS
|SHCONTF_NONFOLDERS
|SHCONTF_INCLUDEHIDDEN
|SHCONTF_SHAREABLE
|SHCONTF_STORAGE
, &idlist
);
1062 if (SUCCEEDED(hr
)) {
1064 #define FETCH_ITEM_COUNT 32
1065 LPITEMIDLIST pidls
[FETCH_ITEM_COUNT
];
1070 memset(pidls
, 0, sizeof(pidls
));
1072 hr
= IEnumIDList_Next(idlist
, FETCH_ITEM_COUNT
, pidls
, &cnt
);
1079 for(n
=0; n
<cnt
; ++n
) {
1080 entry
= alloc_entry();
1083 first_entry
= entry
;
1088 memset(&entry
->data
, 0, sizeof(WIN32_FIND_DATA
));
1089 entry
->bhfi_valid
= FALSE
;
1091 attribs
= ~SFGAO_FILESYSTEM
; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
1093 hr
= IShellFolder_GetAttributesOf(folder
, 1, (LPCITEMIDLIST
*)&pidls
[n
], &attribs
);
1095 if (SUCCEEDED(hr
)) {
1096 if (attribs
!= (SFGAOF
)~SFGAO_FILESYSTEM
) {
1097 fill_w32fdata_shell(folder
, pidls
[n
], attribs
, &entry
->data
);
1099 entry
->bhfi_valid
= TRUE
;
1105 entry
->pidl
= pidls
[n
];
1107 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1108 hr
= IShellFolder_BindToObject(folder
, pidls
[n
], 0, &IID_IShellFolder
, (void**)&child
);
1111 entry
->folder
= child
;
1113 entry
->folder
= NULL
;
1116 entry
->folder
= NULL
;
1118 if (!entry
->data
.cFileName
[0])
1119 /*hr = */name_from_pidl(folder
, pidls
[n
], entry
->data
.cFileName
, MAX_PATH
, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1121 /* get display icons for files and virtual objects */
1122 if (!(entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ||
1123 !(attribs
& SFGAO_FILESYSTEM
)) {
1124 entry
->hicon
= extract_icon(folder
, pidls
[n
]);
1127 entry
->hicon
= (HICON
)-1; /* don't try again later */
1132 entry
->expanded
= FALSE
;
1133 entry
->scanned
= FALSE
;
1134 entry
->level
= level
;
1136 #ifndef _NO_EXTENSIONS
1137 entry
->etype
= ET_SHELL
;
1138 entry
->bhfi_valid
= FALSE
;
1145 IEnumIDList_Release(idlist
);
1151 dir
->down
= first_entry
;
1152 dir
->scanned
= TRUE
;
1155 #endif /* _SHELL_FOLDERS */
1158 /* sort order for different directory/file types */
1167 /* distinguish between ".", ".." and any other directory names */
1168 static int TypeOrderFromDirname(LPCTSTR name
)
1170 if (name
[0] == '.') {
1171 if (name
[1] == '\0')
1172 return TO_DOT
; /* "." */
1174 if (name
[1]=='.' && name
[2]=='\0')
1175 return TO_DOTDOT
; /* ".." */
1178 return TO_OTHER_DIR
; /* anything else */
1181 /* directories first... */
1182 static int compareType(const WIN32_FIND_DATA
* fd1
, const WIN32_FIND_DATA
* fd2
)
1184 int order1
= fd1
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1185 int order2
= fd2
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1187 /* Handle "." and ".." as special case and move them at the very first beginning. */
1188 if (order1
==TO_DIR
&& order2
==TO_DIR
) {
1189 order1
= TypeOrderFromDirname(fd1
->cFileName
);
1190 order2
= TypeOrderFromDirname(fd2
->cFileName
);
1193 return order2
==order1
? 0: order1
<order2
? -1: 1;
1197 static int compareName(const void* arg1
, const void* arg2
)
1199 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1200 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1202 int cmp
= compareType(fd1
, fd2
);
1206 return lstrcmpi(fd1
->cFileName
, fd2
->cFileName
);
1209 static int compareExt(const void* arg1
, const void* arg2
)
1211 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1212 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1213 const TCHAR
*name1
, *name2
, *ext1
, *ext2
;
1215 int cmp
= compareType(fd1
, fd2
);
1219 name1
= fd1
->cFileName
;
1220 name2
= fd2
->cFileName
;
1222 ext1
= _tcsrchr(name1
, '.');
1223 ext2
= _tcsrchr(name2
, '.');
1235 cmp
= lstrcmpi(ext1
, ext2
);
1239 return lstrcmpi(name1
, name2
);
1242 static int compareSize(const void* arg1
, const void* arg2
)
1244 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1245 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1247 int cmp
= compareType(fd1
, fd2
);
1251 cmp
= fd2
->nFileSizeHigh
- fd1
->nFileSizeHigh
;
1258 cmp
= fd2
->nFileSizeLow
- fd1
->nFileSizeLow
;
1260 return cmp
<0? -1: cmp
>0? 1: 0;
1263 static int compareDate(const void* arg1
, const void* arg2
)
1265 const WIN32_FIND_DATA
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1266 const WIN32_FIND_DATA
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1268 int cmp
= compareType(fd1
, fd2
);
1272 return CompareFileTime(&fd2
->ftLastWriteTime
, &fd1
->ftLastWriteTime
);
1276 static int (*sortFunctions
[])(const void* arg1
, const void* arg2
) = {
1277 compareName
, /* SORT_NAME */
1278 compareExt
, /* SORT_EXT */
1279 compareSize
, /* SORT_SIZE */
1280 compareDate
/* SORT_DATE */
1284 static void SortDirectory(Entry
* dir
, SORT_ORDER sortOrder
)
1286 Entry
* entry
= dir
->down
;
1291 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1295 array
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(Entry
*));
1298 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1301 /* call qsort with the appropriate compare function */
1302 qsort(array
, len
, sizeof(array
[0]), sortFunctions
[sortOrder
]);
1304 dir
->down
= array
[0];
1306 for(p
=array
; --len
; p
++)
1311 HeapFree(GetProcessHeap(), 0, array
);
1316 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
1318 TCHAR buffer
[MAX_PATH
];
1323 #ifdef _SHELL_FOLDERS
1324 if (dir
->etype
== ET_SHELL
)
1326 read_directory_shell(dir
, hwnd
);
1328 if (Globals
.prescan_node
) {
1337 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1338 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1339 read_directory_shell(entry
, hwnd
);
1340 SortDirectory(entry
, sortOrder
);
1346 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1347 if (dir
->etype
== ET_UNIX
)
1349 read_directory_unix(dir
, path
);
1351 if (Globals
.prescan_node
) {
1360 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1361 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1362 lstrcpy(d
, entry
->data
.cFileName
);
1363 read_directory_unix(entry
, buffer
);
1364 SortDirectory(entry
, sortOrder
);
1371 read_directory_win(dir
, path
);
1373 if (Globals
.prescan_node
) {
1382 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1383 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1384 lstrcpy(d
, entry
->data
.cFileName
);
1385 read_directory_win(entry
, buffer
);
1386 SortDirectory(entry
, sortOrder
);
1391 SortDirectory(dir
, sortOrder
);
1395 static Entry
* read_tree(Root
* root
, LPCTSTR path
, LPITEMIDLIST pidl
, LPTSTR drv
, SORT_ORDER sortOrder
, HWND hwnd
)
1397 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1398 static const TCHAR sSlash
[] = {'/', '\0'};
1400 static const TCHAR sBackslash
[] = {'\\', '\0'};
1402 #ifdef _SHELL_FOLDERS
1405 /* read shell namespace tree */
1406 root
->drive_type
= DRIVE_UNKNOWN
;
1409 load_string(root
->volname
, sizeof(root
->volname
)/sizeof(root
->volname
[0]), IDS_DESKTOP
);
1411 load_string(root
->fs
, sizeof(root
->fs
)/sizeof(root
->fs
[0]), IDS_SHELL
);
1413 return read_tree_shell(root
, pidl
, sortOrder
, hwnd
);
1417 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1420 /* read unix file system tree */
1421 root
->drive_type
= GetDriveType(path
);
1423 lstrcat(drv
, sSlash
);
1424 load_string(root
->volname
, sizeof(root
->volname
)/sizeof(root
->volname
[0]), IDS_ROOT_FS
);
1426 load_string(root
->fs
, sizeof(root
->fs
)/sizeof(root
->fs
[0]), IDS_UNIXFS
);
1428 lstrcpy(root
->path
, sSlash
);
1430 return read_tree_unix(root
, path
, sortOrder
, hwnd
);
1434 /* read WIN32 file system tree */
1435 root
->drive_type
= GetDriveType(path
);
1437 lstrcat(drv
, sBackslash
);
1438 GetVolumeInformation(drv
, root
->volname
, _MAX_FNAME
, 0, 0, &root
->fs_flags
, root
->fs
, _MAX_DIR
);
1440 lstrcpy(root
->path
, drv
);
1442 return read_tree_win(root
, path
, sortOrder
, hwnd
);
1446 /* flags to filter different file types */
1448 TF_DIRECTORIES
= 0x01,
1450 TF_DOCUMENTS
= 0x04,
1457 static ChildWnd
* alloc_child_window(LPCTSTR path
, LPITEMIDLIST pidl
, HWND hwnd
)
1459 TCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
1460 TCHAR dir_path
[MAX_PATH
];
1461 TCHAR b1
[BUFFER_LEN
];
1462 static const TCHAR sAsterics
[] = {'*', '\0'};
1464 ChildWnd
* child
= HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd
));
1465 Root
* root
= &child
->root
;
1468 memset(child
, 0, sizeof(ChildWnd
));
1470 child
->left
.treePane
= TRUE
;
1471 child
->left
.visible_cols
= 0;
1473 child
->right
.treePane
= FALSE
;
1474 #ifndef _NO_EXTENSIONS
1475 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_INDEX
|COL_LINKS
;
1477 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
;
1480 child
->pos
.length
= sizeof(WINDOWPLACEMENT
);
1481 child
->pos
.flags
= 0;
1482 child
->pos
.showCmd
= SW_SHOWNORMAL
;
1483 child
->pos
.rcNormalPosition
.left
= CW_USEDEFAULT
;
1484 child
->pos
.rcNormalPosition
.top
= CW_USEDEFAULT
;
1485 child
->pos
.rcNormalPosition
.right
= CW_USEDEFAULT
;
1486 child
->pos
.rcNormalPosition
.bottom
= CW_USEDEFAULT
;
1488 child
->focus_pane
= 0;
1489 child
->split_pos
= DEFAULT_SPLIT_POS
;
1490 child
->sortOrder
= SORT_NAME
;
1491 child
->header_wdths_ok
= FALSE
;
1495 lstrcpy(child
->path
, path
);
1497 _tsplitpath(path
, drv
, dir
, name
, ext
);
1500 lstrcpy(child
->filter_pattern
, sAsterics
);
1501 child
->filter_flags
= TF_ALL
;
1503 root
->entry
.level
= 0;
1505 lstrcpy(dir_path
, drv
);
1506 lstrcat(dir_path
, dir
);
1507 entry
= read_tree(root
, dir_path
, pidl
, drv
, child
->sortOrder
, hwnd
);
1509 #ifdef _SHELL_FOLDERS
1510 if (root
->entry
.etype
== ET_SHELL
)
1511 load_string(root
->entry
.data
.cFileName
, sizeof(root
->entry
.data
.cFileName
)/sizeof(root
->entry
.data
.cFileName
[0]), IDS_DESKTOP
);
1514 wsprintf(root
->entry
.data
.cFileName
, RS(b1
,IDS_TITLEFMT
), drv
, root
->fs
);
1516 root
->entry
.data
.dwFileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1518 child
->left
.root
= &root
->entry
;
1519 child
->right
.root
= NULL
;
1521 set_curdir(child
, entry
, 0, hwnd
);
1527 /* free all memory associated with a child window */
1528 static void free_child_window(ChildWnd
* child
)
1530 free_entries(&child
->root
.entry
);
1531 HeapFree(GetProcessHeap(), 0, child
);
1535 /* get full path of specified directory entry */
1536 static void get_path(Entry
* dir
, PTSTR path
)
1542 #ifdef _SHELL_FOLDERS
1543 if (dir
->etype
== ET_SHELL
)
1553 hr
= IShellFolder_GetAttributesOf(dir
->folder
, 1, (LPCITEMIDLIST
*)&dir
->pidl
, &attribs
);
1555 if (SUCCEEDED(hr
) && (attribs
&SFGAO_FILESYSTEM
)) {
1556 IShellFolder
* parent
= dir
->up
? dir
->up
->folder
: Globals
.iDesktop
;
1558 hr
= path_from_pidl(parent
, dir
->pidl
, path
, MAX_PATH
);
1564 for(entry
=dir
; entry
; level
++) {
1570 name
= entry
->data
.cFileName
;
1573 for(l
=0; *s
&& *s
!= '/' && *s
!= '\\'; s
++)
1579 memmove(path
+l
+1, path
, len
*sizeof(TCHAR
));
1580 memcpy(path
+1, name
, l
*sizeof(TCHAR
));
1583 #ifndef _NO_EXTENSIONS
1584 if (entry
->etype
== ET_UNIX
)
1593 memmove(path
+l
, path
, len
*sizeof(TCHAR
));
1594 memcpy(path
, name
, l
*sizeof(TCHAR
));
1601 #ifndef _NO_EXTENSIONS
1602 if (entry
->etype
== ET_UNIX
)
1613 static windowOptions
load_registry_settings(void)
1621 RegOpenKeyExW( HKEY_CURRENT_USER
, registry_key
,
1622 0, KEY_QUERY_VALUE
, &hKey
);
1624 size
= sizeof(DWORD
);
1626 if( RegQueryValueExW( hKey
, reg_start_x
, NULL
, &type
,
1627 (LPBYTE
) &opts
.start_x
, &size
) != ERROR_SUCCESS
)
1628 opts
.start_x
= CW_USEDEFAULT
;
1630 if( RegQueryValueExW( hKey
, reg_start_y
, NULL
, &type
,
1631 (LPBYTE
) &opts
.start_y
, &size
) != ERROR_SUCCESS
)
1632 opts
.start_y
= CW_USEDEFAULT
;
1634 if( RegQueryValueExW( hKey
, reg_width
, NULL
, &type
,
1635 (LPBYTE
) &opts
.width
, &size
) != ERROR_SUCCESS
)
1636 opts
.width
= CW_USEDEFAULT
;
1638 if( RegQueryValueExW( hKey
, reg_height
, NULL
, &type
,
1639 (LPBYTE
) &opts
.height
, &size
) != ERROR_SUCCESS
)
1640 opts
.height
= CW_USEDEFAULT
;
1641 size
=sizeof(logfont
);
1642 if( RegQueryValueExW( hKey
, reg_logfont
, NULL
, &type
,
1643 (LPBYTE
) &logfont
, &size
) != ERROR_SUCCESS
)
1644 GetObject(GetStockObject(DEFAULT_GUI_FONT
),sizeof(logfont
),&logfont
);
1646 RegCloseKey( hKey
);
1648 Globals
.hfont
= CreateFontIndirect(&logfont
);
1652 static void save_registry_settings(void)
1659 wi
.cbSize
= sizeof( WINDOWINFO
);
1660 GetWindowInfo(Globals
.hMainWnd
, &wi
);
1661 width
= wi
.rcWindow
.right
- wi
.rcWindow
.left
;
1662 height
= wi
.rcWindow
.bottom
- wi
.rcWindow
.top
;
1664 if ( RegOpenKeyExW( HKEY_CURRENT_USER
, registry_key
,
1665 0, KEY_SET_VALUE
, &hKey
) != ERROR_SUCCESS
)
1667 /* Unable to save registry settings - try to create key */
1668 if ( RegCreateKeyExW( HKEY_CURRENT_USER
, registry_key
,
1669 0, NULL
, REG_OPTION_NON_VOLATILE
,
1670 KEY_SET_VALUE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
1672 /* FIXME: Cannot create key */
1676 /* Save all of the settings */
1677 RegSetValueExW( hKey
, reg_start_x
, 0, REG_DWORD
,
1678 (LPBYTE
) &wi
.rcWindow
.left
, sizeof(DWORD
) );
1679 RegSetValueExW( hKey
, reg_start_y
, 0, REG_DWORD
,
1680 (LPBYTE
) &wi
.rcWindow
.top
, sizeof(DWORD
) );
1681 RegSetValueExW( hKey
, reg_width
, 0, REG_DWORD
,
1682 (LPBYTE
) &width
, sizeof(DWORD
) );
1683 RegSetValueExW( hKey
, reg_height
, 0, REG_DWORD
,
1684 (LPBYTE
) &height
, sizeof(DWORD
) );
1685 GetObject(Globals
.hfont
, sizeof(logfont
), &logfont
);
1686 RegSetValueExW( hKey
, reg_logfont
, 0, REG_BINARY
,
1687 (LPBYTE
) &logfont
, sizeof(LOGFONT
) );
1689 /* TODO: Save more settings here (List vs. Detailed View, etc.) */
1690 RegCloseKey( hKey
);
1693 static void resize_frame_rect(HWND hwnd
, PRECT prect
)
1698 if (IsWindowVisible(Globals
.htoolbar
)) {
1699 SendMessage(Globals
.htoolbar
, WM_SIZE
, 0, 0);
1700 GetClientRect(Globals
.htoolbar
, &rt
);
1701 prect
->top
= rt
.bottom
+3;
1702 prect
->bottom
-= rt
.bottom
+3;
1705 if (IsWindowVisible(Globals
.hdrivebar
)) {
1706 SendMessage(Globals
.hdrivebar
, WM_SIZE
, 0, 0);
1707 GetClientRect(Globals
.hdrivebar
, &rt
);
1708 new_top
= --prect
->top
+ rt
.bottom
+3;
1709 MoveWindow(Globals
.hdrivebar
, 0, prect
->top
, rt
.right
, new_top
, TRUE
);
1710 prect
->top
= new_top
;
1711 prect
->bottom
-= rt
.bottom
+2;
1714 if (IsWindowVisible(Globals
.hstatusbar
)) {
1715 int parts
[] = {300, 500};
1717 SendMessage(Globals
.hstatusbar
, WM_SIZE
, 0, 0);
1718 SendMessage(Globals
.hstatusbar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
1719 GetClientRect(Globals
.hstatusbar
, &rt
);
1720 prect
->bottom
-= rt
.bottom
;
1723 MoveWindow(Globals
.hmdiclient
, prect
->left
-1,prect
->top
-1,prect
->right
+2,prect
->bottom
+1, TRUE
);
1726 static void resize_frame(HWND hwnd
, int cx
, int cy
)
1735 resize_frame_rect(hwnd
, &rect
);
1738 static void resize_frame_client(HWND hwnd
)
1742 GetClientRect(hwnd
, &rect
);
1744 resize_frame_rect(hwnd
, &rect
);
1748 static HHOOK hcbthook
;
1749 static ChildWnd
* newchild
= NULL
;
1751 static LRESULT CALLBACK
CBTProc(int code
, WPARAM wparam
, LPARAM lparam
)
1753 if (code
==HCBT_CREATEWND
&& newchild
) {
1754 ChildWnd
* child
= newchild
;
1757 child
->hwnd
= (HWND
) wparam
;
1758 SetWindowLongPtr(child
->hwnd
, GWLP_USERDATA
, (LPARAM
)child
);
1761 return CallNextHookEx(hcbthook
, code
, wparam
, lparam
);
1764 static HWND
create_child_window(ChildWnd
* child
)
1766 MDICREATESTRUCT mcs
;
1769 mcs
.szClass
= sWINEFILETREE
;
1770 mcs
.szTitle
= (LPTSTR
)child
->path
;
1771 mcs
.hOwner
= Globals
.hInstance
;
1772 mcs
.x
= child
->pos
.rcNormalPosition
.left
;
1773 mcs
.y
= child
->pos
.rcNormalPosition
.top
;
1774 mcs
.cx
= child
->pos
.rcNormalPosition
.right
-child
->pos
.rcNormalPosition
.left
;
1775 mcs
.cy
= child
->pos
.rcNormalPosition
.bottom
-child
->pos
.rcNormalPosition
.top
;
1779 hcbthook
= SetWindowsHookEx(WH_CBT
, CBTProc
, 0, GetCurrentThreadId());
1782 child
->hwnd
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDICREATE
, 0, (LPARAM
)&mcs
);
1784 UnhookWindowsHookEx(hcbthook
);
1788 UnhookWindowsHookEx(hcbthook
);
1790 SendMessage(child
->left
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1791 SendMessage(child
->right
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1793 idx
= SendMessage(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)child
->left
.cur
);
1794 SendMessage(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
1800 struct ExecuteDialog
{
1801 TCHAR cmd
[MAX_PATH
];
1805 static INT_PTR CALLBACK
ExecuteDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1807 static struct ExecuteDialog
* dlg
;
1811 dlg
= (struct ExecuteDialog
*) lparam
;
1815 int id
= (int)wparam
;
1818 GetWindowText(GetDlgItem(hwnd
, 201), dlg
->cmd
, MAX_PATH
);
1819 dlg
->cmdshow
= get_check(hwnd
,214) ? SW_SHOWMINIMIZED
: SW_SHOWNORMAL
;
1820 EndDialog(hwnd
, id
);
1821 } else if (id
== IDCANCEL
)
1822 EndDialog(hwnd
, id
);
1831 static INT_PTR CALLBACK
DestinationDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1833 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1837 SetWindowLongPtr(hwnd
, GWLP_USERDATA
, lparam
);
1838 SetWindowText(GetDlgItem(hwnd
, 201), (LPCTSTR
)lparam
);
1842 int id
= (int)wparam
;
1846 LPTSTR dest
= (LPTSTR
) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
1847 GetWindowText(GetDlgItem(hwnd
, 201), dest
, MAX_PATH
);
1848 EndDialog(hwnd
, id
);
1852 EndDialog(hwnd
, id
);
1856 MessageBox(hwnd
, RS(b1
,IDS_NO_IMPL
), RS(b2
,IDS_WINEFILE
), MB_OK
);
1868 struct FilterDialog
{
1869 TCHAR pattern
[MAX_PATH
];
1873 static INT_PTR CALLBACK
FilterDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1875 static struct FilterDialog
* dlg
;
1879 dlg
= (struct FilterDialog
*) lparam
;
1880 SetWindowText(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
);
1881 set_check(hwnd
, IDC_VIEW_TYPE_DIRECTORIES
, dlg
->flags
&TF_DIRECTORIES
);
1882 set_check(hwnd
, IDC_VIEW_TYPE_PROGRAMS
, dlg
->flags
&TF_PROGRAMS
);
1883 set_check(hwnd
, IDC_VIEW_TYPE_DOCUMENTS
, dlg
->flags
&TF_DOCUMENTS
);
1884 set_check(hwnd
, IDC_VIEW_TYPE_OTHERS
, dlg
->flags
&TF_OTHERS
);
1885 set_check(hwnd
, IDC_VIEW_TYPE_HIDDEN
, dlg
->flags
&TF_HIDDEN
);
1889 int id
= (int)wparam
;
1894 GetWindowText(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
, MAX_PATH
);
1896 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_DIRECTORIES
) ? TF_DIRECTORIES
: 0;
1897 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_PROGRAMS
) ? TF_PROGRAMS
: 0;
1898 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_DOCUMENTS
) ? TF_DOCUMENTS
: 0;
1899 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_OTHERS
) ? TF_OTHERS
: 0;
1900 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_HIDDEN
) ? TF_HIDDEN
: 0;
1904 EndDialog(hwnd
, id
);
1905 } else if (id
== IDCANCEL
)
1906 EndDialog(hwnd
, id
);
1915 struct PropertiesDialog
{
1916 TCHAR path
[MAX_PATH
];
1921 /* Structure used to store enumerated languages and code pages. */
1922 struct LANGANDCODEPAGE
{
1927 static LPCSTR InfoStrings
[] = {
1943 static void PropDlg_DisplayValue(HWND hlbox
, HWND hedit
)
1945 int idx
= SendMessage(hlbox
, LB_GETCURSEL
, 0, 0);
1947 if (idx
!= LB_ERR
) {
1948 LPCTSTR pValue
= (LPCTSTR
) SendMessage(hlbox
, LB_GETITEMDATA
, idx
, 0);
1951 SetWindowText(hedit
, pValue
);
1955 static void CheckForFileInfo(struct PropertiesDialog
* dlg
, HWND hwnd
, LPCTSTR strFilename
)
1957 static TCHAR sBackSlash
[] = {'\\','\0'};
1958 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'};
1959 static TCHAR sStringFileInfo
[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1960 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1961 DWORD dwVersionDataLen
= GetFileVersionInfoSize(strFilename
, NULL
);
1963 if (dwVersionDataLen
) {
1964 dlg
->pVersionData
= HeapAlloc(GetProcessHeap(), 0, dwVersionDataLen
);
1966 if (GetFileVersionInfo(strFilename
, 0, dwVersionDataLen
, dlg
->pVersionData
)) {
1970 if (VerQueryValue(dlg
->pVersionData
, sBackSlash
, &pVal
, &nValLen
)) {
1971 if (nValLen
== sizeof(VS_FIXEDFILEINFO
)) {
1972 VS_FIXEDFILEINFO
* pFixedFileInfo
= (VS_FIXEDFILEINFO
*)pVal
;
1973 char buffer
[BUFFER_LEN
];
1975 sprintf(buffer
, "%d.%d.%d.%d",
1976 HIWORD(pFixedFileInfo
->dwFileVersionMS
), LOWORD(pFixedFileInfo
->dwFileVersionMS
),
1977 HIWORD(pFixedFileInfo
->dwFileVersionLS
), LOWORD(pFixedFileInfo
->dwFileVersionLS
));
1979 SetDlgItemTextA(hwnd
, IDC_STATIC_PROP_VERSION
, buffer
);
1983 /* Read the list of languages and code pages. */
1984 if (VerQueryValue(dlg
->pVersionData
, sTranslation
, &pVal
, &nValLen
)) {
1985 struct LANGANDCODEPAGE
* pTranslate
= (struct LANGANDCODEPAGE
*)pVal
;
1986 struct LANGANDCODEPAGE
* pEnd
= (struct LANGANDCODEPAGE
*)((LPBYTE
)pVal
+nValLen
);
1988 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
1990 /* Read the file description for each language and code page. */
1991 for(; pTranslate
<pEnd
; ++pTranslate
) {
1994 for(p
=InfoStrings
; *p
; ++p
) {
1995 TCHAR subblock
[200];
2002 LPCSTR pInfoString
= *p
;
2004 MultiByteToWideChar(CP_ACP
, 0, pInfoString
, -1, infoStr
, 100);
2006 #define infoStr pInfoString
2008 wsprintf(subblock
, sStringFileInfo
, pTranslate
->wLanguage
, pTranslate
->wCodePage
, infoStr
);
2010 /* Retrieve file description for language and code page */
2011 if (VerQueryValue(dlg
->pVersionData
, subblock
, (PVOID
)&pTxt
, &nValLen
)) {
2012 int idx
= SendMessage(hlbox
, LB_ADDSTRING
, 0L, (LPARAM
)infoStr
);
2013 SendMessage(hlbox
, LB_SETITEMDATA
, idx
, (LPARAM
) pTxt
);
2018 SendMessage(hlbox
, LB_SETCURSEL
, 0, 0);
2020 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
2026 static INT_PTR CALLBACK
PropertiesDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
2028 static struct PropertiesDialog
* dlg
;
2031 case WM_INITDIALOG
: {
2032 static const TCHAR sByteFmt
[] = {'%','s',' ','B','y','t','e','s','\0'};
2033 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2034 LPWIN32_FIND_DATA pWFD
;
2037 dlg
= (struct PropertiesDialog
*) lparam
;
2038 pWFD
= (LPWIN32_FIND_DATA
) &dlg
->entry
.data
;
2040 GetWindowText(hwnd
, b1
, MAX_PATH
);
2041 wsprintf(b2
, b1
, pWFD
->cFileName
);
2042 SetWindowText(hwnd
, b2
);
2044 format_date(&pWFD
->ftLastWriteTime
, b1
, COL_DATE
|COL_TIME
);
2045 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_LASTCHANGE
), b1
);
2047 size
= ((ULONGLONG
)pWFD
->nFileSizeHigh
<< 32) | pWFD
->nFileSizeLow
;
2048 _stprintf(b1
, sLongNumFmt
, size
);
2049 wsprintf(b2
, sByteFmt
, b1
);
2050 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_SIZE
), b2
);
2052 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_FILENAME
), pWFD
->cFileName
);
2053 SetWindowText(GetDlgItem(hwnd
, IDC_STATIC_PROP_PATH
), dlg
->path
);
2055 set_check(hwnd
, IDC_CHECK_READONLY
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_READONLY
);
2056 set_check(hwnd
, IDC_CHECK_ARCHIVE
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_ARCHIVE
);
2057 set_check(hwnd
, IDC_CHECK_COMPRESSED
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_COMPRESSED
);
2058 set_check(hwnd
, IDC_CHECK_HIDDEN
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_HIDDEN
);
2059 set_check(hwnd
, IDC_CHECK_SYSTEM
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_SYSTEM
);
2061 CheckForFileInfo(dlg
, hwnd
, dlg
->path
);
2065 int id
= (int)wparam
;
2067 switch(HIWORD(wparam
)) {
2068 case LBN_SELCHANGE
: {
2069 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
2070 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
2075 if (id
==IDOK
|| id
==IDCANCEL
)
2076 EndDialog(hwnd
, id
);
2082 HeapFree(GetProcessHeap(), 0, dlg
->pVersionData
);
2083 dlg
->pVersionData
= NULL
;
2090 static void show_properties_dlg(Entry
* entry
, HWND hwnd
)
2092 struct PropertiesDialog dlg
;
2094 memset(&dlg
, 0, sizeof(struct PropertiesDialog
));
2095 get_path(entry
, dlg
.path
);
2096 memcpy(&dlg
.entry
, entry
, sizeof(Entry
));
2098 DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_DIALOG_PROPERTIES
), hwnd
, PropertiesDialogDlgProc
, (LPARAM
)&dlg
);
2102 #ifndef _NO_EXTENSIONS
2104 static struct FullScreenParameters
{
2114 static void frame_get_clientspace(HWND hwnd
, PRECT prect
)
2118 if (!IsIconic(hwnd
))
2119 GetClientRect(hwnd
, prect
);
2123 GetWindowPlacement(hwnd
, &wp
);
2125 prect
->left
= prect
->top
= 0;
2126 prect
->right
= wp
.rcNormalPosition
.right
-wp
.rcNormalPosition
.left
-
2127 2*(GetSystemMetrics(SM_CXSIZEFRAME
)+GetSystemMetrics(SM_CXEDGE
));
2128 prect
->bottom
= wp
.rcNormalPosition
.bottom
-wp
.rcNormalPosition
.top
-
2129 2*(GetSystemMetrics(SM_CYSIZEFRAME
)+GetSystemMetrics(SM_CYEDGE
))-
2130 GetSystemMetrics(SM_CYCAPTION
)-GetSystemMetrics(SM_CYMENUSIZE
);
2133 if (IsWindowVisible(Globals
.htoolbar
)) {
2134 GetClientRect(Globals
.htoolbar
, &rt
);
2135 prect
->top
+= rt
.bottom
+2;
2138 if (IsWindowVisible(Globals
.hdrivebar
)) {
2139 GetClientRect(Globals
.hdrivebar
, &rt
);
2140 prect
->top
+= rt
.bottom
+2;
2143 if (IsWindowVisible(Globals
.hstatusbar
)) {
2144 GetClientRect(Globals
.hstatusbar
, &rt
);
2145 prect
->bottom
-= rt
.bottom
;
2149 static BOOL
toggle_fullscreen(HWND hwnd
)
2153 if ((g_fullscreen
.mode
=!g_fullscreen
.mode
)) {
2154 GetWindowRect(hwnd
, &g_fullscreen
.orgPos
);
2155 g_fullscreen
.wasZoomed
= IsZoomed(hwnd
);
2157 Frame_CalcFrameClient(hwnd
, &rt
);
2158 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
2159 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
2161 rt
.left
= g_fullscreen
.orgPos
.left
-rt
.left
;
2162 rt
.top
= g_fullscreen
.orgPos
.top
-rt
.top
;
2163 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+g_fullscreen
.orgPos
.right
-rt
.right
;
2164 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+g_fullscreen
.orgPos
.bottom
-rt
.bottom
;
2166 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
2168 MoveWindow(hwnd
, g_fullscreen
.orgPos
.left
, g_fullscreen
.orgPos
.top
,
2169 g_fullscreen
.orgPos
.right
-g_fullscreen
.orgPos
.left
,
2170 g_fullscreen
.orgPos
.bottom
-g_fullscreen
.orgPos
.top
, TRUE
);
2172 if (g_fullscreen
.wasZoomed
)
2173 ShowWindow(hwnd
, WS_MAXIMIZE
);
2176 return g_fullscreen
.mode
;
2179 static void fullscreen_move(HWND hwnd
)
2182 GetWindowRect(hwnd
, &pos
);
2184 Frame_CalcFrameClient(hwnd
, &rt
);
2185 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
2186 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
2188 rt
.left
= pos
.left
-rt
.left
;
2189 rt
.top
= pos
.top
-rt
.top
;
2190 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+pos
.right
-rt
.right
;
2191 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+pos
.bottom
-rt
.bottom
;
2193 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
2199 static void toggle_child(HWND hwnd
, UINT cmd
, HWND hchild
)
2201 BOOL vis
= IsWindowVisible(hchild
);
2203 CheckMenuItem(Globals
.hMenuOptions
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
2205 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
2207 #ifndef _NO_EXTENSIONS
2208 if (g_fullscreen
.mode
)
2209 fullscreen_move(hwnd
);
2212 resize_frame_client(hwnd
);
2215 static BOOL
activate_drive_window(LPCTSTR path
)
2217 TCHAR drv1
[_MAX_DRIVE
], drv2
[_MAX_DRIVE
];
2220 _tsplitpath(path
, drv1
, 0, 0, 0);
2222 /* search for a already open window for the same drive */
2223 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2224 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(child_wnd
, GWLP_USERDATA
);
2227 _tsplitpath(child
->root
.path
, drv2
, 0, 0, 0);
2229 if (!lstrcmpi(drv2
, drv1
)) {
2230 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2232 if (IsIconic(child_wnd
))
2233 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2243 static BOOL
activate_fs_window(LPCTSTR filesys
)
2247 /* search for a already open window of the given file system name */
2248 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2249 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(child_wnd
, GWLP_USERDATA
);
2252 if (!lstrcmpi(child
->root
.fs
, filesys
)) {
2253 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2255 if (IsIconic(child_wnd
))
2256 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2266 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
2268 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2272 if (Globals
.saveSettings
)
2273 save_registry_settings();
2275 DestroyWindow(hwnd
);
2277 /* clear handle variables */
2278 Globals
.hMenuFrame
= 0;
2279 Globals
.hMenuView
= 0;
2280 Globals
.hMenuOptions
= 0;
2281 Globals
.hMainWnd
= 0;
2282 Globals
.hmdiclient
= 0;
2283 Globals
.hdrivebar
= 0;
2290 case WM_INITMENUPOPUP
: {
2291 HWND hwndClient
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2293 if (!SendMessage(hwndClient
, WM_INITMENUPOPUP
, wparam
, lparam
))
2298 UINT cmd
= LOWORD(wparam
);
2299 HWND hwndClient
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2301 if (SendMessage(hwndClient
, WM_DISPATCH_COMMAND
, wparam
, lparam
))
2304 if (cmd
>=ID_DRIVE_FIRST
&& cmd
<=ID_DRIVE_FIRST
+0xFF) {
2305 TCHAR drv
[_MAX_DRIVE
], path
[MAX_PATH
];
2307 LPCTSTR root
= Globals
.drives
;
2310 for(i
=cmd
-ID_DRIVE_FIRST
; i
--; root
++)
2314 if (activate_drive_window(root
))
2317 _tsplitpath(root
, drv
, 0, 0, 0);
2319 if (!SetCurrentDirectory(drv
)) {
2320 display_error(hwnd
, GetLastError());
2324 GetCurrentDirectory(MAX_PATH
, path
); /*TODO: store last directory per drive */
2325 child
= alloc_child_window(path
, NULL
, hwnd
);
2327 if (!create_child_window(child
))
2328 HeapFree(GetProcessHeap(), 0, child
);
2329 } else switch(cmd
) {
2331 SendMessage(hwnd
, WM_CLOSE
, 0, 0);
2334 case ID_WINDOW_NEW
: {
2335 TCHAR path
[MAX_PATH
];
2338 GetCurrentDirectory(MAX_PATH
, path
);
2339 child
= alloc_child_window(path
, NULL
, hwnd
);
2341 if (!create_child_window(child
))
2342 HeapFree(GetProcessHeap(), 0, child
);
2349 case ID_WINDOW_CASCADE
:
2350 SendMessage(Globals
.hmdiclient
, WM_MDICASCADE
, 0, 0);
2353 case ID_WINDOW_TILE_HORZ
:
2354 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
2357 case ID_WINDOW_TILE_VERT
:
2358 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
2361 case ID_WINDOW_ARRANGE
:
2362 SendMessage(Globals
.hmdiclient
, WM_MDIICONARRANGE
, 0, 0);
2365 case ID_SELECT_FONT
:
2369 case ID_VIEW_TOOL_BAR
:
2370 toggle_child(hwnd
, cmd
, Globals
.htoolbar
);
2373 case ID_VIEW_DRIVE_BAR
:
2374 toggle_child(hwnd
, cmd
, Globals
.hdrivebar
);
2377 case ID_VIEW_STATUSBAR
:
2378 toggle_child(hwnd
, cmd
, Globals
.hstatusbar
);
2381 case ID_VIEW_SAVESETTINGS
:
2382 Globals
.saveSettings
= !Globals
.saveSettings
;
2383 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_SAVESETTINGS
,
2384 Globals
.saveSettings
? MF_CHECKED
: MF_UNCHECKED
);
2388 struct ExecuteDialog dlg
;
2390 memset(&dlg
, 0, sizeof(struct ExecuteDialog
));
2392 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_EXECUTE
), hwnd
, ExecuteDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
2393 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, dlg
.cmd
/*file*/, NULL
/*parameters*/, NULL
/*dir*/, dlg
.cmdshow
);
2395 if (PtrToUlong(hinst
) <= 32)
2396 display_error(hwnd
, GetLastError());
2400 case ID_CONNECT_NETWORK_DRIVE
: {
2401 DWORD ret
= WNetConnectionDialog(hwnd
, RESOURCETYPE_DISK
);
2402 if (ret
== NO_ERROR
)
2404 else if (ret
!= (DWORD
)-1) {
2405 if (ret
== ERROR_EXTENDED_ERROR
)
2406 display_network_error(hwnd
);
2408 display_error(hwnd
, ret
);
2412 case ID_DISCONNECT_NETWORK_DRIVE
: {
2413 DWORD ret
= WNetDisconnectDialog(hwnd
, RESOURCETYPE_DISK
);
2414 if (ret
== NO_ERROR
)
2416 else if (ret
!= (DWORD
)-1) {
2417 if (ret
== ERROR_EXTENDED_ERROR
)
2418 display_network_error(hwnd
);
2420 display_error(hwnd
, ret
);
2424 case ID_FORMAT_DISK
: {
2425 UINT sem_org
= SetErrorMode(0); /* Get the current Error Mode settings. */
2426 SetErrorMode(sem_org
& ~SEM_FAILCRITICALERRORS
); /* Force O/S to handle */
2427 SHFormatDrive(hwnd
, 0 /* A: */, SHFMT_ID_DEFAULT
, 0);
2428 SetErrorMode(sem_org
); /* Put it back the way it was. */
2432 WinHelp(hwnd
, RS(b1
,IDS_WINEFILE
), HELP_INDEX
, 0);
2435 #ifndef _NO_EXTENSIONS
2436 case ID_VIEW_FULLSCREEN
:
2437 CheckMenuItem(Globals
.hMenuOptions
, cmd
, toggle_fullscreen(hwnd
)?MF_CHECKED
:0);
2441 case ID_DRIVE_UNIX_FS
: {
2442 TCHAR path
[MAX_PATH
];
2444 char cpath
[MAX_PATH
];
2448 if (activate_fs_window(RS(b1
,IDS_UNIXFS
)))
2452 getcwd(cpath
, MAX_PATH
);
2453 MultiByteToWideChar(CP_UNIXCP
, 0, cpath
, -1, path
, MAX_PATH
);
2455 getcwd(path
, MAX_PATH
);
2457 child
= alloc_child_window(path
, NULL
, hwnd
);
2459 if (!create_child_window(child
))
2460 HeapFree(GetProcessHeap(), 0, child
);
2463 #ifdef _SHELL_FOLDERS
2464 case ID_DRIVE_SHELL_NS
: {
2465 TCHAR path
[MAX_PATH
];
2468 if (activate_fs_window(RS(b1
,IDS_SHELL
)))
2471 GetCurrentDirectory(MAX_PATH
, path
);
2472 child
= alloc_child_window(path
, get_path_pidl(path
,hwnd
), hwnd
);
2474 if (!create_child_window(child
))
2475 HeapFree(GetProcessHeap(), 0, child
);
2480 /*TODO: There are even more menu items! */
2483 ShellAbout(hwnd
, RS(b1
,IDS_WINEFILE
), NULL
,
2484 LoadImage( Globals
.hInstance
, MAKEINTRESOURCE(IDI_WINEFILE
),
2485 IMAGE_ICON
, 48, 48, LR_SHARED
));
2489 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2490 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2491 else */if ((cmd
<IDW_FIRST_CHILD
|| cmd
>=IDW_FIRST_CHILD
+0x100) &&
2492 (cmd
<SC_SIZE
|| cmd
>SC_RESTORE
))
2493 MessageBox(hwnd
, RS(b2
,IDS_NO_IMPL
), RS(b1
,IDS_WINEFILE
), MB_OK
);
2495 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2500 resize_frame(hwnd
, LOWORD(lparam
), HIWORD(lparam
));
2501 break; /* do not pass message to DefFrameProc */
2503 case WM_DEVICECHANGE
:
2504 SendMessage(hwnd
, WM_COMMAND
, MAKELONG(ID_REFRESH
,0), 0);
2507 #ifndef _NO_EXTENSIONS
2508 case WM_GETMINMAXINFO
: {
2509 LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
2511 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2512 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2515 case FRM_CALC_CLIENT
:
2516 frame_get_clientspace(hwnd
, (PRECT
)lparam
);
2518 #endif /* _NO_EXTENSIONS */
2521 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2528 static TCHAR g_pos_names
[COLUMNS
][20] = {
2532 static const int g_pos_align
[] = {
2534 HDF_LEFT
, /* Name */
2535 HDF_RIGHT
, /* Size */
2536 HDF_LEFT
, /* CDate */
2537 #ifndef _NO_EXTENSIONS
2538 HDF_LEFT
, /* ADate */
2539 HDF_LEFT
, /* MDate */
2540 HDF_LEFT
, /* Index */
2541 HDF_CENTER
, /* Links */
2543 HDF_CENTER
, /* Attributes */
2544 #ifndef _NO_EXTENSIONS
2545 HDF_LEFT
/* Security */
2549 static void resize_tree(ChildWnd
* child
, int cx
, int cy
)
2551 HDWP hdwp
= BeginDeferWindowPos(4);
2559 cx
= child
->split_pos
+ SPLIT_WIDTH
/2;
2561 #ifndef _NO_EXTENSIONS
2569 SendMessage(child
->left
.hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hdl
);
2571 DeferWindowPos(hdwp
, child
->left
.hwndHeader
, wp
.hwndInsertAfter
,
2572 wp
.x
-1, wp
.y
, child
->split_pos
-SPLIT_WIDTH
/2+1, wp
.cy
, wp
.flags
);
2573 DeferWindowPos(hdwp
, child
->right
.hwndHeader
, wp
.hwndInsertAfter
,
2574 rt
.left
+cx
+1, wp
.y
, wp
.cx
-cx
+2, wp
.cy
, wp
.flags
);
2576 #endif /* _NO_EXTENSIONS */
2578 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
);
2579 DeferWindowPos(hdwp
, child
->right
.hwnd
, 0, rt
.left
+cx
+1, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
2581 EndDeferWindowPos(hdwp
);
2585 #ifndef _NO_EXTENSIONS
2587 static HWND
create_header(HWND parent
, Pane
* pane
, UINT id
)
2592 HWND hwnd
= CreateWindow(WC_HEADER
, 0, WS_CHILD
|WS_VISIBLE
|HDS_HORZ
|HDS_FULLDRAG
/*TODO: |HDS_BUTTONS + sort orders*/,
2593 0, 0, 0, 0, parent
, (HMENU
)ULongToHandle(id
), Globals
.hInstance
, 0);
2597 SendMessage(hwnd
, WM_SETFONT
, (WPARAM
)GetStockObject(DEFAULT_GUI_FONT
), FALSE
);
2599 hdi
.mask
= HDI_TEXT
|HDI_WIDTH
|HDI_FORMAT
;
2601 for(idx
=0; idx
<COLUMNS
; idx
++) {
2602 hdi
.pszText
= g_pos_names
[idx
];
2603 hdi
.fmt
= HDF_STRING
| g_pos_align
[idx
];
2604 hdi
.cxy
= pane
->widths
[idx
];
2605 SendMessage(hwnd
, HDM_INSERTITEM
, idx
, (LPARAM
) &hdi
);
2611 #endif /* _NO_EXTENSIONS */
2614 static void init_output(HWND hwnd
)
2616 static const WCHAR s1000
[] = {'1','0','0','0','\0'};
2619 HDC hdc
= GetDC(hwnd
);
2621 if (GetNumberFormatW(LOCALE_USER_DEFAULT
, 0, s1000
, 0, b
, 16) > 4)
2622 Globals
.num_sep
= b
[1];
2624 Globals
.num_sep
= '.';
2626 old_font
= SelectObject(hdc
, Globals
.hfont
);
2627 GetTextExtentPoint32W(hdc
, sSpace
, 1, &Globals
.spaceSize
);
2628 SelectObject(hdc
, old_font
);
2629 ReleaseDC(hwnd
, hdc
);
2632 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
);
2635 /* calculate preferred width for all visible columns */
2637 static BOOL
calc_widths(Pane
* pane
, BOOL anyway
)
2639 int col
, x
, cx
, spc
=3*Globals
.spaceSize
.cx
;
2640 int entries
= SendMessage(pane
->hwnd
, LB_GETCOUNT
, 0, 0);
2641 int orgWidths
[COLUMNS
];
2642 int orgPositions
[COLUMNS
+1];
2648 memcpy(orgWidths
, pane
->widths
, sizeof(orgWidths
));
2649 memcpy(orgPositions
, pane
->positions
, sizeof(orgPositions
));
2652 for(col
=0; col
<COLUMNS
; col
++)
2653 pane
->widths
[col
] = 0;
2655 hdc
= GetDC(pane
->hwnd
);
2656 hfontOld
= SelectObject(hdc
, Globals
.hfont
);
2658 for(cnt
=0; cnt
<entries
; cnt
++) {
2659 Entry
* entry
= (Entry
*) SendMessage(pane
->hwnd
, LB_GETITEMDATA
, cnt
, 0);
2668 dis
.hwndItem
= pane
->hwnd
;
2670 dis
.rcItem
.left
= 0;
2672 dis
.rcItem
.right
= 0;
2673 dis
.rcItem
.bottom
= 0;
2674 /*dis.itemData = 0; */
2676 draw_item(pane
, &dis
, entry
, COLUMNS
);
2679 SelectObject(hdc
, hfontOld
);
2680 ReleaseDC(pane
->hwnd
, hdc
);
2683 for(col
=0; col
<COLUMNS
; col
++) {
2684 pane
->positions
[col
] = x
;
2685 cx
= pane
->widths
[col
];
2690 if (cx
< IMAGE_WIDTH
)
2693 pane
->widths
[col
] = cx
;
2699 pane
->positions
[COLUMNS
] = x
;
2701 SendMessage(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, x
, 0);
2704 if (!anyway
&& !memcmp(orgWidths
, pane
->widths
, sizeof(orgWidths
)))
2707 /* don't move, if only collapsing an entry */
2708 if (!anyway
&& pane
->widths
[0]<orgWidths
[0] &&
2709 !memcmp(orgWidths
+1, pane
->widths
+1, sizeof(orgWidths
)-sizeof(int))) {
2710 pane
->widths
[0] = orgWidths
[0];
2711 memcpy(pane
->positions
, orgPositions
, sizeof(orgPositions
));
2716 InvalidateRect(pane
->hwnd
, 0, TRUE
);
2722 /* calculate one preferred column width */
2724 static void calc_single_width(Pane
* pane
, int col
)
2728 int entries
= SendMessage(pane
->hwnd
, LB_GETCOUNT
, 0, 0);
2732 pane
->widths
[col
] = 0;
2734 hdc
= GetDC(pane
->hwnd
);
2735 hfontOld
= SelectObject(hdc
, Globals
.hfont
);
2737 for(cnt
=0; cnt
<entries
; cnt
++) {
2738 Entry
* entry
= (Entry
*) SendMessage(pane
->hwnd
, LB_GETITEMDATA
, cnt
, 0);
2746 dis
.hwndItem
= pane
->hwnd
;
2748 dis
.rcItem
.left
= 0;
2750 dis
.rcItem
.right
= 0;
2751 dis
.rcItem
.bottom
= 0;
2752 /*dis.itemData = 0; */
2754 draw_item(pane
, &dis
, entry
, col
);
2757 SelectObject(hdc
, hfontOld
);
2758 ReleaseDC(pane
->hwnd
, hdc
);
2760 cx
= pane
->widths
[col
];
2763 cx
+= 3*Globals
.spaceSize
.cx
;
2765 if (cx
< IMAGE_WIDTH
)
2769 pane
->widths
[col
] = cx
;
2771 x
= pane
->positions
[col
] + cx
;
2773 for(; col
<COLUMNS
; ) {
2774 pane
->positions
[++col
] = x
;
2775 x
+= pane
->widths
[col
];
2778 SendMessage(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, x
, 0);
2782 static BOOL
pattern_match(LPCTSTR str
, LPCTSTR pattern
)
2784 for( ; *str
&&*pattern
; str
++,pattern
++) {
2785 if (*pattern
== '*') {
2787 while(*pattern
== '*');
2793 if (*str
==*pattern
&& pattern_match(str
, pattern
))
2798 else if (*str
!=*pattern
&& *pattern
!='?')
2802 if (*str
|| *pattern
)
2803 if (*pattern
!='*' || pattern
[1]!='\0')
2809 static BOOL
pattern_imatch(LPCTSTR str
, LPCTSTR pattern
)
2811 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2814 lstrcpy(b2
, pattern
);
2818 return pattern_match(b1
, b2
);
2828 static enum FILE_TYPE
get_file_type(LPCTSTR filename
);
2831 /* insert listbox entries after index idx */
2833 static int insert_entries(Pane
* pane
, Entry
* dir
, LPCTSTR pattern
, int filter_flags
, int idx
)
2840 ShowWindow(pane
->hwnd
, SW_HIDE
);
2842 for(; entry
; entry
=entry
->next
) {
2844 if (pane
->treePane
&& !(entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
2848 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
2849 /* don't display entries "." and ".." in the left pane */
2850 if (pane
->treePane
&& entry
->data
.cFileName
[0] == '.')
2852 #ifndef _NO_EXTENSIONS
2853 entry
->data
.cFileName
[1] == '\0' ||
2855 (entry
->data
.cFileName
[1] == '.' && entry
->data
.cFileName
[2] == '\0'))
2858 /* filter directories in right pane */
2859 if (!pane
->treePane
&& !(filter_flags
&TF_DIRECTORIES
))
2863 /* filter using the file name pattern */
2865 if (!pattern_imatch(entry
->data
.cFileName
, pattern
))
2868 /* filter system and hidden files */
2869 if (!(filter_flags
&TF_HIDDEN
) && (entry
->data
.dwFileAttributes
&(FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
)))
2872 /* filter looking at the file type */
2873 if ((filter_flags
&(TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
)) != (TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
))
2874 switch(get_file_type(entry
->data
.cFileName
)) {
2876 if (!(filter_flags
& TF_PROGRAMS
))
2881 if (!(filter_flags
& TF_DOCUMENTS
))
2885 default: /* TF_OTHERS */
2886 if (!(filter_flags
& TF_OTHERS
))
2893 SendMessage(pane
->hwnd
, LB_INSERTSTRING
, idx
, (LPARAM
) entry
);
2895 if (pane
->treePane
&& entry
->expanded
)
2896 idx
= insert_entries(pane
, entry
->down
, pattern
, filter_flags
, idx
);
2899 ShowWindow(pane
->hwnd
, SW_SHOW
);
2905 static void format_bytes(LPTSTR buffer
, LONGLONG bytes
)
2907 static const TCHAR sFmtGB
[] = {'%', '.', '1', 'f', ' ', 'G', 'B', '\0'};
2908 static const TCHAR sFmtMB
[] = {'%', '.', '1', 'f', ' ', 'M', 'B', '\0'};
2909 static const TCHAR sFmtkB
[] = {'%', '.', '1', 'f', ' ', 'k', 'B', '\0'};
2911 float fBytes
= (float)bytes
;
2913 if (bytes
>= 1073741824) /* 1 GB */
2914 _stprintf(buffer
, sFmtGB
, fBytes
/1073741824.f
+.5f
);
2915 else if (bytes
>= 1048576) /* 1 MB */
2916 _stprintf(buffer
, sFmtMB
, fBytes
/1048576.f
+.5f
);
2917 else if (bytes
>= 1024) /* 1 kB */
2918 _stprintf(buffer
, sFmtkB
, fBytes
/1024.f
+.5f
);
2920 _stprintf(buffer
, sLongNumFmt
, bytes
);
2923 static void set_space_status(void)
2925 ULARGE_INTEGER ulFreeBytesToCaller
, ulTotalBytes
, ulFreeBytes
;
2926 TCHAR fmt
[64], b1
[64], b2
[64], buffer
[BUFFER_LEN
];
2928 if (GetDiskFreeSpaceEx(NULL
, &ulFreeBytesToCaller
, &ulTotalBytes
, &ulFreeBytes
)) {
2929 format_bytes(b1
, ulFreeBytesToCaller
.QuadPart
);
2930 format_bytes(b2
, ulTotalBytes
.QuadPart
);
2931 wsprintf(buffer
, RS(fmt
,IDS_FREE_SPACE_FMT
), b1
, b2
);
2933 lstrcpy(buffer
, sQMarks
);
2935 SendMessage(Globals
.hstatusbar
, SB_SETTEXT
, 0, (LPARAM
)buffer
);
2939 static WNDPROC g_orgTreeWndProc
;
2941 static void create_tree_window(HWND parent
, Pane
* pane
, UINT id
, UINT id_header
, LPCTSTR pattern
, int filter_flags
)
2943 static const TCHAR sListBox
[] = {'L','i','s','t','B','o','x','\0'};
2945 static int s_init
= 0;
2946 Entry
* entry
= pane
->root
;
2948 pane
->hwnd
= CreateWindow(sListBox
, sEmpty
, WS_CHILD
|WS_VISIBLE
|WS_HSCROLL
|WS_VSCROLL
|
2949 LBS_DISABLENOSCROLL
|LBS_NOINTEGRALHEIGHT
|LBS_OWNERDRAWFIXED
|LBS_NOTIFY
,
2950 0, 0, 0, 0, parent
, (HMENU
)ULongToHandle(id
), Globals
.hInstance
, 0);
2952 SetWindowLongPtr(pane
->hwnd
, GWLP_USERDATA
, (LPARAM
)pane
);
2953 g_orgTreeWndProc
= (WNDPROC
) SetWindowLongPtr(pane
->hwnd
, GWLP_WNDPROC
, (LPARAM
)TreeWndProc
);
2955 SendMessage(pane
->hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, FALSE
);
2957 /* insert entries into listbox */
2959 insert_entries(pane
, entry
, pattern
, filter_flags
, -1);
2961 /* calculate column widths */
2964 init_output(pane
->hwnd
);
2967 calc_widths(pane
, TRUE
);
2969 #ifndef _NO_EXTENSIONS
2970 pane
->hwndHeader
= create_header(parent
, pane
, id_header
);
2975 static void InitChildWindow(ChildWnd
* child
)
2977 create_tree_window(child
->hwnd
, &child
->left
, IDW_TREE_LEFT
, IDW_HEADER_LEFT
, NULL
, TF_ALL
);
2978 create_tree_window(child
->hwnd
, &child
->right
, IDW_TREE_RIGHT
, IDW_HEADER_RIGHT
, child
->filter_pattern
, child
->filter_flags
);
2982 static void format_date(const FILETIME
* ft
, TCHAR
* buffer
, int visible_cols
)
2990 if (!ft
->dwLowDateTime
&& !ft
->dwHighDateTime
)
2993 if (!FileTimeToLocalFileTime(ft
, &lft
))
2994 {err
: lstrcpy(buffer
,sQMarks
); return;}
2996 if (!FileTimeToSystemTime(&lft
, &systime
))
2999 if (visible_cols
& COL_DATE
) {
3000 len
= GetDateFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
, BUFFER_LEN
);
3005 if (visible_cols
& COL_TIME
) {
3007 buffer
[len
-1] = ' ';
3009 buffer
[len
++] = ' ';
3011 if (!GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
+len
, BUFFER_LEN
-len
))
3017 static void calc_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3019 RECT rt
= {0, 0, 0, 0};
3021 DrawText(dis
->hDC
, str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
3023 if (rt
.right
> pane
->widths
[col
])
3024 pane
->widths
[col
] = rt
.right
;
3027 static void calc_tabbed_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3029 RECT rt
= {0, 0, 0, 0};
3031 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
3032 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
3034 DrawText(dis
->hDC
, str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
3035 /*FIXME rt (0,0) ??? */
3037 if (rt
.right
> pane
->widths
[col
])
3038 pane
->widths
[col
] = rt
.right
;
3042 static void output_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
, DWORD flags
)
3044 int x
= dis
->rcItem
.left
;
3047 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
3048 rt
.top
= dis
->rcItem
.top
;
3049 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
3050 rt
.bottom
= dis
->rcItem
.bottom
;
3052 DrawText(dis
->hDC
, str
, -1, &rt
, DT_SINGLELINE
|DT_NOPREFIX
|flags
);
3055 static void output_tabbed_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3057 int x
= dis
->rcItem
.left
;
3060 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
3061 rt
.top
= dis
->rcItem
.top
;
3062 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
3063 rt
.bottom
= dis
->rcItem
.bottom
;
3065 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
3066 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
3068 DrawText(dis
->hDC
, str
, -1, &rt
, DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
3071 static void output_number(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
3073 int x
= dis
->rcItem
.left
;
3080 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
3081 rt
.top
= dis
->rcItem
.top
;
3082 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
3083 rt
.bottom
= dis
->rcItem
.bottom
;
3088 /* insert number separator characters */
3089 pos
= lstrlen(s
) % 3;
3095 *d
++ = Globals
.num_sep
;
3099 DrawText(dis
->hDC
, b
, d
-b
, &rt
, DT_RIGHT
|DT_SINGLELINE
|DT_NOPREFIX
|DT_END_ELLIPSIS
);
3103 static BOOL
is_exe_file(LPCTSTR ext
)
3105 static const TCHAR executable_extensions
[][4] = {
3110 #ifndef _NO_EXTENSIONS
3114 #endif /* _NO_EXTENSIONS */
3118 TCHAR ext_buffer
[_MAX_EXT
];
3119 const TCHAR (*p
)[4];
3123 for(s
=ext
+1,d
=ext_buffer
; (*d
=tolower(*s
)); s
++)
3126 for(p
=executable_extensions
; (*p
)[0]; p
++)
3127 if (!lstrcmpi(ext_buffer
, *p
))
3133 static BOOL
is_registered_type(LPCTSTR ext
)
3135 /* check if there exists a classname for this file extension in the registry */
3136 if (!RegQueryValue(HKEY_CLASSES_ROOT
, ext
, NULL
, NULL
))
3142 static enum FILE_TYPE
get_file_type(LPCTSTR filename
)
3144 LPCTSTR ext
= _tcsrchr(filename
, '.');
3148 if (is_exe_file(ext
))
3149 return FT_EXECUTABLE
;
3150 else if (is_registered_type(ext
))
3157 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
)
3159 TCHAR buffer
[BUFFER_LEN
];
3161 int visible_cols
= pane
->visible_cols
;
3162 COLORREF bkcolor
, textcolor
;
3163 RECT focusRect
= dis
->rcItem
;
3170 attrs
= entry
->data
.dwFileAttributes
;
3172 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) {
3173 if (entry
->data
.cFileName
[0] == '.' && entry
->data
.cFileName
[1] == '.'
3174 && entry
->data
.cFileName
[2] == '\0')
3175 img
= IMG_FOLDER_UP
;
3176 #ifndef _NO_EXTENSIONS
3177 else if (entry
->data
.cFileName
[0] == '.' && entry
->data
.cFileName
[1] == '\0')
3178 img
= IMG_FOLDER_CUR
;
3181 #ifdef _NO_EXTENSIONS
3184 (pane
->treePane
&& (dis
->itemState
&ODS_FOCUS
)))
3185 img
= IMG_OPEN_FOLDER
;
3189 switch(get_file_type(entry
->data
.cFileName
)) {
3190 case FT_EXECUTABLE
: img
= IMG_EXECUTABLE
; break;
3191 case FT_DOCUMENT
: img
= IMG_DOCUMENT
; break;
3192 default: img
= IMG_FILE
;
3200 if (pane
->treePane
) {
3202 img_pos
= dis
->rcItem
.left
+ entry
->level
*(IMAGE_WIDTH
+TREE_LINE_DX
);
3204 if (calcWidthCol
== -1) {
3206 int y
= dis
->rcItem
.top
+ IMAGE_HEIGHT
/2;
3209 HRGN hrgn_org
= CreateRectRgn(0, 0, 0, 0);
3212 rt_clip
.left
= dis
->rcItem
.left
;
3213 rt_clip
.top
= dis
->rcItem
.top
;
3214 rt_clip
.right
= dis
->rcItem
.left
+pane
->widths
[col
];
3215 rt_clip
.bottom
= dis
->rcItem
.bottom
;
3217 hrgn
= CreateRectRgnIndirect(&rt_clip
);
3219 if (!GetClipRgn(dis
->hDC
, hrgn_org
)) {
3220 DeleteObject(hrgn_org
);
3224 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
3225 ExtSelectClipRgn(dis
->hDC
, hrgn
, RGN_AND
);
3228 if ((up
=entry
->up
) != NULL
) {
3229 MoveToEx(dis
->hDC
, img_pos
-IMAGE_WIDTH
/2, y
, 0);
3230 LineTo(dis
->hDC
, img_pos
-2, y
);
3232 x
= img_pos
- IMAGE_WIDTH
/2;
3235 x
-= IMAGE_WIDTH
+TREE_LINE_DX
;
3239 && (up
->next
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
3242 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
3243 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
3245 } while((up
=up
->up
) != NULL
);
3248 x
= img_pos
- IMAGE_WIDTH
/2;
3250 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
3251 LineTo(dis
->hDC
, x
, y
);
3255 && (entry
->next
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
)
3258 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
3260 SelectClipRgn(dis
->hDC
, hrgn_org
);
3261 if (hrgn_org
) DeleteObject(hrgn_org
);
3262 /* SelectObject(dis->hDC, holdPen); */
3263 } else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
) {
3264 int right
= img_pos
+ IMAGE_WIDTH
- TREE_LINE_DX
;
3266 if (right
> pane
->widths
[col
])
3267 pane
->widths
[col
] = right
;
3270 img_pos
= dis
->rcItem
.left
;
3273 img_pos
= dis
->rcItem
.left
;
3275 if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3276 pane
->widths
[col
] = IMAGE_WIDTH
;
3279 if (calcWidthCol
== -1) {
3280 focusRect
.left
= img_pos
-2;
3282 #ifdef _NO_EXTENSIONS
3283 if (pane
->treePane
&& entry
) {
3286 DrawText(dis
->hDC
, entry
->data
.cFileName
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
3288 focusRect
.right
= dis
->rcItem
.left
+pane
->positions
[col
+1]+TREE_LINE_DX
+ rt
.right
+2;
3292 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
)
3293 textcolor
= COLOR_COMPRESSED
;
3295 #endif /* _NO_EXTENSIONS */
3296 textcolor
= RGB(0,0,0);
3298 if (dis
->itemState
& ODS_FOCUS
) {
3299 textcolor
= RGB(255,255,255);
3300 bkcolor
= COLOR_SELECTION
;
3302 bkcolor
= RGB(255,255,255);
3305 hbrush
= CreateSolidBrush(bkcolor
);
3306 FillRect(dis
->hDC
, &focusRect
, hbrush
);
3307 DeleteObject(hbrush
);
3309 SetBkMode(dis
->hDC
, TRANSPARENT
);
3310 SetTextColor(dis
->hDC
, textcolor
);
3312 cx
= pane
->widths
[col
];
3314 if (cx
&& img
!=IMG_NONE
) {
3315 if (cx
> IMAGE_WIDTH
)
3318 #ifdef _SHELL_FOLDERS
3319 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
3320 DrawIconEx(dis
->hDC
, img_pos
, dis
->rcItem
.top
, entry
->hicon
, cx
, GetSystemMetrics(SM_CYSMICON
), 0, 0, DI_NORMAL
);
3323 ImageList_DrawEx(Globals
.himl
, img
, dis
->hDC
,
3324 img_pos
, dis
->rcItem
.top
, cx
,
3325 IMAGE_HEIGHT
, bkcolor
, CLR_DEFAULT
, ILD_NORMAL
);
3332 #ifdef _NO_EXTENSIONS
3333 if (img
>= IMG_FOLDER_UP
)
3339 /* ouput file name */
3340 if (calcWidthCol
== -1)
3341 output_text(pane
, dis
, col
, entry
->data
.cFileName
, 0);
3342 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3343 calc_width(pane
, dis
, col
, entry
->data
.cFileName
);
3347 #ifdef _NO_EXTENSIONS
3348 if (!pane
->treePane
) {
3351 /* display file size */
3352 if (visible_cols
& COL_SIZE
) {
3353 #ifdef _NO_EXTENSIONS
3354 if (!(attrs
&FILE_ATTRIBUTE_DIRECTORY
))
3359 size
= ((ULONGLONG
)entry
->data
.nFileSizeHigh
<< 32) | entry
->data
.nFileSizeLow
;
3361 _stprintf(buffer
, sLongNumFmt
, size
);
3363 if (calcWidthCol
== -1)
3364 output_number(pane
, dis
, col
, buffer
);
3365 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3366 calc_width(pane
, dis
, col
, buffer
);/*TODO: not ever time enough */
3372 /* display file date */
3373 if (visible_cols
& (COL_DATE
|COL_TIME
)) {
3374 #ifndef _NO_EXTENSIONS
3375 format_date(&entry
->data
.ftCreationTime
, buffer
, visible_cols
);
3376 if (calcWidthCol
== -1)
3377 output_text(pane
, dis
, col
, buffer
, 0);
3378 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3379 calc_width(pane
, dis
, col
, buffer
);
3382 format_date(&entry
->data
.ftLastAccessTime
, buffer
, visible_cols
);
3383 if (calcWidthCol
== -1)
3384 output_text(pane
, dis
, col
, buffer
, 0);
3385 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3386 calc_width(pane
, dis
, col
, buffer
);
3388 #endif /* _NO_EXTENSIONS */
3390 format_date(&entry
->data
.ftLastWriteTime
, buffer
, visible_cols
);
3391 if (calcWidthCol
== -1)
3392 output_text(pane
, dis
, col
, buffer
, 0);
3393 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3394 calc_width(pane
, dis
, col
, buffer
);
3398 #ifndef _NO_EXTENSIONS
3399 if (entry
->bhfi_valid
) {
3400 ULONGLONG index
= ((ULONGLONG
)entry
->bhfi
.nFileIndexHigh
<< 32) | entry
->bhfi
.nFileIndexLow
;
3402 if (visible_cols
& COL_INDEX
) {
3403 _stprintf(buffer
, sLongHexFmt
, index
);
3405 if (calcWidthCol
== -1)
3406 output_text(pane
, dis
, col
, buffer
, DT_RIGHT
);
3407 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3408 calc_width(pane
, dis
, col
, buffer
);
3413 if (visible_cols
& COL_LINKS
) {
3414 wsprintf(buffer
, sNumFmt
, entry
->bhfi
.nNumberOfLinks
);
3416 if (calcWidthCol
== -1)
3417 output_text(pane
, dis
, col
, buffer
, DT_CENTER
);
3418 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3419 calc_width(pane
, dis
, col
, buffer
);
3425 #endif /* _NO_EXTENSIONS */
3427 /* show file attributes */
3428 if (visible_cols
& COL_ATTRIBUTES
) {
3429 #ifdef _NO_EXTENSIONS
3430 static const TCHAR s4Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3431 lstrcpy(buffer
, s4Tabs
);
3433 static const TCHAR s11Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3434 lstrcpy(buffer
, s11Tabs
);
3437 if (attrs
& FILE_ATTRIBUTE_NORMAL
) buffer
[ 0] = 'N';
3439 if (attrs
& FILE_ATTRIBUTE_READONLY
) buffer
[ 2] = 'R';
3440 if (attrs
& FILE_ATTRIBUTE_HIDDEN
) buffer
[ 4] = 'H';
3441 if (attrs
& FILE_ATTRIBUTE_SYSTEM
) buffer
[ 6] = 'S';
3442 if (attrs
& FILE_ATTRIBUTE_ARCHIVE
) buffer
[ 8] = 'A';
3443 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
) buffer
[10] = 'C';
3444 #ifndef _NO_EXTENSIONS
3445 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) buffer
[12] = 'D';
3446 if (attrs
& FILE_ATTRIBUTE_ENCRYPTED
) buffer
[14] = 'E';
3447 if (attrs
& FILE_ATTRIBUTE_TEMPORARY
) buffer
[16] = 'T';
3448 if (attrs
& FILE_ATTRIBUTE_SPARSE_FILE
) buffer
[18] = 'P';
3449 if (attrs
& FILE_ATTRIBUTE_REPARSE_POINT
) buffer
[20] = 'Q';
3450 if (attrs
& FILE_ATTRIBUTE_OFFLINE
) buffer
[22] = 'O';
3451 if (attrs
& FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
) buffer
[24] = 'X';
3452 #endif /* _NO_EXTENSIONS */
3455 if (calcWidthCol
== -1)
3456 output_tabbed_text(pane
, dis
, col
, buffer
);
3457 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3458 calc_tabbed_width(pane
, dis
, col
, buffer
);
3464 if (flags.security) {
3465 static const TCHAR sSecTabs[] = {
3466 ' ','\t',' ','\t',' ','\t',' ',
3468 ' ','\t',' ','\t',' ','\t',' ',
3470 ' ','\t',' ','\t',' ','\t',' ',
3474 DWORD rights = get_access_mask();
3476 lstrcpy(buffer, sSecTabs);
3478 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
3479 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
3480 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
3481 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
3482 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
3483 if (rights & FILE_EXECUTE) buffer[12] = 'X';
3484 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
3485 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
3486 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
3487 if (rights & WRITE_DAC) buffer[22] = 'C';
3488 if (rights & WRITE_OWNER) buffer[24] = 'O';
3489 if (rights & SYNCHRONIZE) buffer[26] = 'S';
3491 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
3494 if (flags.description) {
3495 get_description(buffer);
3496 output_text(dis, col++, buffer, 0, psize);
3500 #ifdef _NO_EXTENSIONS
3503 /* draw focus frame */
3504 if ((dis
->itemState
&ODS_FOCUS
) && calcWidthCol
==-1) {
3505 /* Currently [04/2000] Wine neither behaves exactly the same */
3506 /* way as WIN 95 nor like Windows NT... */
3511 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
3512 LOGBRUSH lb
= {PS_SOLID
, RGB(255,255,255)};
3513 hpen
= ExtCreatePen(PS_COSMETIC
|PS_ALTERNATE
, 1, &lb
, 0, 0);
3515 hpen
= CreatePen(PS_DOT
, 0, RGB(255,255,255));
3517 lastPen
= SelectPen(dis
->hDC
, hpen
);
3518 lastBrush
= SelectObject(dis
->hDC
, GetStockObject(HOLLOW_BRUSH
));
3519 SetROP2(dis
->hDC
, R2_XORPEN
);
3520 Rectangle(dis
->hDC
, focusRect
.left
, focusRect
.top
, focusRect
.right
, focusRect
.bottom
);
3521 SelectObject(dis
->hDC
, lastBrush
);
3522 SelectObject(dis
->hDC
, lastPen
);
3525 #endif /* _NO_EXTENSIONS */
3529 #ifdef _NO_EXTENSIONS
3531 static void draw_splitbar(HWND hwnd
, int x
)
3534 HDC hdc
= GetDC(hwnd
);
3536 GetClientRect(hwnd
, &rt
);
3538 rt
.left
= x
- SPLIT_WIDTH
/2;
3539 rt
.right
= x
+ SPLIT_WIDTH
/2+1;
3541 InvertRect(hdc
, &rt
);
3543 ReleaseDC(hwnd
, hdc
);
3546 #endif /* _NO_EXTENSIONS */
3549 #ifndef _NO_EXTENSIONS
3551 static void set_header(Pane
* pane
)
3554 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3557 item
.mask
= HDI_WIDTH
;
3560 for(; x
+pane
->widths
[i
]<scroll_pos
&& i
<COLUMNS
; i
++) {
3561 x
+= pane
->widths
[i
];
3562 SendMessage(pane
->hwndHeader
, HDM_SETITEM
, i
, (LPARAM
) &item
);
3566 x
+= pane
->widths
[i
];
3567 item
.cxy
= x
- scroll_pos
;
3568 SendMessage(pane
->hwndHeader
, HDM_SETITEM
, i
++, (LPARAM
) &item
);
3570 for(; i
<COLUMNS
; i
++) {
3571 item
.cxy
= pane
->widths
[i
];
3572 x
+= pane
->widths
[i
];
3573 SendMessage(pane
->hwndHeader
, HDM_SETITEM
, i
, (LPARAM
) &item
);
3578 static LRESULT
pane_notify(Pane
* pane
, NMHDR
* pnmh
)
3580 switch(pnmh
->code
) {
3581 case HDN_ITEMCHANGED
: {
3582 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3583 int idx
= phdn
->iItem
;
3584 int dx
= phdn
->pitem
->cxy
- pane
->widths
[idx
];
3588 GetClientRect(pane
->hwnd
, &clnt
);
3590 pane
->widths
[idx
] += dx
;
3592 for(i
=idx
; ++i
<=COLUMNS
; )
3593 pane
->positions
[i
] += dx
;
3596 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3600 rt_scr
.left
= pane
->positions
[idx
+1]-scroll_pos
;
3602 rt_scr
.right
= clnt
.right
;
3603 rt_scr
.bottom
= clnt
.bottom
;
3605 rt_clip
.left
= pane
->positions
[idx
]-scroll_pos
;
3607 rt_clip
.right
= clnt
.right
;
3608 rt_clip
.bottom
= clnt
.bottom
;
3610 if (rt_scr
.left
< 0) rt_scr
.left
= 0;
3611 if (rt_clip
.left
< 0) rt_clip
.left
= 0;
3613 ScrollWindowEx(pane
->hwnd
, dx
, 0, &rt_scr
, &rt_clip
, 0, 0, SW_INVALIDATE
);
3615 rt_clip
.right
= pane
->positions
[idx
+1];
3616 RedrawWindow(pane
->hwnd
, &rt_clip
, 0, RDW_INVALIDATE
|RDW_UPDATENOW
);
3618 if (pnmh
->code
== HDN_ENDTRACK
) {
3619 SendMessage(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, pane
->positions
[COLUMNS
], 0);
3621 if (GetScrollPos(pane
->hwnd
, SB_HORZ
) != scroll_pos
)
3629 case HDN_DIVIDERDBLCLICK
: {
3630 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3633 calc_single_width(pane
, phdn
->iItem
);
3634 item
.mask
= HDI_WIDTH
;
3635 item
.cxy
= pane
->widths
[phdn
->iItem
];
3637 SendMessage(pane
->hwndHeader
, HDM_SETITEM
, phdn
->iItem
, (LPARAM
) &item
);
3638 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3645 #endif /* _NO_EXTENSIONS */
3648 static void scan_entry(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3650 TCHAR path
[MAX_PATH
];
3651 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
3653 /* delete sub entries in left pane */
3655 LRESULT res
= SendMessage(child
->left
.hwnd
, LB_GETITEMDATA
, idx
+1, 0);
3656 Entry
* sub
= (Entry
*) res
;
3658 if (res
==LB_ERR
|| !sub
|| sub
->level
<=entry
->level
)
3661 SendMessage(child
->left
.hwnd
, LB_DELETESTRING
, idx
+1, 0);
3664 /* empty right pane */
3665 SendMessage(child
->right
.hwnd
, LB_RESETCONTENT
, 0, 0);
3667 /* release memory */
3668 free_entries(entry
);
3670 /* read contents from disk */
3671 #ifdef _SHELL_FOLDERS
3672 if (entry
->etype
== ET_SHELL
)
3674 read_directory(entry
, NULL
, child
->sortOrder
, hwnd
);
3679 get_path(entry
, path
);
3680 read_directory(entry
, path
, child
->sortOrder
, hwnd
);
3683 /* insert found entries in right pane */
3684 insert_entries(&child
->right
, entry
->down
, child
->filter_pattern
, child
->filter_flags
, -1);
3685 calc_widths(&child
->right
, FALSE
);
3686 #ifndef _NO_EXTENSIONS
3687 set_header(&child
->right
);
3690 child
->header_wdths_ok
= FALSE
;
3692 SetCursor(old_cursor
);
3696 /* expand a directory entry */
3698 static BOOL
expand_entry(ChildWnd
* child
, Entry
* dir
)
3703 if (!dir
|| dir
->expanded
|| !dir
->down
)
3708 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='\0' && p
->next
) {
3711 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='.' &&
3712 p
->data
.cFileName
[2]=='\0' && p
->next
)
3716 /* no subdirectories ? */
3717 if (!(p
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
3720 idx
= SendMessage(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)dir
);
3722 dir
->expanded
= TRUE
;
3724 /* insert entries in left pane */
3725 insert_entries(&child
->left
, p
, NULL
, TF_ALL
, idx
);
3727 if (!child
->header_wdths_ok
) {
3728 if (calc_widths(&child
->left
, FALSE
)) {
3729 #ifndef _NO_EXTENSIONS
3730 set_header(&child
->left
);
3733 child
->header_wdths_ok
= TRUE
;
3741 static void collapse_entry(Pane
* pane
, Entry
* dir
)
3743 int idx
= SendMessage(pane
->hwnd
, LB_FINDSTRING
, 0, (LPARAM
)dir
);
3745 ShowWindow(pane
->hwnd
, SW_HIDE
);
3747 /* hide sub entries */
3749 LRESULT res
= SendMessage(pane
->hwnd
, LB_GETITEMDATA
, idx
+1, 0);
3750 Entry
* sub
= (Entry
*) res
;
3752 if (res
==LB_ERR
|| !sub
|| sub
->level
<=dir
->level
)
3755 SendMessage(pane
->hwnd
, LB_DELETESTRING
, idx
+1, 0);
3758 dir
->expanded
= FALSE
;
3760 ShowWindow(pane
->hwnd
, SW_SHOW
);
3764 static void refresh_right_pane(ChildWnd
* child
)
3766 SendMessage(child
->right
.hwnd
, LB_RESETCONTENT
, 0, 0);
3767 insert_entries(&child
->right
, child
->right
.root
, child
->filter_pattern
, child
->filter_flags
, -1);
3768 calc_widths(&child
->right
, FALSE
);
3770 #ifndef _NO_EXTENSIONS
3771 set_header(&child
->right
);
3775 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3777 TCHAR path
[MAX_PATH
];
3784 child
->left
.cur
= entry
;
3786 child
->right
.root
= entry
->down
? entry
->down
: entry
;
3787 child
->right
.cur
= entry
;
3789 if (!entry
->scanned
)
3790 scan_entry(child
, entry
, idx
, hwnd
);
3792 refresh_right_pane(child
);
3794 get_path(entry
, path
);
3795 lstrcpy(child
->path
, path
);
3797 if (child
->hwnd
) /* only change window title, if the window already exists */
3798 SetWindowText(child
->hwnd
, path
);
3801 if (SetCurrentDirectory(path
))
3806 static void refresh_child(ChildWnd
* child
)
3808 TCHAR path
[MAX_PATH
], drv
[_MAX_DRIVE
+1];
3812 get_path(child
->left
.cur
, path
);
3813 _tsplitpath(path
, drv
, NULL
, NULL
, NULL
);
3815 child
->right
.root
= NULL
;
3817 scan_entry(child
, &child
->root
.entry
, 0, child
->hwnd
);
3819 #ifdef _SHELL_FOLDERS
3820 if (child
->root
.entry
.etype
== ET_SHELL
)
3821 entry
= read_tree(&child
->root
, NULL
, get_path_pidl(path
,child
->hwnd
), drv
, child
->sortOrder
, child
->hwnd
);
3824 entry
= read_tree(&child
->root
, path
, NULL
, drv
, child
->sortOrder
, child
->hwnd
);
3827 entry
= &child
->root
.entry
;
3829 insert_entries(&child
->left
, child
->root
.entry
.down
, NULL
, TF_ALL
, 0);
3831 set_curdir(child
, entry
, 0, child
->hwnd
);
3833 idx
= SendMessage(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)child
->left
.cur
);
3834 SendMessage(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
3838 static void create_drive_bar(void)
3840 TBBUTTON drivebarBtn
= {0, 0, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0};
3841 #ifndef _NO_EXTENSIONS
3842 TCHAR b1
[BUFFER_LEN
];
3847 GetLogicalDriveStrings(BUFFER_LEN
, Globals
.drives
);
3849 Globals
.hdrivebar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
,
3850 IDW_DRIVEBAR
, 2, Globals
.hInstance
, IDB_DRIVEBAR
, &drivebarBtn
,
3851 0, 16, 13, 16, 13, sizeof(TBBUTTON
));
3853 #ifndef _NO_EXTENSIONS
3855 /* insert unix file system button */
3859 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
3861 drivebarBtn
.idCommand
= ID_DRIVE_UNIX_FS
;
3862 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3863 drivebarBtn
.iString
++;
3865 #ifdef _SHELL_FOLDERS
3866 /* insert shell namespace button */
3867 load_string(b1
, sizeof(b1
)/sizeof(b1
[0]), IDS_SHELL
);
3868 b1
[lstrlen(b1
)+1] = '\0';
3869 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
3871 drivebarBtn
.idCommand
= ID_DRIVE_SHELL_NS
;
3872 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3873 drivebarBtn
.iString
++;
3876 /* register windows drive root strings */
3877 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)Globals
.drives
);
3880 drivebarBtn
.idCommand
= ID_DRIVE_FIRST
;
3882 for(p
=Globals
.drives
; *p
; ) {
3883 #ifdef _NO_EXTENSIONS
3884 /* insert drive letter */
3885 TCHAR b
[3] = {tolower(*p
)};
3886 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b
);
3888 switch(GetDriveType(p
)) {
3889 case DRIVE_REMOVABLE
: drivebarBtn
.iBitmap
= 1; break;
3890 case DRIVE_CDROM
: drivebarBtn
.iBitmap
= 3; break;
3891 case DRIVE_REMOTE
: drivebarBtn
.iBitmap
= 4; break;
3892 case DRIVE_RAMDISK
: drivebarBtn
.iBitmap
= 5; break;
3893 default:/*DRIVE_FIXED*/ drivebarBtn
.iBitmap
= 2;
3896 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3897 drivebarBtn
.idCommand
++;
3898 drivebarBtn
.iString
++;
3904 static void refresh_drives(void)
3908 /* destroy drive bar */
3909 DestroyWindow(Globals
.hdrivebar
);
3910 Globals
.hdrivebar
= 0;
3912 /* re-create drive bar */
3915 /* update window layout */
3916 GetClientRect(Globals
.hMainWnd
, &rect
);
3917 SendMessage(Globals
.hMainWnd
, WM_SIZE
, 0, MAKELONG(rect
.right
, rect
.bottom
));
3921 static BOOL
launch_file(HWND hwnd
, LPCTSTR cmd
, UINT nCmdShow
)
3923 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3925 if (PtrToUlong(hinst
) <= 32) {
3926 display_error(hwnd
, GetLastError());
3934 static BOOL
launch_entry(Entry
* entry
, HWND hwnd
, UINT nCmdShow
)
3936 TCHAR cmd
[MAX_PATH
];
3938 #ifdef _SHELL_FOLDERS
3939 if (entry
->etype
== ET_SHELL
) {
3942 SHELLEXECUTEINFO shexinfo
;
3944 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFO
);
3945 shexinfo
.fMask
= SEE_MASK_IDLIST
;
3946 shexinfo
.hwnd
= hwnd
;
3947 shexinfo
.lpVerb
= NULL
;
3948 shexinfo
.lpFile
= NULL
;
3949 shexinfo
.lpParameters
= NULL
;
3950 shexinfo
.lpDirectory
= NULL
;
3951 shexinfo
.nShow
= nCmdShow
;
3952 shexinfo
.lpIDList
= get_to_absolute_pidl(entry
, hwnd
);
3954 if (!ShellExecuteEx(&shexinfo
)) {
3955 display_error(hwnd
, GetLastError());
3959 if (shexinfo
.lpIDList
!= entry
->pidl
)
3960 IMalloc_Free(Globals
.iMalloc
, shexinfo
.lpIDList
);
3966 get_path(entry
, cmd
);
3968 /* start program, open document... */
3969 return launch_file(hwnd
, cmd
, nCmdShow
);
3973 static void activate_entry(ChildWnd
* child
, Pane
* pane
, HWND hwnd
)
3975 Entry
* entry
= pane
->cur
;
3980 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
3981 int scanned_old
= entry
->scanned
;
3985 int idx
= SendMessage(child
->left
.hwnd
, LB_GETCURSEL
, 0, 0);
3986 scan_entry(child
, entry
, idx
, hwnd
);
3989 #ifndef _NO_EXTENSIONS
3990 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='\0')
3994 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='.' && entry
->data
.cFileName
[2]=='\0') {
3995 entry
= child
->left
.cur
->up
;
3996 collapse_entry(&child
->left
, entry
);
3998 } else if (entry
->expanded
)
3999 collapse_entry(pane
, child
->left
.cur
);
4001 expand_entry(child
, child
->left
.cur
);
4003 if (!pane
->treePane
) focus_entry
: {
4004 int idxstart
= SendMessage(child
->left
.hwnd
, LB_GETCURSEL
, 0, 0);
4005 int idx
= SendMessage(child
->left
.hwnd
, LB_FINDSTRING
, idxstart
, (LPARAM
)entry
);
4006 SendMessage(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
4007 set_curdir(child
, entry
, idx
, hwnd
);
4012 calc_widths(pane
, FALSE
);
4014 #ifndef _NO_EXTENSIONS
4019 if (GetKeyState(VK_MENU
) < 0)
4020 show_properties_dlg(entry
, child
->hwnd
);
4022 launch_entry(entry
, child
->hwnd
, SW_SHOWNORMAL
);
4027 static BOOL
pane_command(Pane
* pane
, UINT cmd
)
4031 if (pane
->visible_cols
) {
4032 pane
->visible_cols
= 0;
4033 calc_widths(pane
, TRUE
);
4034 #ifndef _NO_EXTENSIONS
4037 InvalidateRect(pane
->hwnd
, 0, TRUE
);
4038 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
|MF_CHECKED
);
4039 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
);
4040 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
4044 case ID_VIEW_ALL_ATTRIBUTES
:
4045 if (pane
->visible_cols
!= COL_ALL
) {
4046 pane
->visible_cols
= COL_ALL
;
4047 calc_widths(pane
, TRUE
);
4048 #ifndef _NO_EXTENSIONS
4051 InvalidateRect(pane
->hwnd
, 0, TRUE
);
4052 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
);
4053 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
|MF_CHECKED
);
4054 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
4058 #ifndef _NO_EXTENSIONS
4059 case ID_PREFERRED_SIZES
: {
4060 calc_widths(pane
, TRUE
);
4062 InvalidateRect(pane
->hwnd
, 0, TRUE
);
4066 /* TODO: more command ids... */
4076 static void set_sort_order(ChildWnd
* child
, SORT_ORDER sortOrder
)
4078 if (child
->sortOrder
!= sortOrder
) {
4079 child
->sortOrder
= sortOrder
;
4080 refresh_child(child
);
4084 static void update_view_menu(ChildWnd
* child
)
4086 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_NAME
, child
->sortOrder
==SORT_NAME
? MF_CHECKED
: MF_UNCHECKED
);
4087 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_TYPE
, child
->sortOrder
==SORT_EXT
? MF_CHECKED
: MF_UNCHECKED
);
4088 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_SIZE
, child
->sortOrder
==SORT_SIZE
? MF_CHECKED
: MF_UNCHECKED
);
4089 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_DATE
, child
->sortOrder
==SORT_DATE
? MF_CHECKED
: MF_UNCHECKED
);
4093 static BOOL
is_directory(LPCTSTR target
)
4095 /*TODO correctly handle UNIX paths */
4096 DWORD target_attr
= GetFileAttributes(target
);
4098 if (target_attr
== INVALID_FILE_ATTRIBUTES
)
4101 return target_attr
&FILE_ATTRIBUTE_DIRECTORY
? TRUE
: FALSE
;
4104 static BOOL
prompt_target(Pane
* pane
, LPTSTR source
, LPTSTR target
)
4106 TCHAR path
[MAX_PATH
];
4109 get_path(pane
->cur
, path
);
4111 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_SELECT_DESTINATION
), pane
->hwnd
, DestinationDlgProc
, (LPARAM
)path
) != IDOK
)
4114 get_path(pane
->cur
, source
);
4116 /* convert relative targets to absolute paths */
4117 if (path
[0]!='/' && path
[1]!=':') {
4118 get_path(pane
->cur
->up
, target
);
4119 len
= lstrlen(target
);
4121 if (target
[len
-1]!='\\' && target
[len
-1]!='/')
4122 target
[len
++] = '/';
4124 lstrcpy(target
+len
, path
);
4126 lstrcpy(target
, path
);
4128 /* If the target already exists as directory, create a new target below this. */
4129 if (is_directory(path
)) {
4130 TCHAR fname
[_MAX_FNAME
], ext
[_MAX_EXT
];
4131 static const TCHAR sAppend
[] = {'%','s','/','%','s','%','s','\0'};
4133 _tsplitpath(source
, NULL
, NULL
, fname
, ext
);
4135 wsprintf(target
, sAppend
, path
, fname
, ext
);
4142 static IContextMenu2
* s_pctxmenu2
= NULL
;
4143 static IContextMenu3
* s_pctxmenu3
= NULL
;
4145 static void CtxMenu_reset(void)
4151 static IContextMenu
* CtxMenu_query_interfaces(IContextMenu
* pcm1
)
4153 IContextMenu
* pcm
= NULL
;
4157 if (IContextMenu_QueryInterface(pcm1
, &IID_IContextMenu3
, (void**)&pcm
) == NOERROR
)
4158 s_pctxmenu3
= (LPCONTEXTMENU3
)pcm
;
4159 else if (IContextMenu_QueryInterface(pcm1
, &IID_IContextMenu2
, (void**)&pcm
) == NOERROR
)
4160 s_pctxmenu2
= (LPCONTEXTMENU2
)pcm
;
4163 IContextMenu_Release(pcm1
);
4169 static BOOL
CtxMenu_HandleMenuMsg(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4172 if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3
, nmsg
, wparam
, lparam
)))
4177 if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2
, nmsg
, wparam
, lparam
)))
4184 static HRESULT
ShellFolderContextMenu(IShellFolder
* shell_folder
, HWND hwndParent
, int cidl
, LPCITEMIDLIST
* apidl
, int x
, int y
)
4187 BOOL executed
= FALSE
;
4189 HRESULT hr
= IShellFolder_GetUIObjectOf(shell_folder
, hwndParent
, cidl
, apidl
, &IID_IContextMenu
, NULL
, (LPVOID
*)&pcm
);
4190 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
4192 if (SUCCEEDED(hr
)) {
4193 HMENU hmenu
= CreatePopupMenu();
4195 pcm
= CtxMenu_query_interfaces(pcm
);
4198 hr
= IContextMenu_QueryContextMenu(pcm
, hmenu
, 0, FCIDM_SHVIEWFIRST
, FCIDM_SHVIEWLAST
, CMF_NORMAL
);
4200 if (SUCCEEDED(hr
)) {
4201 UINT idCmd
= TrackPopupMenu(hmenu
, TPM_LEFTALIGN
|TPM_RETURNCMD
|TPM_RIGHTBUTTON
, x
, y
, 0, hwndParent
, NULL
);
4206 CMINVOKECOMMANDINFO cmi
;
4208 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFO
);
4210 cmi
.hwnd
= hwndParent
;
4211 cmi
.lpVerb
= (LPCSTR
)(INT_PTR
)(idCmd
- FCIDM_SHVIEWFIRST
);
4212 cmi
.lpParameters
= NULL
;
4213 cmi
.lpDirectory
= NULL
;
4214 cmi
.nShow
= SW_SHOWNORMAL
;
4218 hr
= IContextMenu_InvokeCommand(pcm
, &cmi
);
4225 IContextMenu_Release(pcm
);
4228 return FAILED(hr
)? hr
: executed
? S_OK
: S_FALSE
;
4232 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4234 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
4239 LPDRAWITEMSTRUCT dis
= (LPDRAWITEMSTRUCT
)lparam
;
4240 Entry
* entry
= (Entry
*) dis
->itemData
;
4242 if (dis
->CtlID
== IDW_TREE_LEFT
)
4243 draw_item(&child
->left
, dis
, entry
, -1);
4244 else if (dis
->CtlID
== IDW_TREE_RIGHT
)
4245 draw_item(&child
->right
, dis
, entry
, -1);
4247 goto draw_menu_item
;
4252 InitChildWindow(child
);
4256 free_child_window(child
);
4257 SetWindowLongPtr(hwnd
, GWLP_USERDATA
, 0);
4264 GetClientRect(hwnd
, &rt
);
4265 BeginPaint(hwnd
, &ps
);
4266 rt
.left
= child
->split_pos
-SPLIT_WIDTH
/2;
4267 rt
.right
= child
->split_pos
+SPLIT_WIDTH
/2+1;
4268 lastBrush
= SelectObject(ps
.hdc
, GetStockObject(COLOR_SPLITBAR
));
4269 Rectangle(ps
.hdc
, rt
.left
, rt
.top
-1, rt
.right
, rt
.bottom
+1);
4270 SelectObject(ps
.hdc
, lastBrush
);
4271 #ifdef _NO_EXTENSIONS
4272 rt
.top
= rt
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
4273 FillRect(ps
.hdc
, &rt
, GetStockObject(BLACK_BRUSH
));
4275 EndPaint(hwnd
, &ps
);
4279 if (LOWORD(lparam
) == HTCLIENT
) {
4282 ScreenToClient(hwnd
, &pt
);
4284 if (pt
.x
>=child
->split_pos
-SPLIT_WIDTH
/2 && pt
.x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
4285 SetCursor(LoadCursor(0, IDC_SIZEWE
));
4291 case WM_LBUTTONDOWN
: {
4293 int x
= (short)LOWORD(lparam
);
4295 GetClientRect(hwnd
, &rt
);
4297 if (x
>=child
->split_pos
-SPLIT_WIDTH
/2 && x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
4298 last_split
= child
->split_pos
;
4299 #ifdef _NO_EXTENSIONS
4300 draw_splitbar(hwnd
, last_split
);
4308 if (GetCapture() == hwnd
) {
4309 #ifdef _NO_EXTENSIONS
4311 int x
= (short)LOWORD(lparam
);
4312 draw_splitbar(hwnd
, last_split
);
4314 GetClientRect(hwnd
, &rt
);
4315 child
->split_pos
= x
;
4316 resize_tree(child
, rt
.right
, rt
.bottom
);
4322 #ifdef _NO_EXTENSIONS
4323 case WM_CAPTURECHANGED
:
4324 if (GetCapture()==hwnd
&& last_split
>=0)
4325 draw_splitbar(hwnd
, last_split
);
4330 if (wparam
== VK_ESCAPE
)
4331 if (GetCapture() == hwnd
) {
4333 #ifdef _NO_EXTENSIONS
4334 draw_splitbar(hwnd
, last_split
);
4336 child
->split_pos
= last_split
;
4338 GetClientRect(hwnd
, &rt
);
4339 resize_tree(child
, rt
.right
, rt
.bottom
);
4342 SetCursor(LoadCursor(0, IDC_ARROW
));
4347 if (GetCapture() == hwnd
) {
4349 int x
= (short)LOWORD(lparam
);
4351 #ifdef _NO_EXTENSIONS
4352 HDC hdc
= GetDC(hwnd
);
4353 GetClientRect(hwnd
, &rt
);
4355 rt
.left
= last_split
-SPLIT_WIDTH
/2;
4356 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
4357 InvertRect(hdc
, &rt
);
4360 rt
.left
= x
-SPLIT_WIDTH
/2;
4361 rt
.right
= x
+SPLIT_WIDTH
/2+1;
4362 InvertRect(hdc
, &rt
);
4364 ReleaseDC(hwnd
, hdc
);
4366 GetClientRect(hwnd
, &rt
);
4368 if (x
>=0 && x
<rt
.right
) {
4369 child
->split_pos
= x
;
4370 resize_tree(child
, rt
.right
, rt
.bottom
);
4371 rt
.left
= x
-SPLIT_WIDTH
/2;
4372 rt
.right
= x
+SPLIT_WIDTH
/2+1;
4373 InvalidateRect(hwnd
, &rt
, FALSE
);
4374 UpdateWindow(child
->left
.hwnd
);
4376 UpdateWindow(child
->right
.hwnd
);
4382 #ifndef _NO_EXTENSIONS
4383 case WM_GETMINMAXINFO
:
4384 DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
4386 {LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
4388 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
4389 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
4391 #endif /* _NO_EXTENSIONS */
4394 if (SetCurrentDirectory(child
->path
))
4396 SetFocus(child
->focus_pane
? child
->right
.hwnd
: child
->left
.hwnd
);
4399 case WM_DISPATCH_COMMAND
: {
4400 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4402 switch(LOWORD(wparam
)) {
4403 case ID_WINDOW_NEW
: {
4404 ChildWnd
* new_child
= alloc_child_window(child
->path
, NULL
, hwnd
);
4406 if (!create_child_window(new_child
))
4407 HeapFree(GetProcessHeap(), 0, new_child
);
4413 refresh_child(child
);
4417 activate_entry(child
, pane
, hwnd
);
4420 case ID_FILE_MOVE
: {
4421 TCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
4423 if (prompt_target(pane
, source
, target
)) {
4424 SHFILEOPSTRUCT shfo
= {hwnd
, FO_MOVE
, source
, target
};
4426 source
[lstrlen(source
)+1] = '\0';
4427 target
[lstrlen(target
)+1] = '\0';
4429 if (!SHFileOperation(&shfo
))
4430 refresh_child(child
);
4434 case ID_FILE_COPY
: {
4435 TCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
4437 if (prompt_target(pane
, source
, target
)) {
4438 SHFILEOPSTRUCT shfo
= {hwnd
, FO_COPY
, source
, target
};
4440 source
[lstrlen(source
)+1] = '\0';
4441 target
[lstrlen(target
)+1] = '\0';
4443 if (!SHFileOperation(&shfo
))
4444 refresh_child(child
);
4448 case ID_FILE_DELETE
: {
4449 TCHAR path
[BUFFER_LEN
];
4450 SHFILEOPSTRUCT shfo
= {hwnd
, FO_DELETE
, path
, NULL
, FOF_ALLOWUNDO
};
4452 get_path(pane
->cur
, path
);
4454 path
[lstrlen(path
)+1] = '\0';
4456 if (!SHFileOperation(&shfo
))
4457 refresh_child(child
);
4460 case ID_VIEW_SORT_NAME
:
4461 set_sort_order(child
, SORT_NAME
);
4464 case ID_VIEW_SORT_TYPE
:
4465 set_sort_order(child
, SORT_EXT
);
4468 case ID_VIEW_SORT_SIZE
:
4469 set_sort_order(child
, SORT_SIZE
);
4472 case ID_VIEW_SORT_DATE
:
4473 set_sort_order(child
, SORT_DATE
);
4476 case ID_VIEW_FILTER
: {
4477 struct FilterDialog dlg
;
4479 memset(&dlg
, 0, sizeof(struct FilterDialog
));
4480 lstrcpy(dlg
.pattern
, child
->filter_pattern
);
4481 dlg
.flags
= child
->filter_flags
;
4483 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE
), hwnd
, FilterDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
4484 lstrcpy(child
->filter_pattern
, dlg
.pattern
);
4485 child
->filter_flags
= dlg
.flags
;
4486 refresh_right_pane(child
);
4490 case ID_VIEW_SPLIT
: {
4491 last_split
= child
->split_pos
;
4492 #ifdef _NO_EXTENSIONS
4493 draw_splitbar(hwnd
, last_split
);
4498 case ID_EDIT_PROPERTIES
:
4499 show_properties_dlg(pane
->cur
, child
->hwnd
);
4503 return pane_command(pane
, LOWORD(wparam
));
4509 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4511 switch(HIWORD(wparam
)) {
4512 case LBN_SELCHANGE
: {
4513 int idx
= SendMessage(pane
->hwnd
, LB_GETCURSEL
, 0, 0);
4514 Entry
* entry
= (Entry
*) SendMessage(pane
->hwnd
, LB_GETITEMDATA
, idx
, 0);
4516 if (pane
== &child
->left
)
4517 set_curdir(child
, entry
, idx
, hwnd
);
4523 activate_entry(child
, pane
, hwnd
);
4528 #ifndef _NO_EXTENSIONS
4530 NMHDR
* pnmh
= (NMHDR
*) lparam
;
4531 return pane_notify(pnmh
->idFrom
==IDW_HEADER_LEFT
? &child
->left
: &child
->right
, pnmh
);}
4534 #ifdef _SHELL_FOLDERS
4535 case WM_CONTEXTMENU
: {
4540 /* first select the current item in the listbox */
4541 HWND hpanel
= (HWND
) wparam
;
4542 pt_clnt
.x
= pt
.x
= (short)LOWORD(lparam
);
4543 pt_clnt
.y
= pt
.y
= (short)HIWORD(lparam
);
4544 ScreenToClient(hpanel
, &pt_clnt
);
4545 SendMessage(hpanel
, WM_LBUTTONDOWN
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4546 SendMessage(hpanel
, WM_LBUTTONUP
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4548 /* now create the popup menu using shell namespace and IContextMenu */
4549 pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4550 idx
= SendMessage(pane
->hwnd
, LB_GETCURSEL
, 0, 0);
4553 Entry
* entry
= (Entry
*) SendMessage(pane
->hwnd
, LB_GETITEMDATA
, idx
, 0);
4555 LPITEMIDLIST pidl_abs
= get_to_absolute_pidl(entry
, hwnd
);
4558 IShellFolder
* parentFolder
;
4559 LPCITEMIDLIST pidlLast
;
4561 /* get and use the parent folder to display correct context menu in all cases */
4562 if (SUCCEEDED(SHBindToParent(pidl_abs
, &IID_IShellFolder
, (LPVOID
*)&parentFolder
, &pidlLast
))) {
4563 if (ShellFolderContextMenu(parentFolder
, hwnd
, 1, &pidlLast
, pt
.x
, pt
.y
) == S_OK
)
4564 refresh_child(child
);
4566 IShellFolder_Release(parentFolder
);
4569 IMalloc_Free(Globals
.iMalloc
, pidl_abs
);
4575 case WM_MEASUREITEM
:
4577 if (!wparam
) /* Is the message menu-related? */
4578 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4583 case WM_INITMENUPOPUP
:
4584 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4587 update_view_menu(child
);
4590 case WM_MENUCHAR
: /* only supported by IContextMenu3 */
4592 LRESULT lResult
= 0;
4594 IContextMenu3_HandleMenuMsg2(s_pctxmenu3
, nmsg
, wparam
, lparam
, &lResult
);
4602 if (wparam
!= SIZE_MINIMIZED
)
4603 resize_tree(child
, LOWORD(lparam
), HIWORD(lparam
));
4607 return DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
4614 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4616 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtr(GetParent(hwnd
), GWLP_USERDATA
);
4617 Pane
* pane
= (Pane
*) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
4621 #ifndef _NO_EXTENSIONS
4628 child
->focus_pane
= pane
==&child
->right
? 1: 0;
4629 SendMessage(hwnd
, LB_SETSEL
, TRUE
, 1);
4630 /*TODO: check menu items */
4634 if (wparam
== VK_TAB
) {
4635 /*TODO: SetFocus(Globals.hdrivebar) */
4636 SetFocus(child
->focus_pane
? child
->left
.hwnd
: child
->right
.hwnd
);
4640 return CallWindowProc(g_orgTreeWndProc
, hwnd
, nmsg
, wparam
, lparam
);
4644 static void InitInstance(HINSTANCE hinstance
)
4646 static const TCHAR sFont
[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4653 INITCOMMONCONTROLSEX icc
= {
4654 sizeof(INITCOMMONCONTROLSEX
),
4660 setlocale(LC_COLLATE
, ""); /* set collating rules to local settings for compareName */
4662 InitCommonControlsEx(&icc
);
4665 /* register frame window class */
4667 wcFrame
.cbSize
= sizeof(WNDCLASSEX
);
4669 wcFrame
.lpfnWndProc
= FrameWndProc
;
4670 wcFrame
.cbClsExtra
= 0;
4671 wcFrame
.cbWndExtra
= 0;
4672 wcFrame
.hInstance
= hinstance
;
4673 wcFrame
.hIcon
= LoadIcon(hinstance
, MAKEINTRESOURCE(IDI_WINEFILE
));
4674 wcFrame
.hCursor
= LoadCursor(0, IDC_ARROW
);
4675 wcFrame
.hbrBackground
= 0;
4676 wcFrame
.lpszMenuName
= 0;
4677 wcFrame
.lpszClassName
= sWINEFILEFRAME
;
4678 wcFrame
.hIconSm
= (HICON
)LoadImage(hinstance
,
4679 MAKEINTRESOURCE(IDI_WINEFILE
),
4681 GetSystemMetrics(SM_CXSMICON
),
4682 GetSystemMetrics(SM_CYSMICON
),
4685 Globals
.hframeClass
= RegisterClassEx(&wcFrame
);
4688 /* register tree windows class */
4690 wcChild
.style
= CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
;
4691 wcChild
.lpfnWndProc
= ChildWndProc
;
4692 wcChild
.cbClsExtra
= 0;
4693 wcChild
.cbWndExtra
= 0;
4694 wcChild
.hInstance
= hinstance
;
4696 wcChild
.hCursor
= LoadCursor(0, IDC_ARROW
);
4697 wcChild
.hbrBackground
= 0;
4698 wcChild
.lpszMenuName
= 0;
4699 wcChild
.lpszClassName
= sWINEFILETREE
;
4701 hChildClass
= RegisterClass(&wcChild
);
4704 Globals
.haccel
= LoadAccelerators(hinstance
, MAKEINTRESOURCE(IDA_WINEFILE
));
4706 Globals
.hfont
= CreateFont(-MulDiv(8,GetDeviceCaps(hdc
,LOGPIXELSY
),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont
);
4710 Globals
.hInstance
= hinstance
;
4712 #ifdef _SHELL_FOLDERS
4714 CoGetMalloc(MEMCTX_TASK
, &Globals
.iMalloc
);
4715 SHGetDesktopFolder(&Globals
.iDesktop
);
4716 Globals
.cfStrFName
= RegisterClipboardFormat(CFSTR_FILENAME
);
4719 /* load column strings */
4722 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_NAME
);
4723 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_SIZE
);
4724 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_CDATE
);
4725 #ifndef _NO_EXTENSIONS
4726 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_ADATE
);
4727 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_MDATE
);
4728 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_IDX
);
4729 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_LINKS
);
4731 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_ATTR
);
4732 #ifndef _NO_EXTENSIONS
4733 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_SEC
);
4738 static void show_frame(HWND hwndParent
, int cmdshow
, LPCTSTR path
)
4740 static const TCHAR sMDICLIENT
[] = {'M','D','I','C','L','I','E','N','T','\0'};
4742 TCHAR buffer
[MAX_PATH
], b1
[BUFFER_LEN
];
4744 HMENU hMenuFrame
, hMenuWindow
;
4747 CLIENTCREATESTRUCT ccs
;
4749 if (Globals
.hMainWnd
)
4752 opts
= load_registry_settings();
4753 hMenuFrame
= LoadMenu(Globals
.hInstance
, MAKEINTRESOURCE(IDM_WINEFILE
));
4754 hMenuWindow
= GetSubMenu(hMenuFrame
, GetMenuItemCount(hMenuFrame
)-2);
4756 Globals
.hMenuFrame
= hMenuFrame
;
4757 Globals
.hMenuView
= GetSubMenu(hMenuFrame
, 3);
4758 Globals
.hMenuOptions
= GetSubMenu(hMenuFrame
, 4);
4760 ccs
.hWindowMenu
= hMenuWindow
;
4761 ccs
.idFirstChild
= IDW_FIRST_CHILD
;
4764 /* create main window */
4765 Globals
.hMainWnd
= CreateWindowEx(0, MAKEINTRESOURCE(Globals
.hframeClass
), RS(b1
,IDS_WINE_FILE
), WS_OVERLAPPEDWINDOW
,
4766 opts
.start_x
, opts
.start_y
, opts
.width
, opts
.height
,
4767 hwndParent
, Globals
.hMenuFrame
, Globals
.hInstance
, 0/*lpParam*/);
4770 Globals
.hmdiclient
= CreateWindowEx(0, sMDICLIENT
, NULL
,
4771 WS_CHILD
|WS_CLIPCHILDREN
|WS_VSCROLL
|WS_HSCROLL
|WS_VISIBLE
|WS_BORDER
,
4773 Globals
.hMainWnd
, 0, Globals
.hInstance
, &ccs
);
4775 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_DRIVE_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4776 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_SAVESETTINGS
, MF_BYCOMMAND
);
4781 TBBUTTON toolbarBtns
[] = {
4782 {0, 0, 0, BTNS_SEP
, {0, 0}, 0, 0},
4783 {0, ID_WINDOW_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4784 {1, ID_WINDOW_CASCADE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4785 {2, ID_WINDOW_TILE_HORZ
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4786 {3, ID_WINDOW_TILE_VERT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4788 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4789 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4792 Globals
.htoolbar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
,
4793 IDW_TOOLBAR
, 2, Globals
.hInstance
, IDB_TOOLBAR
, toolbarBtns
,
4794 sizeof(toolbarBtns
)/sizeof(TBBUTTON
), 16, 15, 16, 15, sizeof(TBBUTTON
));
4795 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_TOOL_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4798 Globals
.hstatusbar
= CreateStatusWindow(WS_CHILD
|WS_VISIBLE
, 0, Globals
.hMainWnd
, IDW_STATUSBAR
);
4799 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
4801 /* CreateStatusWindow does not accept WS_BORDER
4802 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
4803 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
4804 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
4806 /*TODO: read paths from registry */
4808 if (!path
|| !*path
) {
4809 GetCurrentDirectory(MAX_PATH
, buffer
);
4813 ShowWindow(Globals
.hMainWnd
, cmdshow
);
4815 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4816 /* Shell Namespace as default: */
4817 child
= alloc_child_window(path
, get_path_pidl(path
,Globals
.hMainWnd
), Globals
.hMainWnd
);
4819 child
= alloc_child_window(path
, NULL
, Globals
.hMainWnd
);
4822 child
->pos
.showCmd
= SW_SHOWMAXIMIZED
;
4823 child
->pos
.rcNormalPosition
.left
= 0;
4824 child
->pos
.rcNormalPosition
.top
= 0;
4825 child
->pos
.rcNormalPosition
.right
= 320;
4826 child
->pos
.rcNormalPosition
.bottom
= 280;
4828 if (!create_child_window(child
))
4829 HeapFree(GetProcessHeap(), 0, child
);
4831 SetWindowPlacement(child
->hwnd
, &child
->pos
);
4833 Globals
.himl
= ImageList_LoadBitmap(Globals
.hInstance
, MAKEINTRESOURCE(IDB_IMAGES
), 16, 0, RGB(0,255,0));
4835 Globals
.prescan_node
= FALSE
;
4837 UpdateWindow(Globals
.hMainWnd
);
4839 if (path
&& path
[0])
4842 TCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
4843 TCHAR fullname
[_MAX_FNAME
+_MAX_EXT
+1];
4845 memset(name
,0,sizeof(name
));
4846 memset(name
,0,sizeof(ext
));
4847 _tsplitpath(path
, drv
, dir
, name
, ext
);
4850 count
= SendMessage(child
->right
.hwnd
, LB_GETCOUNT
, 0, 0);
4851 lstrcpy(fullname
,name
);
4852 lstrcat(fullname
,ext
);
4854 for (index
= 0; index
< count
; index
++)
4856 Entry
* entry
= (Entry
*) SendMessage(child
->right
.hwnd
, LB_GETITEMDATA
, index
, 0);
4857 if (lstrcmp(entry
->data
.cFileName
,fullname
)==0 ||
4858 lstrcmp(entry
->data
.cAlternateFileName
,fullname
)==0)
4860 SendMessage(child
->right
.hwnd
, LB_SETCURSEL
, index
, 0);
4861 SetFocus(child
->right
.hwnd
);
4869 static void ExitInstance(void)
4871 #ifdef _SHELL_FOLDERS
4872 IShellFolder_Release(Globals
.iDesktop
);
4873 IMalloc_Release(Globals
.iMalloc
);
4877 DeleteObject(Globals
.hfont
);
4878 ImageList_Destroy(Globals
.himl
);
4881 #ifdef _NO_EXTENSIONS
4883 /* search for already running win[e]files */
4885 static int g_foundPrevInstance
= 0;
4887 static BOOL CALLBACK
EnumWndProc(HWND hwnd
, LPARAM lparam
)
4891 GetClassName(hwnd
, cls
, 128);
4893 if (!lstrcmp(cls
, (LPCTSTR
)lparam
)) {
4894 g_foundPrevInstance
++;
4901 /* search for window of given class name to allow only one running instance */
4902 static int find_window_class(LPCTSTR classname
)
4904 EnumWindows(EnumWndProc
, (LPARAM
)classname
);
4906 if (g_foundPrevInstance
)
4914 static int winefile_main(HINSTANCE hinstance
, int cmdshow
, LPCTSTR path
)
4918 InitInstance(hinstance
);
4920 show_frame(0, cmdshow
, path
);
4922 while(GetMessage(&msg
, 0, 0, 0)) {
4923 if (Globals
.hmdiclient
&& TranslateMDISysAccel(Globals
.hmdiclient
, &msg
))
4926 if (Globals
.hMainWnd
&& TranslateAccelerator(Globals
.hMainWnd
, Globals
.haccel
, &msg
))
4929 TranslateMessage(&msg
);
4930 DispatchMessage(&msg
);
4939 #if defined(UNICODE) && defined(_MSC_VER)
4940 int APIENTRY
wWinMain(HINSTANCE hinstance
, HINSTANCE previnstance
, LPWSTR cmdline
, int cmdshow
)
4942 int APIENTRY
WinMain(HINSTANCE hinstance
, HINSTANCE previnstance
, LPSTR cmdline
, int cmdshow
)
4945 #ifdef _NO_EXTENSIONS
4946 if (find_window_class(sWINEFILEFRAME
))
4950 #if defined(UNICODE) && !defined(_MSC_VER)
4951 { /* convert ANSI cmdline into WCS path string */
4952 TCHAR buffer
[MAX_PATH
];
4953 MultiByteToWideChar(CP_ACP
, 0, cmdline
, -1, buffer
, MAX_PATH
);
4954 winefile_main(hinstance
, cmdshow
, buffer
);
4957 winefile_main(hinstance
, cmdshow
, cmdline
);