4 * Copyright 2000, 2003, 2004, 2005 Martin Fuchs
5 * Copyright 2006 Jason Green
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
26 /* for unix filesystem function calls */
28 #include <sys/types.h>
36 #include "wine/unicode.h"
40 #define _MAX_FNAME 256
41 #define _MAX_DIR _MAX_FNAME
42 #define _MAX_EXT _MAX_FNAME
46 #ifdef NONAMELESSUNION
47 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
49 #define UNION_MEMBER(x) x
52 #define DEFAULT_SPLIT_POS 300
54 static const WCHAR registry_key
[] = { 'S','o','f','t','w','a','r','e','\\',
56 'W','i','n','e','F','i','l','e','\0'};
57 static const WCHAR reg_start_x
[] = { 's','t','a','r','t','X','\0'};
58 static const WCHAR reg_start_y
[] = { 's','t','a','r','t','Y','\0'};
59 static const WCHAR reg_width
[] = { 'w','i','d','t','h','\0'};
60 static const WCHAR reg_height
[] = { 'h','e','i','g','h','t','\0'};
61 static const WCHAR reg_logfont
[] = { 'l','o','g','f','o','n','t','\0'};
69 typedef struct _Entry
{
78 WIN32_FIND_DATAW data
;
80 BY_HANDLE_FILE_INFORMATION bhfi
;
82 enum ENTRY_TYPE etype
;
91 WCHAR volname
[_MAX_FNAME
];
101 COL_ATTRIBUTES
= 0x08,
105 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
|COL_INDEX
|COL_LINKS
121 int widths_shown
[COLUMNS
];
122 int positions
[COLUMNS
+1];
134 int focus_pane
; /* 0: left 1: right */
137 BOOL header_wdths_ok
;
139 WCHAR path
[MAX_PATH
];
140 WCHAR filter_pattern
[MAX_PATH
];
144 SORT_ORDER sortOrder
;
149 static void read_directory(Entry
* dir
, LPCWSTR path
, SORT_ORDER sortOrder
, HWND hwnd
);
150 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
);
151 static void refresh_child(ChildWnd
* child
);
152 static void refresh_drives(void);
153 static void get_path(Entry
* dir
, PWSTR path
);
154 static void format_date(const FILETIME
* ft
, WCHAR
* buffer
, int visible_cols
);
156 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
157 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
158 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
162 WINEFILE_GLOBALS Globals
;
164 static int last_split
;
166 /* some common string constants */
167 static const WCHAR sEmpty
[] = {'\0'};
168 static const WCHAR sSpace
[] = {' ', '\0'};
169 static const WCHAR sNumFmt
[] = {'%','d','\0'};
170 static const WCHAR sQMarks
[] = {'?','?','?','\0'};
172 /* window class names */
173 static const WCHAR sWINEFILEFRAME
[] = {'W','F','S','_','F','r','a','m','e','\0'};
174 static const WCHAR sWINEFILETREE
[] = {'W','F','S','_','T','r','e','e','\0'};
176 static void format_longlong(LPWSTR ret
, ULONGLONG val
)
178 WCHAR buffer
[65], *p
= &buffer
[64];
182 *(--p
) = '0' + val
% 10;
189 /* load resource string */
190 static LPWSTR
load_string(LPWSTR buffer
, DWORD size
, UINT id
)
192 LoadStringW(Globals
.hInstance
, id
, buffer
, size
);
196 #define RS(b, i) load_string(b, sizeof(b)/sizeof(b[0]), i)
199 /* display error message for the specified WIN32 error code */
200 static void display_error(HWND hwnd
, DWORD error
)
202 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
205 if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_FROM_SYSTEM
,
206 0, error
, MAKELANGID(LANG_NEUTRAL
,SUBLANG_DEFAULT
), (PWSTR
)&msg
, 0, NULL
))
207 MessageBoxW(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
209 MessageBoxW(hwnd
, RS(b1
,IDS_ERROR
), RS(b2
,IDS_WINEFILE
), MB_OK
);
215 /* display network error message using WNetGetLastErrorW() */
216 static void display_network_error(HWND hwnd
)
218 WCHAR msg
[BUFFER_LEN
], provider
[BUFFER_LEN
], b2
[BUFFER_LEN
];
221 if (WNetGetLastErrorW(&error
, msg
, BUFFER_LEN
, provider
, BUFFER_LEN
) == NO_ERROR
)
222 MessageBoxW(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
225 static inline BOOL
get_check(HWND hwnd
, INT id
)
227 return BST_CHECKED
&SendMessageW(GetDlgItem(hwnd
, id
), BM_GETSTATE
, 0, 0);
230 static inline INT
set_check(HWND hwnd
, INT id
, BOOL on
)
232 return SendMessageW(GetDlgItem(hwnd
, id
), BM_SETCHECK
, on
?BST_CHECKED
:BST_UNCHECKED
, 0);
235 static inline void choose_font(HWND hwnd
)
237 WCHAR dlg_name
[BUFFER_LEN
], dlg_info
[BUFFER_LEN
];
241 HDC hdc
= GetDC(hwnd
);
243 GetObjectW(Globals
.hfont
, sizeof(LOGFONTW
), &lFont
);
245 chFont
.lStructSize
= sizeof(CHOOSEFONTW
);
246 chFont
.hwndOwner
= hwnd
;
248 chFont
.lpLogFont
= &lFont
;
249 chFont
.Flags
= CF_SCREENFONTS
| CF_FORCEFONTEXIST
| CF_LIMITSIZE
| CF_NOSCRIPTSEL
| CF_INITTOLOGFONTSTRUCT
| CF_NOVERTFONTS
;
250 chFont
.rgbColors
= RGB(0,0,0);
251 chFont
.lCustData
= 0;
252 chFont
.lpfnHook
= NULL
;
253 chFont
.lpTemplateName
= NULL
;
254 chFont
.hInstance
= Globals
.hInstance
;
255 chFont
.lpszStyle
= NULL
;
256 chFont
.nFontType
= SIMULATED_FONTTYPE
;
258 chFont
.nSizeMax
= 24;
260 if (ChooseFontW(&chFont
)) {
264 DeleteObject(Globals
.hfont
);
265 Globals
.hfont
= CreateFontIndirectW(&lFont
);
266 hFontOld
= SelectObject(hdc
, Globals
.hfont
);
267 GetTextExtentPoint32W(hdc
, sSpace
, 1, &Globals
.spaceSize
);
269 /* change font in all open child windows */
270 for(childWnd
=GetWindow(Globals
.hmdiclient
,GW_CHILD
); childWnd
; childWnd
=GetNextWindow(childWnd
,GW_HWNDNEXT
)) {
271 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtrW(childWnd
, GWLP_USERDATA
);
272 SendMessageW(child
->left
.hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, TRUE
);
273 SendMessageW(child
->right
.hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, TRUE
);
274 SendMessageW(child
->left
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
275 SendMessageW(child
->right
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
276 InvalidateRect(child
->left
.hwnd
, NULL
, TRUE
);
277 InvalidateRect(child
->right
.hwnd
, NULL
, TRUE
);
280 SelectObject(hdc
, hFontOld
);
282 else if (CommDlgExtendedError()) {
283 LoadStringW(Globals
.hInstance
, IDS_FONT_SEL_DLG_NAME
, dlg_name
, BUFFER_LEN
);
284 LoadStringW(Globals
.hInstance
, IDS_FONT_SEL_ERROR
, dlg_info
, BUFFER_LEN
);
285 MessageBoxW(hwnd
, dlg_info
, dlg_name
, MB_OK
);
288 ReleaseDC(hwnd
, hdc
);
292 /* allocate and initialise a directory entry */
293 static Entry
* alloc_entry(void)
295 Entry
* entry
= HeapAlloc(GetProcessHeap(), 0, sizeof(Entry
));
298 entry
->folder
= NULL
;
304 /* free a directory entry */
305 static void free_entry(Entry
* entry
)
307 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
308 DestroyIcon(entry
->hicon
);
310 if (entry
->folder
&& entry
->folder
!=Globals
.iDesktop
)
311 IShellFolder_Release(entry
->folder
);
314 IMalloc_Free(Globals
.iMalloc
, entry
->pidl
);
316 HeapFree(GetProcessHeap(), 0, entry
);
319 /* recursively free all child entries */
320 static void free_entries(Entry
* dir
)
322 Entry
*entry
, *next
=dir
->down
;
338 static void read_directory_win(Entry
* dir
, LPCWSTR path
)
340 Entry
* first_entry
= NULL
;
344 int level
= dir
->level
+ 1;
345 WIN32_FIND_DATAW w32fd
;
349 WCHAR buffer
[MAX_PATH
], *p
;
350 for(p
=buffer
; *path
; )
357 hFind
= FindFirstFileW(buffer
, &w32fd
);
359 if (hFind
!= INVALID_HANDLE_VALUE
) {
361 entry
= alloc_entry();
369 memcpy(&entry
->data
, &w32fd
, sizeof(WIN32_FIND_DATAW
));
372 entry
->expanded
= FALSE
;
373 entry
->scanned
= FALSE
;
374 entry
->level
= level
;
375 entry
->etype
= ET_WINDOWS
;
376 entry
->bhfi_valid
= FALSE
;
378 lstrcpyW(p
, entry
->data
.cFileName
);
380 hFile
= CreateFileW(buffer
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
381 0, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0);
383 if (hFile
!= INVALID_HANDLE_VALUE
) {
384 if (GetFileInformationByHandle(hFile
, &entry
->bhfi
))
385 entry
->bhfi_valid
= TRUE
;
391 } while(FindNextFileW(hFind
, &w32fd
));
399 dir
->down
= first_entry
;
404 static Entry
* find_entry_win(Entry
* dir
, LPCWSTR name
)
408 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
410 LPCWSTR q
= entry
->data
.cFileName
;
413 if (!*p
|| *p
== '\\' || *p
== '/')
415 } while(tolower(*p
++) == tolower(*q
++));
418 q
= entry
->data
.cAlternateFileName
;
421 if (!*p
|| *p
== '\\' || *p
== '/')
423 } while(tolower(*p
++) == tolower(*q
++));
430 static Entry
* read_tree_win(Root
* root
, LPCWSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
432 WCHAR buffer
[MAX_PATH
];
433 Entry
* entry
= &root
->entry
;
437 HCURSOR old_cursor
= SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_WAIT
));
439 entry
->etype
= ET_WINDOWS
;
441 while(*s
&& *s
!= '\\' && *s
!= '/')
444 while(*s
== '\\' || *s
== '/')
450 read_directory(entry
, buffer
, sortOrder
, hwnd
);
453 entry
->expanded
= TRUE
;
458 entry
= find_entry_win(entry
, s
);
461 SetCursor(old_cursor
);
469 static BOOL
time_to_filetime(time_t t
, FILETIME
* ftime
)
471 struct tm
* tm
= gmtime(&t
);
477 stime
.wYear
= tm
->tm_year
+1900;
478 stime
.wMonth
= tm
->tm_mon
+1;
479 /* stime.wDayOfWeek */
480 stime
.wDay
= tm
->tm_mday
;
481 stime
.wHour
= tm
->tm_hour
;
482 stime
.wMinute
= tm
->tm_min
;
483 stime
.wSecond
= tm
->tm_sec
;
484 stime
.wMilliseconds
= 0;
486 return SystemTimeToFileTime(&stime
, ftime
);
489 static void read_directory_unix(Entry
* dir
, LPCWSTR path
)
491 Entry
* first_entry
= NULL
;
496 int level
= dir
->level
+ 1;
497 char cpath
[MAX_PATH
];
499 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, cpath
, MAX_PATH
, NULL
, NULL
);
500 pdir
= opendir(cpath
);
505 char buffer
[MAX_PATH
], *p
;
508 for(p
=buffer
,s
=cpath
; *s
; )
511 if (p
==buffer
|| p
[-1]!='/')
514 while((ent
=readdir(pdir
))) {
515 entry
= alloc_entry();
523 entry
->etype
= ET_UNIX
;
525 strcpy(p
, ent
->d_name
);
526 MultiByteToWideChar(CP_UNIXCP
, 0, p
, -1, entry
->data
.cFileName
, MAX_PATH
);
528 if (!stat(buffer
, &st
)) {
529 entry
->data
.dwFileAttributes
= p
[0]=='.'? FILE_ATTRIBUTE_HIDDEN
: 0;
531 if (S_ISDIR(st
.st_mode
))
532 entry
->data
.dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
534 entry
->data
.nFileSizeLow
= st
.st_size
& 0xFFFFFFFF;
535 entry
->data
.nFileSizeHigh
= st
.st_size
>> 32;
537 memset(&entry
->data
.ftCreationTime
, 0, sizeof(FILETIME
));
538 time_to_filetime(st
.st_atime
, &entry
->data
.ftLastAccessTime
);
539 time_to_filetime(st
.st_mtime
, &entry
->data
.ftLastWriteTime
);
541 entry
->bhfi
.nFileIndexLow
= ent
->d_ino
;
542 entry
->bhfi
.nFileIndexHigh
= 0;
544 entry
->bhfi
.nNumberOfLinks
= st
.st_nlink
;
546 entry
->bhfi_valid
= TRUE
;
548 entry
->data
.nFileSizeLow
= 0;
549 entry
->data
.nFileSizeHigh
= 0;
550 entry
->bhfi_valid
= FALSE
;
555 entry
->expanded
= FALSE
;
556 entry
->scanned
= FALSE
;
557 entry
->level
= level
;
568 dir
->down
= first_entry
;
572 static Entry
* find_entry_unix(Entry
* dir
, LPCWSTR name
)
576 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
578 LPCWSTR q
= entry
->data
.cFileName
;
581 if (!*p
|| *p
== '/')
583 } while(*p
++ == *q
++);
589 static Entry
* read_tree_unix(Root
* root
, LPCWSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
591 WCHAR buffer
[MAX_PATH
];
592 Entry
* entry
= &root
->entry
;
596 HCURSOR old_cursor
= SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_WAIT
));
598 entry
->etype
= ET_UNIX
;
601 while(*s
&& *s
!= '/')
610 read_directory(entry
, buffer
, sortOrder
, hwnd
);
613 entry
->expanded
= TRUE
;
618 entry
= find_entry_unix(entry
, s
);
621 SetCursor(old_cursor
);
626 #endif /* __WINE__ */
628 static void free_strret(STRRET
* str
)
630 if (str
->uType
== STRRET_WSTR
)
631 IMalloc_Free(Globals
.iMalloc
, str
->UNION_MEMBER(pOleStr
));
634 static LPWSTR
wcscpyn(LPWSTR dest
, LPCWSTR source
, size_t count
)
639 for(s
=source
; count
&&(*d
++=*s
++); )
645 static void get_strretW(STRRET
* str
, const SHITEMID
* shiid
, LPWSTR buffer
, int len
)
649 wcscpyn(buffer
, str
->UNION_MEMBER(pOleStr
), len
);
653 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), -1, buffer
, len
);
657 MultiByteToWideChar(CP_ACP
, 0, str
->UNION_MEMBER(cStr
), -1, buffer
, len
);
662 static HRESULT
name_from_pidl(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPWSTR buffer
, int len
, SHGDNF flags
)
666 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, flags
, &str
);
669 get_strretW(&str
, &pidl
->mkid
, buffer
, len
);
678 static HRESULT
path_from_pidlW(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPWSTR buffer
, int len
)
682 /* SHGDN_FORPARSING: get full path of id list */
683 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, SHGDN_FORPARSING
, &str
);
686 get_strretW(&str
, &pidl
->mkid
, buffer
, len
);
695 /* create an item id list from a file system path */
697 static LPITEMIDLIST
get_path_pidl(LPWSTR path
, HWND hwnd
)
702 LPWSTR buffer
= path
;
704 hr
= IShellFolder_ParseDisplayName(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
712 /* convert an item id list from relative to absolute (=relative to the desktop) format */
714 static LPITEMIDLIST
get_to_absolute_pidl(Entry
* entry
, HWND hwnd
)
716 if (entry
->up
&& entry
->up
->etype
==ET_SHELL
) {
717 LPITEMIDLIST idl
= NULL
;
720 idl
= ILCombine(ILClone(entry
->pidl
), idl
);
725 } else if (entry
->etype
== ET_WINDOWS
) {
726 WCHAR path
[MAX_PATH
];
728 get_path(entry
, path
);
730 return get_path_pidl(path
, hwnd
);
731 } else if (entry
->pidl
)
732 return ILClone(entry
->pidl
);
738 static HICON
extract_icon(IShellFolder
* folder
, LPCITEMIDLIST pidl
)
740 IExtractIconW
* pExtract
;
742 if (SUCCEEDED(IShellFolder_GetUIObjectOf(folder
, 0, 1, (LPCITEMIDLIST
*)&pidl
, &IID_IExtractIconW
, 0, (LPVOID
*)&pExtract
))) {
743 WCHAR path
[_MAX_PATH
];
748 if (SUCCEEDED(IExtractIconW_GetIconLocation(pExtract
, GIL_FORSHELL
, path
, _MAX_PATH
, &idx
, &flags
))) {
749 if (!(flags
& GIL_NOTFILENAME
)) {
751 idx
= 0; /* special case for some control panel applications */
753 if ((int)ExtractIconExW(path
, idx
, 0, &hicon
, 1) > 0)
754 flags
&= ~GIL_DONTCACHE
;
756 HICON hIconLarge
= 0;
758 HRESULT hr
= IExtractIconW_Extract(pExtract
, path
, idx
, &hIconLarge
, &hicon
, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON
)));
761 DestroyIcon(hIconLarge
);
772 static Entry
* find_entry_shell(Entry
* dir
, LPCITEMIDLIST pidl
)
776 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
777 if (entry
->pidl
->mkid
.cb
== pidl
->mkid
.cb
&&
778 !memcmp(entry
->pidl
, pidl
, entry
->pidl
->mkid
.cb
))
785 static Entry
* read_tree_shell(Root
* root
, LPITEMIDLIST pidl
, SORT_ORDER sortOrder
, HWND hwnd
)
787 Entry
* entry
= &root
->entry
;
789 LPITEMIDLIST next_pidl
= pidl
;
790 IShellFolder
* folder
;
791 IShellFolder
* child
= NULL
;
794 HCURSOR old_cursor
= SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_WAIT
));
796 entry
->etype
= ET_SHELL
;
797 folder
= Globals
.iDesktop
;
800 entry
->pidl
= next_pidl
;
801 entry
->folder
= folder
;
806 /* copy first element of item idlist */
807 next_pidl
= IMalloc_Alloc(Globals
.iMalloc
, pidl
->mkid
.cb
+sizeof(USHORT
));
808 memcpy(next_pidl
, pidl
, pidl
->mkid
.cb
);
809 ((LPITEMIDLIST
)((LPBYTE
)next_pidl
+pidl
->mkid
.cb
))->mkid
.cb
= 0;
811 hr
= IShellFolder_BindToObject(folder
, next_pidl
, 0, &IID_IShellFolder
, (void**)&child
);
815 read_directory(entry
, NULL
, sortOrder
, hwnd
);
818 entry
->expanded
= TRUE
;
820 next
= find_entry_shell(entry
, next_pidl
);
827 /* go to next element */
828 pidl
= (LPITEMIDLIST
) ((LPBYTE
)pidl
+pidl
->mkid
.cb
);
831 SetCursor(old_cursor
);
837 static void fill_w32fdata_shell(IShellFolder
* folder
, LPCITEMIDLIST pidl
, SFGAOF attribs
, WIN32_FIND_DATAW
* w32fdata
)
839 if (!(attribs
& SFGAO_FILESYSTEM
) ||
840 FAILED(SHGetDataFromIDListW(folder
, pidl
, SHGDFIL_FINDDATA
, w32fdata
, sizeof(WIN32_FIND_DATAW
)))) {
841 WIN32_FILE_ATTRIBUTE_DATA fad
;
842 IDataObject
* pDataObj
;
844 STGMEDIUM medium
= {0, {0}, 0};
845 FORMATETC fmt
= {Globals
.cfStrFName
, 0, DVASPECT_CONTENT
, -1, TYMED_HGLOBAL
};
847 HRESULT hr
= IShellFolder_GetUIObjectOf(folder
, 0, 1, &pidl
, &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
850 hr
= IDataObject_GetData(pDataObj
, &fmt
, &medium
);
852 IDataObject_Release(pDataObj
);
855 LPCWSTR path
= GlobalLock(medium
.UNION_MEMBER(hGlobal
));
856 UINT sem_org
= SetErrorMode(SEM_FAILCRITICALERRORS
);
858 if (GetFileAttributesExW(path
, GetFileExInfoStandard
, &fad
)) {
859 w32fdata
->dwFileAttributes
= fad
.dwFileAttributes
;
860 w32fdata
->ftCreationTime
= fad
.ftCreationTime
;
861 w32fdata
->ftLastAccessTime
= fad
.ftLastAccessTime
;
862 w32fdata
->ftLastWriteTime
= fad
.ftLastWriteTime
;
864 if (!(fad
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)) {
865 w32fdata
->nFileSizeLow
= fad
.nFileSizeLow
;
866 w32fdata
->nFileSizeHigh
= fad
.nFileSizeHigh
;
870 SetErrorMode(sem_org
);
872 GlobalUnlock(medium
.UNION_MEMBER(hGlobal
));
873 GlobalFree(medium
.UNION_MEMBER(hGlobal
));
878 if (attribs
& (SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
))
879 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
881 if (attribs
& SFGAO_READONLY
)
882 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_READONLY
;
884 if (attribs
& SFGAO_COMPRESSED
)
885 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_COMPRESSED
;
889 static void read_directory_shell(Entry
* dir
, HWND hwnd
)
891 IShellFolder
* folder
= dir
->folder
;
892 int level
= dir
->level
+ 1;
898 Entry
* first_entry
= NULL
;
905 hr
= IShellFolder_EnumObjects(folder
, hwnd
, SHCONTF_FOLDERS
|SHCONTF_NONFOLDERS
|SHCONTF_INCLUDEHIDDEN
|SHCONTF_SHAREABLE
|SHCONTF_STORAGE
, &idlist
);
909 #define FETCH_ITEM_COUNT 32
910 LPITEMIDLIST pidls
[FETCH_ITEM_COUNT
];
915 memset(pidls
, 0, sizeof(pidls
));
917 hr
= IEnumIDList_Next(idlist
, FETCH_ITEM_COUNT
, pidls
, &cnt
);
924 for(n
=0; n
<cnt
; ++n
) {
925 entry
= alloc_entry();
933 memset(&entry
->data
, 0, sizeof(WIN32_FIND_DATAW
));
934 entry
->bhfi_valid
= FALSE
;
936 attribs
= ~SFGAO_FILESYSTEM
; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
938 hr
= IShellFolder_GetAttributesOf(folder
, 1, (LPCITEMIDLIST
*)&pidls
[n
], &attribs
);
941 if (attribs
!= (SFGAOF
)~SFGAO_FILESYSTEM
) {
942 fill_w32fdata_shell(folder
, pidls
[n
], attribs
, &entry
->data
);
944 entry
->bhfi_valid
= TRUE
;
950 entry
->pidl
= pidls
[n
];
952 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
953 hr
= IShellFolder_BindToObject(folder
, pidls
[n
], 0, &IID_IShellFolder
, (void**)&child
);
956 entry
->folder
= child
;
958 entry
->folder
= NULL
;
961 entry
->folder
= NULL
;
963 if (!entry
->data
.cFileName
[0])
964 /*hr = */name_from_pidl(folder
, pidls
[n
], entry
->data
.cFileName
, MAX_PATH
, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
966 /* get display icons for files and virtual objects */
967 if (!(entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ||
968 !(attribs
& SFGAO_FILESYSTEM
)) {
969 entry
->hicon
= extract_icon(folder
, pidls
[n
]);
972 entry
->hicon
= (HICON
)-1; /* don't try again later */
977 entry
->expanded
= FALSE
;
978 entry
->scanned
= FALSE
;
979 entry
->level
= level
;
981 entry
->etype
= ET_SHELL
;
982 entry
->bhfi_valid
= FALSE
;
988 IEnumIDList_Release(idlist
);
994 dir
->down
= first_entry
;
998 /* sort order for different directory/file types */
1007 /* distinguish between ".", ".." and any other directory names */
1008 static int TypeOrderFromDirname(LPCWSTR name
)
1010 if (name
[0] == '.') {
1011 if (name
[1] == '\0')
1012 return TO_DOT
; /* "." */
1014 if (name
[1]=='.' && name
[2]=='\0')
1015 return TO_DOTDOT
; /* ".." */
1018 return TO_OTHER_DIR
; /* anything else */
1021 /* directories first... */
1022 static int compareType(const WIN32_FIND_DATAW
* fd1
, const WIN32_FIND_DATAW
* fd2
)
1024 int order1
= fd1
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1025 int order2
= fd2
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1027 /* Handle "." and ".." as special case and move them at the very first beginning. */
1028 if (order1
==TO_DIR
&& order2
==TO_DIR
) {
1029 order1
= TypeOrderFromDirname(fd1
->cFileName
);
1030 order2
= TypeOrderFromDirname(fd2
->cFileName
);
1033 return order2
==order1
? 0: order1
<order2
? -1: 1;
1037 static int compareName(const void* arg1
, const void* arg2
)
1039 const WIN32_FIND_DATAW
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1040 const WIN32_FIND_DATAW
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1042 int cmp
= compareType(fd1
, fd2
);
1046 return lstrcmpiW(fd1
->cFileName
, fd2
->cFileName
);
1049 static int compareExt(const void* arg1
, const void* arg2
)
1051 const WIN32_FIND_DATAW
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1052 const WIN32_FIND_DATAW
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1053 const WCHAR
*name1
, *name2
, *ext1
, *ext2
;
1055 int cmp
= compareType(fd1
, fd2
);
1059 name1
= fd1
->cFileName
;
1060 name2
= fd2
->cFileName
;
1062 ext1
= strrchrW(name1
, '.');
1063 ext2
= strrchrW(name2
, '.');
1075 cmp
= lstrcmpiW(ext1
, ext2
);
1079 return lstrcmpiW(name1
, name2
);
1082 static int compareSize(const void* arg1
, const void* arg2
)
1084 const WIN32_FIND_DATAW
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1085 const WIN32_FIND_DATAW
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1087 int cmp
= compareType(fd1
, fd2
);
1091 cmp
= fd2
->nFileSizeHigh
- fd1
->nFileSizeHigh
;
1098 cmp
= fd2
->nFileSizeLow
- fd1
->nFileSizeLow
;
1100 return cmp
<0? -1: cmp
>0? 1: 0;
1103 static int compareDate(const void* arg1
, const void* arg2
)
1105 const WIN32_FIND_DATAW
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1106 const WIN32_FIND_DATAW
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1108 int cmp
= compareType(fd1
, fd2
);
1112 return CompareFileTime(&fd2
->ftLastWriteTime
, &fd1
->ftLastWriteTime
);
1116 static int (*sortFunctions
[])(const void* arg1
, const void* arg2
) = {
1117 compareName
, /* SORT_NAME */
1118 compareExt
, /* SORT_EXT */
1119 compareSize
, /* SORT_SIZE */
1120 compareDate
/* SORT_DATE */
1124 static void SortDirectory(Entry
* dir
, SORT_ORDER sortOrder
)
1131 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1135 array
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(Entry
*));
1138 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1141 /* call qsort with the appropriate compare function */
1142 qsort(array
, len
, sizeof(array
[0]), sortFunctions
[sortOrder
]);
1144 dir
->down
= array
[0];
1146 for(p
=array
; --len
; p
++)
1151 HeapFree(GetProcessHeap(), 0, array
);
1156 static void read_directory(Entry
* dir
, LPCWSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
1158 WCHAR buffer
[MAX_PATH
];
1163 if (dir
->etype
== ET_SHELL
)
1165 read_directory_shell(dir
, hwnd
);
1167 if (Globals
.prescan_node
) {
1176 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1177 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1178 read_directory_shell(entry
, hwnd
);
1179 SortDirectory(entry
, sortOrder
);
1185 if (dir
->etype
== ET_UNIX
)
1187 read_directory_unix(dir
, path
);
1189 if (Globals
.prescan_node
) {
1198 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1199 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1200 lstrcpyW(d
, entry
->data
.cFileName
);
1201 read_directory_unix(entry
, buffer
);
1202 SortDirectory(entry
, sortOrder
);
1209 read_directory_win(dir
, path
);
1211 if (Globals
.prescan_node
) {
1220 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1221 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1222 lstrcpyW(d
, entry
->data
.cFileName
);
1223 read_directory_win(entry
, buffer
);
1224 SortDirectory(entry
, sortOrder
);
1229 SortDirectory(dir
, sortOrder
);
1233 static Entry
* read_tree(Root
* root
, LPCWSTR path
, LPITEMIDLIST pidl
, LPWSTR drv
, SORT_ORDER sortOrder
, HWND hwnd
)
1236 static const WCHAR sSlash
[] = {'/', '\0'};
1238 static const WCHAR sBackslash
[] = {'\\', '\0'};
1242 /* read shell namespace tree */
1243 root
->drive_type
= DRIVE_UNKNOWN
;
1246 load_string(root
->volname
, sizeof(root
->volname
)/sizeof(root
->volname
[0]), IDS_DESKTOP
);
1248 load_string(root
->fs
, sizeof(root
->fs
)/sizeof(root
->fs
[0]), IDS_SHELL
);
1250 return read_tree_shell(root
, pidl
, sortOrder
, hwnd
);
1256 /* read unix file system tree */
1257 root
->drive_type
= GetDriveTypeW(path
);
1259 lstrcatW(drv
, sSlash
);
1260 load_string(root
->volname
, sizeof(root
->volname
)/sizeof(root
->volname
[0]), IDS_ROOT_FS
);
1262 load_string(root
->fs
, sizeof(root
->fs
)/sizeof(root
->fs
[0]), IDS_UNIXFS
);
1264 lstrcpyW(root
->path
, sSlash
);
1266 return read_tree_unix(root
, path
, sortOrder
, hwnd
);
1270 /* read WIN32 file system tree */
1271 root
->drive_type
= GetDriveTypeW(path
);
1273 lstrcatW(drv
, sBackslash
);
1274 GetVolumeInformationW(drv
, root
->volname
, _MAX_FNAME
, 0, 0, &root
->fs_flags
, root
->fs
, _MAX_DIR
);
1276 lstrcpyW(root
->path
, drv
);
1278 return read_tree_win(root
, path
, sortOrder
, hwnd
);
1282 /* flags to filter different file types */
1284 TF_DIRECTORIES
= 0x01,
1286 TF_DOCUMENTS
= 0x04,
1293 static ChildWnd
* alloc_child_window(LPCWSTR path
, LPITEMIDLIST pidl
, HWND hwnd
)
1295 WCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
1296 WCHAR dir_path
[MAX_PATH
];
1297 static const WCHAR sAsterics
[] = {'*', '\0'};
1298 static const WCHAR sTitleFmt
[] = {'%','s',' ','-',' ','%','s','\0'};
1300 ChildWnd
* child
= HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd
));
1301 Root
* root
= &child
->root
;
1304 memset(child
, 0, sizeof(ChildWnd
));
1306 child
->left
.treePane
= TRUE
;
1307 child
->left
.visible_cols
= 0;
1309 child
->right
.treePane
= FALSE
;
1310 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_INDEX
|COL_LINKS
;
1312 child
->pos
.length
= sizeof(WINDOWPLACEMENT
);
1313 child
->pos
.flags
= 0;
1314 child
->pos
.showCmd
= SW_SHOWNORMAL
;
1315 child
->pos
.rcNormalPosition
.left
= CW_USEDEFAULT
;
1316 child
->pos
.rcNormalPosition
.top
= CW_USEDEFAULT
;
1317 child
->pos
.rcNormalPosition
.right
= CW_USEDEFAULT
;
1318 child
->pos
.rcNormalPosition
.bottom
= CW_USEDEFAULT
;
1320 child
->focus_pane
= 0;
1321 child
->split_pos
= DEFAULT_SPLIT_POS
;
1322 child
->sortOrder
= SORT_NAME
;
1323 child
->header_wdths_ok
= FALSE
;
1327 int pathlen
= strlenW(path
);
1328 const WCHAR
*npath
= path
;
1330 if (path
[0] == '"' && path
[pathlen
- 1] == '"')
1335 lstrcpynW(child
->path
, npath
, pathlen
+ 1);
1337 _wsplitpath(child
->path
, drv
, dir
, name
, ext
);
1340 lstrcpyW(child
->filter_pattern
, sAsterics
);
1341 child
->filter_flags
= TF_ALL
;
1343 root
->entry
.level
= 0;
1345 lstrcpyW(dir_path
, drv
);
1346 lstrcatW(dir_path
, dir
);
1347 entry
= read_tree(root
, dir_path
, pidl
, drv
, child
->sortOrder
, hwnd
);
1349 if (root
->entry
.etype
== ET_SHELL
)
1350 load_string(root
->entry
.data
.cFileName
, sizeof(root
->entry
.data
.cFileName
)/sizeof(root
->entry
.data
.cFileName
[0]), IDS_DESKTOP
);
1352 wsprintfW(root
->entry
.data
.cFileName
, sTitleFmt
, drv
, root
->fs
);
1354 root
->entry
.data
.dwFileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1356 child
->left
.root
= &root
->entry
;
1357 child
->right
.root
= NULL
;
1359 set_curdir(child
, entry
, 0, hwnd
);
1365 /* free all memory associated with a child window */
1366 static void free_child_window(ChildWnd
* child
)
1368 free_entries(&child
->root
.entry
);
1369 HeapFree(GetProcessHeap(), 0, child
);
1373 /* get full path of specified directory entry */
1374 static void get_path(Entry
* dir
, PWSTR path
)
1380 if (dir
->etype
== ET_SHELL
)
1390 hr
= IShellFolder_GetAttributesOf(dir
->folder
, 1, (LPCITEMIDLIST
*)&dir
->pidl
, &attribs
);
1392 if (SUCCEEDED(hr
) && (attribs
&SFGAO_FILESYSTEM
)) {
1393 IShellFolder
* parent
= dir
->up
? dir
->up
->folder
: Globals
.iDesktop
;
1395 hr
= path_from_pidlW(parent
, dir
->pidl
, path
, MAX_PATH
);
1400 for(entry
=dir
; entry
; level
++) {
1406 name
= entry
->data
.cFileName
;
1409 for(l
=0; *s
&& *s
!= '/' && *s
!= '\\'; s
++)
1415 memmove(path
+l
+1, path
, len
*sizeof(WCHAR
));
1416 memcpy(path
+1, name
, l
*sizeof(WCHAR
));
1419 if (entry
->etype
== ET_UNIX
)
1427 memmove(path
+l
, path
, len
*sizeof(WCHAR
));
1428 memcpy(path
, name
, l
*sizeof(WCHAR
));
1435 if (entry
->etype
== ET_UNIX
)
1445 static windowOptions
load_registry_settings(void)
1453 RegOpenKeyExW( HKEY_CURRENT_USER
, registry_key
,
1454 0, KEY_QUERY_VALUE
, &hKey
);
1456 size
= sizeof(DWORD
);
1458 if( RegQueryValueExW( hKey
, reg_start_x
, NULL
, &type
,
1459 (LPBYTE
) &opts
.start_x
, &size
) != ERROR_SUCCESS
)
1460 opts
.start_x
= CW_USEDEFAULT
;
1462 if( RegQueryValueExW( hKey
, reg_start_y
, NULL
, &type
,
1463 (LPBYTE
) &opts
.start_y
, &size
) != ERROR_SUCCESS
)
1464 opts
.start_y
= CW_USEDEFAULT
;
1466 if( RegQueryValueExW( hKey
, reg_width
, NULL
, &type
,
1467 (LPBYTE
) &opts
.width
, &size
) != ERROR_SUCCESS
)
1468 opts
.width
= CW_USEDEFAULT
;
1470 if( RegQueryValueExW( hKey
, reg_height
, NULL
, &type
,
1471 (LPBYTE
) &opts
.height
, &size
) != ERROR_SUCCESS
)
1472 opts
.height
= CW_USEDEFAULT
;
1473 size
=sizeof(logfont
);
1474 if( RegQueryValueExW( hKey
, reg_logfont
, NULL
, &type
,
1475 (LPBYTE
) &logfont
, &size
) != ERROR_SUCCESS
)
1476 GetObjectW(GetStockObject(DEFAULT_GUI_FONT
),sizeof(logfont
),&logfont
);
1478 RegCloseKey( hKey
);
1480 Globals
.hfont
= CreateFontIndirectW(&logfont
);
1484 static void save_registry_settings(void)
1491 wi
.cbSize
= sizeof( WINDOWINFO
);
1492 GetWindowInfo(Globals
.hMainWnd
, &wi
);
1493 width
= wi
.rcWindow
.right
- wi
.rcWindow
.left
;
1494 height
= wi
.rcWindow
.bottom
- wi
.rcWindow
.top
;
1496 if ( RegOpenKeyExW( HKEY_CURRENT_USER
, registry_key
,
1497 0, KEY_SET_VALUE
, &hKey
) != ERROR_SUCCESS
)
1499 /* Unable to save registry settings - try to create key */
1500 if ( RegCreateKeyExW( HKEY_CURRENT_USER
, registry_key
,
1501 0, NULL
, REG_OPTION_NON_VOLATILE
,
1502 KEY_SET_VALUE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
1504 /* FIXME: Cannot create key */
1508 /* Save all of the settings */
1509 RegSetValueExW( hKey
, reg_start_x
, 0, REG_DWORD
,
1510 (LPBYTE
) &wi
.rcWindow
.left
, sizeof(DWORD
) );
1511 RegSetValueExW( hKey
, reg_start_y
, 0, REG_DWORD
,
1512 (LPBYTE
) &wi
.rcWindow
.top
, sizeof(DWORD
) );
1513 RegSetValueExW( hKey
, reg_width
, 0, REG_DWORD
,
1514 (LPBYTE
) &width
, sizeof(DWORD
) );
1515 RegSetValueExW( hKey
, reg_height
, 0, REG_DWORD
,
1516 (LPBYTE
) &height
, sizeof(DWORD
) );
1517 GetObjectW(Globals
.hfont
, sizeof(logfont
), &logfont
);
1518 RegSetValueExW( hKey
, reg_logfont
, 0, REG_BINARY
,
1519 (LPBYTE
)&logfont
, sizeof(LOGFONTW
) );
1521 /* TODO: Save more settings here (List vs. Detailed View, etc.) */
1522 RegCloseKey( hKey
);
1525 static void resize_frame_rect(HWND hwnd
, PRECT prect
)
1530 if (IsWindowVisible(Globals
.htoolbar
)) {
1531 SendMessageW(Globals
.htoolbar
, WM_SIZE
, 0, 0);
1532 GetClientRect(Globals
.htoolbar
, &rt
);
1533 prect
->top
= rt
.bottom
+3;
1534 prect
->bottom
-= rt
.bottom
+3;
1537 if (IsWindowVisible(Globals
.hdrivebar
)) {
1538 SendMessageW(Globals
.hdrivebar
, WM_SIZE
, 0, 0);
1539 GetClientRect(Globals
.hdrivebar
, &rt
);
1540 new_top
= --prect
->top
+ rt
.bottom
+3;
1541 MoveWindow(Globals
.hdrivebar
, 0, prect
->top
, rt
.right
, new_top
, TRUE
);
1542 prect
->top
= new_top
;
1543 prect
->bottom
-= rt
.bottom
+2;
1546 if (IsWindowVisible(Globals
.hstatusbar
)) {
1547 int parts
[] = {300, 500};
1549 SendMessageW(Globals
.hstatusbar
, WM_SIZE
, 0, 0);
1550 SendMessageW(Globals
.hstatusbar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
1551 GetClientRect(Globals
.hstatusbar
, &rt
);
1552 prect
->bottom
-= rt
.bottom
;
1555 MoveWindow(Globals
.hmdiclient
, prect
->left
-1,prect
->top
-1,prect
->right
+2,prect
->bottom
+1, TRUE
);
1558 static void resize_frame(HWND hwnd
, int cx
, int cy
)
1567 resize_frame_rect(hwnd
, &rect
);
1570 static void resize_frame_client(HWND hwnd
)
1574 GetClientRect(hwnd
, &rect
);
1576 resize_frame_rect(hwnd
, &rect
);
1580 static HHOOK hcbthook
;
1581 static ChildWnd
* newchild
= NULL
;
1583 static LRESULT CALLBACK
CBTProc(int code
, WPARAM wparam
, LPARAM lparam
)
1585 if (code
==HCBT_CREATEWND
&& newchild
) {
1586 ChildWnd
* child
= newchild
;
1589 child
->hwnd
= (HWND
) wparam
;
1590 SetWindowLongPtrW(child
->hwnd
, GWLP_USERDATA
, (LPARAM
)child
);
1593 return CallNextHookEx(hcbthook
, code
, wparam
, lparam
);
1596 static HWND
create_child_window(ChildWnd
* child
)
1598 MDICREATESTRUCTW mcs
;
1601 mcs
.szClass
= sWINEFILETREE
;
1602 mcs
.szTitle
= child
->path
;
1603 mcs
.hOwner
= Globals
.hInstance
;
1604 mcs
.x
= child
->pos
.rcNormalPosition
.left
;
1605 mcs
.y
= child
->pos
.rcNormalPosition
.top
;
1606 mcs
.cx
= child
->pos
.rcNormalPosition
.right
-child
->pos
.rcNormalPosition
.left
;
1607 mcs
.cy
= child
->pos
.rcNormalPosition
.bottom
-child
->pos
.rcNormalPosition
.top
;
1611 hcbthook
= SetWindowsHookExW(WH_CBT
, CBTProc
, 0, GetCurrentThreadId());
1614 child
->hwnd
= (HWND
)SendMessageW(Globals
.hmdiclient
, WM_MDICREATE
, 0, (LPARAM
)&mcs
);
1616 UnhookWindowsHookEx(hcbthook
);
1620 UnhookWindowsHookEx(hcbthook
);
1622 SendMessageW(child
->left
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1623 SendMessageW(child
->right
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1625 idx
= SendMessageW(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)child
->left
.cur
);
1626 SendMessageW(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
1631 #define RFF_NODEFAULT 0x02 /* No default item selected. */
1633 static void WineFile_OnRun( HWND hwnd
)
1635 static const WCHAR shell32_dll
[] = {'S','H','E','L','L','3','2','.','D','L','L',0};
1636 void (WINAPI
*pRunFileDlgAW
)(HWND
, HICON
, LPWSTR
, LPWSTR
, LPWSTR
, DWORD
);
1637 HMODULE hshell
= GetModuleHandleW( shell32_dll
);
1638 HICON hIcon
= LoadIconW(Globals
.hInstance
, MAKEINTRESOURCEW(IDI_WINEFILE
));
1640 pRunFileDlgAW
= (void*)GetProcAddress(hshell
, (LPCSTR
)61);
1641 if (pRunFileDlgAW
) pRunFileDlgAW( hwnd
, hIcon
, NULL
, NULL
, NULL
, RFF_NODEFAULT
);
1644 static INT_PTR CALLBACK
DestinationDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1646 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1650 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, lparam
);
1651 SetWindowTextW(GetDlgItem(hwnd
, 201), (LPCWSTR
)lparam
);
1655 int id
= (int)wparam
;
1659 LPWSTR dest
= (LPWSTR
)GetWindowLongPtrW(hwnd
, GWLP_USERDATA
);
1660 GetWindowTextW(GetDlgItem(hwnd
, 201), dest
, MAX_PATH
);
1661 EndDialog(hwnd
, id
);
1665 EndDialog(hwnd
, id
);
1669 MessageBoxW(hwnd
, RS(b1
,IDS_NO_IMPL
), RS(b2
,IDS_WINEFILE
), MB_OK
);
1681 struct FilterDialog
{
1682 WCHAR pattern
[MAX_PATH
];
1686 static INT_PTR CALLBACK
FilterDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1688 static struct FilterDialog
* dlg
;
1692 dlg
= (struct FilterDialog
*) lparam
;
1693 SetWindowTextW(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
);
1694 set_check(hwnd
, IDC_VIEW_TYPE_DIRECTORIES
, dlg
->flags
&TF_DIRECTORIES
);
1695 set_check(hwnd
, IDC_VIEW_TYPE_PROGRAMS
, dlg
->flags
&TF_PROGRAMS
);
1696 set_check(hwnd
, IDC_VIEW_TYPE_DOCUMENTS
, dlg
->flags
&TF_DOCUMENTS
);
1697 set_check(hwnd
, IDC_VIEW_TYPE_OTHERS
, dlg
->flags
&TF_OTHERS
);
1698 set_check(hwnd
, IDC_VIEW_TYPE_HIDDEN
, dlg
->flags
&TF_HIDDEN
);
1702 int id
= (int)wparam
;
1707 GetWindowTextW(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
, MAX_PATH
);
1709 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_DIRECTORIES
) ? TF_DIRECTORIES
: 0;
1710 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_PROGRAMS
) ? TF_PROGRAMS
: 0;
1711 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_DOCUMENTS
) ? TF_DOCUMENTS
: 0;
1712 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_OTHERS
) ? TF_OTHERS
: 0;
1713 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_HIDDEN
) ? TF_HIDDEN
: 0;
1717 EndDialog(hwnd
, id
);
1718 } else if (id
== IDCANCEL
)
1719 EndDialog(hwnd
, id
);
1728 struct PropertiesDialog
{
1729 WCHAR path
[MAX_PATH
];
1734 /* Structure used to store enumerated languages and code pages. */
1735 struct LANGANDCODEPAGE
{
1740 static LPCSTR InfoStrings
[] = {
1756 static void PropDlg_DisplayValue(HWND hlbox
, HWND hedit
)
1758 int idx
= SendMessageW(hlbox
, LB_GETCURSEL
, 0, 0);
1760 if (idx
!= LB_ERR
) {
1761 LPCWSTR pValue
= (LPCWSTR
)SendMessageW(hlbox
, LB_GETITEMDATA
, idx
, 0);
1764 SetWindowTextW(hedit
, pValue
);
1768 static void CheckForFileInfo(struct PropertiesDialog
* dlg
, HWND hwnd
, LPCWSTR strFilename
)
1770 static const WCHAR sBackSlash
[] = {'\\','\0'};
1771 static const WCHAR sTranslation
[] = {'\\','V','a','r','F','i','l','e','I','n','f','o','\\','T','r','a','n','s','l','a','t','i','o','n','\0'};
1772 static const WCHAR sStringFileInfo
[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1773 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1774 static const WCHAR sFmt
[] = {'%','d','.','%','d','.','%','d','.','%','d','\0'};
1775 DWORD dwVersionDataLen
= GetFileVersionInfoSizeW(strFilename
, NULL
);
1777 if (dwVersionDataLen
) {
1778 dlg
->pVersionData
= HeapAlloc(GetProcessHeap(), 0, dwVersionDataLen
);
1780 if (GetFileVersionInfoW(strFilename
, 0, dwVersionDataLen
, dlg
->pVersionData
)) {
1784 if (VerQueryValueW(dlg
->pVersionData
, sBackSlash
, &pVal
, &nValLen
)) {
1785 if (nValLen
== sizeof(VS_FIXEDFILEINFO
)) {
1786 VS_FIXEDFILEINFO
* pFixedFileInfo
= (VS_FIXEDFILEINFO
*)pVal
;
1787 WCHAR buffer
[BUFFER_LEN
];
1789 sprintfW(buffer
, sFmt
,
1790 HIWORD(pFixedFileInfo
->dwFileVersionMS
), LOWORD(pFixedFileInfo
->dwFileVersionMS
),
1791 HIWORD(pFixedFileInfo
->dwFileVersionLS
), LOWORD(pFixedFileInfo
->dwFileVersionLS
));
1793 SetDlgItemTextW(hwnd
, IDC_STATIC_PROP_VERSION
, buffer
);
1797 /* Read the list of languages and code pages. */
1798 if (VerQueryValueW(dlg
->pVersionData
, sTranslation
, &pVal
, &nValLen
)) {
1799 struct LANGANDCODEPAGE
* pTranslate
= (struct LANGANDCODEPAGE
*)pVal
;
1800 struct LANGANDCODEPAGE
* pEnd
= (struct LANGANDCODEPAGE
*)((LPBYTE
)pVal
+nValLen
);
1802 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
1804 /* Read the file description for each language and code page. */
1805 for(; pTranslate
<pEnd
; ++pTranslate
) {
1808 for(p
=InfoStrings
; *p
; ++p
) {
1809 WCHAR subblock
[200];
1814 LPCSTR pInfoString
= *p
;
1815 MultiByteToWideChar(CP_ACP
, 0, pInfoString
, -1, infoStr
, 100);
1816 wsprintfW(subblock
, sStringFileInfo
, pTranslate
->wLanguage
, pTranslate
->wCodePage
, infoStr
);
1818 /* Retrieve file description for language and code page */
1819 if (VerQueryValueW(dlg
->pVersionData
, subblock
, (PVOID
)&pTxt
, &nValLen
)) {
1820 int idx
= SendMessageW(hlbox
, LB_ADDSTRING
, 0L, (LPARAM
)infoStr
);
1821 SendMessageW(hlbox
, LB_SETITEMDATA
, idx
, (LPARAM
)pTxt
);
1826 SendMessageW(hlbox
, LB_SETCURSEL
, 0, 0);
1828 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
1834 static INT_PTR CALLBACK
PropertiesDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1836 static struct PropertiesDialog
* dlg
;
1839 case WM_INITDIALOG
: {
1840 static const WCHAR sByteFmt
[] = {'%','s',' ','B','y','t','e','s','\0'};
1841 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1842 LPWIN32_FIND_DATAW pWFD
;
1844 dlg
= (struct PropertiesDialog
*) lparam
;
1845 pWFD
= (LPWIN32_FIND_DATAW
)&dlg
->entry
.data
;
1847 GetWindowTextW(hwnd
, b1
, MAX_PATH
);
1848 wsprintfW(b2
, b1
, pWFD
->cFileName
);
1849 SetWindowTextW(hwnd
, b2
);
1851 format_date(&pWFD
->ftLastWriteTime
, b1
, COL_DATE
|COL_TIME
);
1852 SetWindowTextW(GetDlgItem(hwnd
, IDC_STATIC_PROP_LASTCHANGE
), b1
);
1854 format_longlong( b1
, ((ULONGLONG
)pWFD
->nFileSizeHigh
<< 32) | pWFD
->nFileSizeLow
);
1855 wsprintfW(b2
, sByteFmt
, b1
);
1856 SetWindowTextW(GetDlgItem(hwnd
, IDC_STATIC_PROP_SIZE
), b2
);
1858 SetWindowTextW(GetDlgItem(hwnd
, IDC_STATIC_PROP_FILENAME
), pWFD
->cFileName
);
1859 SetWindowTextW(GetDlgItem(hwnd
, IDC_STATIC_PROP_PATH
), dlg
->path
);
1861 set_check(hwnd
, IDC_CHECK_READONLY
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_READONLY
);
1862 set_check(hwnd
, IDC_CHECK_ARCHIVE
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_ARCHIVE
);
1863 set_check(hwnd
, IDC_CHECK_COMPRESSED
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_COMPRESSED
);
1864 set_check(hwnd
, IDC_CHECK_HIDDEN
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_HIDDEN
);
1865 set_check(hwnd
, IDC_CHECK_SYSTEM
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_SYSTEM
);
1867 CheckForFileInfo(dlg
, hwnd
, dlg
->path
);
1871 int id
= (int)wparam
;
1873 switch(HIWORD(wparam
)) {
1874 case LBN_SELCHANGE
: {
1875 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
1876 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
1881 if (id
==IDOK
|| id
==IDCANCEL
)
1882 EndDialog(hwnd
, id
);
1888 HeapFree(GetProcessHeap(), 0, dlg
->pVersionData
);
1889 dlg
->pVersionData
= NULL
;
1896 static void show_properties_dlg(Entry
* entry
, HWND hwnd
)
1898 struct PropertiesDialog dlg
;
1900 memset(&dlg
, 0, sizeof(struct PropertiesDialog
));
1901 get_path(entry
, dlg
.path
);
1902 memcpy(&dlg
.entry
, entry
, sizeof(Entry
));
1904 DialogBoxParamW(Globals
.hInstance
, MAKEINTRESOURCEW(IDD_DIALOG_PROPERTIES
), hwnd
, PropertiesDialogDlgProc
, (LPARAM
)&dlg
);
1907 static struct FullScreenParameters
{
1917 static void frame_get_clientspace(HWND hwnd
, PRECT prect
)
1921 if (!IsIconic(hwnd
))
1922 GetClientRect(hwnd
, prect
);
1926 wp
.length
= sizeof(wp
);
1927 GetWindowPlacement(hwnd
, &wp
);
1929 prect
->left
= prect
->top
= 0;
1930 prect
->right
= wp
.rcNormalPosition
.right
-wp
.rcNormalPosition
.left
-
1931 2*(GetSystemMetrics(SM_CXSIZEFRAME
)+GetSystemMetrics(SM_CXEDGE
));
1932 prect
->bottom
= wp
.rcNormalPosition
.bottom
-wp
.rcNormalPosition
.top
-
1933 2*(GetSystemMetrics(SM_CYSIZEFRAME
)+GetSystemMetrics(SM_CYEDGE
))-
1934 GetSystemMetrics(SM_CYCAPTION
)-GetSystemMetrics(SM_CYMENUSIZE
);
1937 if (IsWindowVisible(Globals
.htoolbar
)) {
1938 GetClientRect(Globals
.htoolbar
, &rt
);
1939 prect
->top
+= rt
.bottom
+2;
1942 if (IsWindowVisible(Globals
.hdrivebar
)) {
1943 GetClientRect(Globals
.hdrivebar
, &rt
);
1944 prect
->top
+= rt
.bottom
+2;
1947 if (IsWindowVisible(Globals
.hstatusbar
)) {
1948 GetClientRect(Globals
.hstatusbar
, &rt
);
1949 prect
->bottom
-= rt
.bottom
;
1953 static BOOL
toggle_fullscreen(HWND hwnd
)
1957 if ((g_fullscreen
.mode
=!g_fullscreen
.mode
)) {
1958 GetWindowRect(hwnd
, &g_fullscreen
.orgPos
);
1959 g_fullscreen
.wasZoomed
= IsZoomed(hwnd
);
1961 Frame_CalcFrameClient(hwnd
, &rt
);
1962 MapWindowPoints( hwnd
, 0, (POINT
*)&rt
, 2 );
1964 rt
.left
= g_fullscreen
.orgPos
.left
-rt
.left
;
1965 rt
.top
= g_fullscreen
.orgPos
.top
-rt
.top
;
1966 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+g_fullscreen
.orgPos
.right
-rt
.right
;
1967 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+g_fullscreen
.orgPos
.bottom
-rt
.bottom
;
1969 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
1971 MoveWindow(hwnd
, g_fullscreen
.orgPos
.left
, g_fullscreen
.orgPos
.top
,
1972 g_fullscreen
.orgPos
.right
-g_fullscreen
.orgPos
.left
,
1973 g_fullscreen
.orgPos
.bottom
-g_fullscreen
.orgPos
.top
, TRUE
);
1975 if (g_fullscreen
.wasZoomed
)
1976 ShowWindow(hwnd
, WS_MAXIMIZE
);
1979 return g_fullscreen
.mode
;
1982 static void fullscreen_move(HWND hwnd
)
1985 GetWindowRect(hwnd
, &pos
);
1987 Frame_CalcFrameClient(hwnd
, &rt
);
1988 MapWindowPoints( hwnd
, 0, (POINT
*)&rt
, 2 );
1990 rt
.left
= pos
.left
-rt
.left
;
1991 rt
.top
= pos
.top
-rt
.top
;
1992 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+pos
.right
-rt
.right
;
1993 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+pos
.bottom
-rt
.bottom
;
1995 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
1998 static void toggle_child(HWND hwnd
, UINT cmd
, HWND hchild
)
2000 BOOL vis
= IsWindowVisible(hchild
);
2002 CheckMenuItem(Globals
.hMenuOptions
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
2004 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
2006 if (g_fullscreen
.mode
)
2007 fullscreen_move(hwnd
);
2009 resize_frame_client(hwnd
);
2012 static BOOL
activate_drive_window(LPCWSTR path
)
2014 WCHAR drv1
[_MAX_DRIVE
], drv2
[_MAX_DRIVE
];
2017 _wsplitpath(path
, drv1
, 0, 0, 0);
2019 /* search for an already open window for the same drive */
2020 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2021 ChildWnd
* child
= (ChildWnd
*)GetWindowLongPtrW(child_wnd
, GWLP_USERDATA
);
2024 _wsplitpath(child
->root
.path
, drv2
, 0, 0, 0);
2026 if (!lstrcmpiW(drv2
, drv1
)) {
2027 SendMessageW(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2029 if (IsIconic(child_wnd
))
2030 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2040 static BOOL
activate_fs_window(LPCWSTR filesys
)
2044 /* search for an already open window of the given file system name */
2045 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2046 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtrW(child_wnd
, GWLP_USERDATA
);
2049 if (!lstrcmpiW(child
->root
.fs
, filesys
)) {
2050 SendMessageW(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2052 if (IsIconic(child_wnd
))
2053 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2063 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
2065 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2069 if (Globals
.saveSettings
)
2070 save_registry_settings();
2072 DestroyWindow(hwnd
);
2074 /* clear handle variables */
2075 Globals
.hMenuFrame
= 0;
2076 Globals
.hMenuView
= 0;
2077 Globals
.hMenuOptions
= 0;
2078 Globals
.hMainWnd
= 0;
2079 Globals
.hmdiclient
= 0;
2080 Globals
.hdrivebar
= 0;
2087 case WM_INITMENUPOPUP
: {
2088 HWND hwndClient
= (HWND
)SendMessageW(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2090 if (!SendMessageW(hwndClient
, WM_INITMENUPOPUP
, wparam
, lparam
))
2095 UINT cmd
= LOWORD(wparam
);
2096 HWND hwndClient
= (HWND
)SendMessageW(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2098 if (SendMessageW(hwndClient
, WM_DISPATCH_COMMAND
, wparam
, lparam
))
2101 if (cmd
>=ID_DRIVE_FIRST
&& cmd
<=ID_DRIVE_FIRST
+0xFF) {
2102 WCHAR drv
[_MAX_DRIVE
], path
[MAX_PATH
];
2104 LPCWSTR root
= Globals
.drives
;
2107 for(i
=cmd
-ID_DRIVE_FIRST
; i
--; root
++)
2111 if (activate_drive_window(root
))
2114 _wsplitpath(root
, drv
, 0, 0, 0);
2116 if (!SetCurrentDirectoryW(drv
)) {
2117 display_error(hwnd
, GetLastError());
2121 GetCurrentDirectoryW(MAX_PATH
, path
); /*TODO: store last directory per drive */
2122 child
= alloc_child_window(path
, NULL
, hwnd
);
2124 if (!create_child_window(child
))
2125 HeapFree(GetProcessHeap(), 0, child
);
2126 } else switch(cmd
) {
2128 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
2131 case ID_WINDOW_NEW
: {
2132 WCHAR path
[MAX_PATH
];
2135 GetCurrentDirectoryW(MAX_PATH
, path
);
2136 child
= alloc_child_window(path
, NULL
, hwnd
);
2138 if (!create_child_window(child
))
2139 HeapFree(GetProcessHeap(), 0, child
);
2146 case ID_WINDOW_CASCADE
:
2147 SendMessageW(Globals
.hmdiclient
, WM_MDICASCADE
, 0, 0);
2150 case ID_WINDOW_TILE_HORZ
:
2151 SendMessageW(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
2154 case ID_WINDOW_TILE_VERT
:
2155 SendMessageW(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
2158 case ID_WINDOW_ARRANGE
:
2159 SendMessageW(Globals
.hmdiclient
, WM_MDIICONARRANGE
, 0, 0);
2162 case ID_SELECT_FONT
:
2166 case ID_VIEW_TOOL_BAR
:
2167 toggle_child(hwnd
, cmd
, Globals
.htoolbar
);
2170 case ID_VIEW_DRIVE_BAR
:
2171 toggle_child(hwnd
, cmd
, Globals
.hdrivebar
);
2174 case ID_VIEW_STATUSBAR
:
2175 toggle_child(hwnd
, cmd
, Globals
.hstatusbar
);
2178 case ID_VIEW_SAVESETTINGS
:
2179 Globals
.saveSettings
= !Globals
.saveSettings
;
2180 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_SAVESETTINGS
,
2181 Globals
.saveSettings
? MF_CHECKED
: MF_UNCHECKED
);
2185 WineFile_OnRun( hwnd
);
2188 case ID_CONNECT_NETWORK_DRIVE
: {
2189 DWORD ret
= WNetConnectionDialog(hwnd
, RESOURCETYPE_DISK
);
2190 if (ret
== NO_ERROR
)
2192 else if (ret
!= (DWORD
)-1) {
2193 if (ret
== ERROR_EXTENDED_ERROR
)
2194 display_network_error(hwnd
);
2196 display_error(hwnd
, ret
);
2200 case ID_DISCONNECT_NETWORK_DRIVE
: {
2201 DWORD ret
= WNetDisconnectDialog(hwnd
, RESOURCETYPE_DISK
);
2202 if (ret
== NO_ERROR
)
2204 else if (ret
!= (DWORD
)-1) {
2205 if (ret
== ERROR_EXTENDED_ERROR
)
2206 display_network_error(hwnd
);
2208 display_error(hwnd
, ret
);
2213 WinHelpW(hwnd
, RS(b1
,IDS_WINEFILE
), HELP_INDEX
, 0);
2216 case ID_VIEW_FULLSCREEN
:
2217 CheckMenuItem(Globals
.hMenuOptions
, cmd
, toggle_fullscreen(hwnd
)?MF_CHECKED
:0);
2221 case ID_DRIVE_UNIX_FS
: {
2222 WCHAR path
[MAX_PATH
];
2223 char cpath
[MAX_PATH
];
2226 if (activate_fs_window(RS(b1
,IDS_UNIXFS
)))
2229 getcwd(cpath
, MAX_PATH
);
2230 MultiByteToWideChar(CP_UNIXCP
, 0, cpath
, -1, path
, MAX_PATH
);
2231 child
= alloc_child_window(path
, NULL
, hwnd
);
2233 if (!create_child_window(child
))
2234 HeapFree(GetProcessHeap(), 0, child
);
2237 case ID_DRIVE_SHELL_NS
: {
2238 WCHAR path
[MAX_PATH
];
2241 if (activate_fs_window(RS(b1
,IDS_SHELL
)))
2244 GetCurrentDirectoryW(MAX_PATH
, path
);
2245 child
= alloc_child_window(path
, get_path_pidl(path
,hwnd
), hwnd
);
2247 if (!create_child_window(child
))
2248 HeapFree(GetProcessHeap(), 0, child
);
2251 /*TODO: There are even more menu items! */
2254 ShellAboutW(hwnd
, RS(b1
,IDS_WINEFILE
), NULL
,
2255 LoadImageW( Globals
.hInstance
, MAKEINTRESOURCEW(IDI_WINEFILE
),
2256 IMAGE_ICON
, 48, 48, LR_SHARED
));
2260 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2261 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2262 else */if ((cmd
<IDW_FIRST_CHILD
|| cmd
>=IDW_FIRST_CHILD
+0x100) &&
2263 (cmd
<SC_SIZE
|| cmd
>SC_RESTORE
))
2264 MessageBoxW(hwnd
, RS(b2
,IDS_NO_IMPL
), RS(b1
,IDS_WINEFILE
), MB_OK
);
2266 return DefFrameProcW(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2271 resize_frame(hwnd
, LOWORD(lparam
), HIWORD(lparam
));
2272 break; /* do not pass message to DefFrameProcW */
2274 case WM_DEVICECHANGE
:
2275 SendMessageW(hwnd
, WM_COMMAND
, MAKELONG(ID_REFRESH
,0), 0);
2278 case WM_GETMINMAXINFO
: {
2279 LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
2281 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2282 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2285 case FRM_CALC_CLIENT
:
2286 frame_get_clientspace(hwnd
, (PRECT
)lparam
);
2290 return DefFrameProcW(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2297 static WCHAR g_pos_names
[COLUMNS
][40] = {
2301 static const int g_pos_align
[] = {
2303 HDF_LEFT
, /* Name */
2304 HDF_RIGHT
, /* Size */
2305 HDF_LEFT
, /* CDate */
2306 HDF_LEFT
, /* ADate */
2307 HDF_LEFT
, /* MDate */
2308 HDF_LEFT
, /* Index */
2309 HDF_CENTER
, /* Links */
2310 HDF_CENTER
, /* Attributes */
2311 HDF_LEFT
/* Security */
2314 static void resize_tree(ChildWnd
* child
, int cx
, int cy
)
2316 HDWP hdwp
= BeginDeferWindowPos(4);
2326 cx
= child
->split_pos
+ SPLIT_WIDTH
/2;
2330 SendMessageW(child
->left
.hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hdl
);
2332 DeferWindowPos(hdwp
, child
->left
.hwndHeader
, wp
.hwndInsertAfter
,
2333 wp
.x
-1, wp
.y
, child
->split_pos
-SPLIT_WIDTH
/2+1, wp
.cy
, wp
.flags
);
2334 DeferWindowPos(hdwp
, child
->right
.hwndHeader
, wp
.hwndInsertAfter
,
2335 rt
.left
+cx
+1, wp
.y
, wp
.cx
-cx
+2, wp
.cy
, wp
.flags
);
2336 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
);
2337 DeferWindowPos(hdwp
, child
->right
.hwnd
, 0, rt
.left
+cx
+1, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
2339 EndDeferWindowPos(hdwp
);
2342 static HWND
create_header(HWND parent
, Pane
* pane
, UINT id
)
2347 HWND hwnd
= CreateWindowW(WC_HEADERW
, 0, WS_CHILD
|WS_VISIBLE
|HDS_HORZ
|HDS_FULLDRAG
/*TODO: |HDS_BUTTONS + sort orders*/,
2348 0, 0, 0, 0, parent
, (HMENU
)ULongToHandle(id
), Globals
.hInstance
, 0);
2352 SendMessageW(hwnd
, WM_SETFONT
, (WPARAM
)GetStockObject(DEFAULT_GUI_FONT
), FALSE
);
2354 hdi
.mask
= HDI_TEXT
|HDI_WIDTH
|HDI_FORMAT
;
2356 for(idx
=0; idx
<COLUMNS
; idx
++) {
2357 hdi
.pszText
= g_pos_names
[idx
];
2358 hdi
.fmt
= HDF_STRING
| g_pos_align
[idx
];
2359 hdi
.cxy
= pane
->widths
[idx
];
2360 pane
->widths_shown
[idx
] = hdi
.cxy
;
2361 SendMessageW(hwnd
, HDM_INSERTITEMW
, idx
, (LPARAM
)&hdi
);
2367 static void init_output(HWND hwnd
)
2369 static const WCHAR s1000
[] = {'1','0','0','0','\0'};
2372 HDC hdc
= GetDC(hwnd
);
2374 if (GetNumberFormatW(LOCALE_USER_DEFAULT
, 0, s1000
, 0, b
, 16) > 4)
2375 Globals
.num_sep
= b
[1];
2377 Globals
.num_sep
= '.';
2379 old_font
= SelectObject(hdc
, Globals
.hfont
);
2380 GetTextExtentPoint32W(hdc
, sSpace
, 1, &Globals
.spaceSize
);
2381 SelectObject(hdc
, old_font
);
2382 ReleaseDC(hwnd
, hdc
);
2385 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
);
2388 /* calculate preferred width for all visible columns */
2390 static BOOL
calc_widths(Pane
* pane
, BOOL anyway
)
2392 int col
, x
, cx
, spc
=3*Globals
.spaceSize
.cx
;
2393 int entries
= SendMessageW(pane
->hwnd
, LB_GETCOUNT
, 0, 0);
2394 int orgWidths
[COLUMNS
];
2395 int orgPositions
[COLUMNS
+1];
2401 memcpy(orgWidths
, pane
->widths
, sizeof(orgWidths
));
2402 memcpy(orgPositions
, pane
->positions
, sizeof(orgPositions
));
2405 for(col
=0; col
<COLUMNS
; col
++)
2406 pane
->widths
[col
] = 0;
2408 hdc
= GetDC(pane
->hwnd
);
2409 hfontOld
= SelectObject(hdc
, Globals
.hfont
);
2411 for(cnt
=0; cnt
<entries
; cnt
++) {
2412 Entry
* entry
= (Entry
*)SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, cnt
, 0);
2421 dis
.hwndItem
= pane
->hwnd
;
2423 SetRectEmpty(&dis
.rcItem
);
2424 /*dis.itemData = 0; */
2426 draw_item(pane
, &dis
, entry
, COLUMNS
);
2429 SelectObject(hdc
, hfontOld
);
2430 ReleaseDC(pane
->hwnd
, hdc
);
2433 for(col
=0; col
<COLUMNS
; col
++) {
2434 pane
->positions
[col
] = x
;
2435 cx
= pane
->widths
[col
];
2440 if (cx
< IMAGE_WIDTH
)
2443 pane
->widths
[col
] = cx
;
2449 pane
->positions
[COLUMNS
] = x
;
2451 SendMessageW(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, x
, 0);
2454 if (!anyway
&& !memcmp(orgWidths
, pane
->widths
, sizeof(orgWidths
)))
2457 /* don't move, if only collapsing an entry */
2458 if (!anyway
&& pane
->widths
[0]<orgWidths
[0] &&
2459 !memcmp(orgWidths
+1, pane
->widths
+1, sizeof(orgWidths
)-sizeof(int))) {
2460 pane
->widths
[0] = orgWidths
[0];
2461 memcpy(pane
->positions
, orgPositions
, sizeof(orgPositions
));
2466 InvalidateRect(pane
->hwnd
, 0, TRUE
);
2471 /* calculate one preferred column width */
2472 static void calc_single_width(Pane
* pane
, int col
)
2476 int entries
= SendMessageW(pane
->hwnd
, LB_GETCOUNT
, 0, 0);
2480 pane
->widths
[col
] = 0;
2482 hdc
= GetDC(pane
->hwnd
);
2483 hfontOld
= SelectObject(hdc
, Globals
.hfont
);
2485 for(cnt
=0; cnt
<entries
; cnt
++) {
2486 Entry
* entry
= (Entry
*)SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, cnt
, 0);
2494 dis
.hwndItem
= pane
->hwnd
;
2496 SetRectEmpty(&dis
.rcItem
);
2497 /*dis.itemData = 0; */
2499 draw_item(pane
, &dis
, entry
, col
);
2502 SelectObject(hdc
, hfontOld
);
2503 ReleaseDC(pane
->hwnd
, hdc
);
2505 cx
= pane
->widths
[col
];
2508 cx
+= 3*Globals
.spaceSize
.cx
;
2510 if (cx
< IMAGE_WIDTH
)
2514 pane
->widths
[col
] = cx
;
2516 x
= pane
->positions
[col
] + cx
;
2518 for(; col
<COLUMNS
-1; ) {
2519 pane
->positions
[++col
] = x
;
2520 x
+= pane
->widths
[col
];
2523 SendMessageW(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, x
, 0);
2526 static BOOL
pattern_match(LPCWSTR str
, LPCWSTR pattern
)
2528 for( ; *str
&&*pattern
; str
++,pattern
++) {
2529 if (*pattern
== '*') {
2531 while(*pattern
== '*');
2537 if (*str
==*pattern
&& pattern_match(str
, pattern
))
2542 else if (*str
!=*pattern
&& *pattern
!='?')
2546 if (*str
|| *pattern
)
2547 if (*pattern
!='*' || pattern
[1]!='\0')
2553 static BOOL
pattern_imatch(LPCWSTR str
, LPCWSTR pattern
)
2555 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2558 lstrcpyW(b2
, pattern
);
2562 return pattern_match(b1
, b2
);
2572 static enum FILE_TYPE
get_file_type(LPCWSTR filename
);
2575 /* insert listbox entries after index idx */
2577 static int insert_entries(Pane
* pane
, Entry
* dir
, LPCWSTR pattern
, int filter_flags
, int idx
)
2584 ShowWindow(pane
->hwnd
, SW_HIDE
);
2586 for(; entry
; entry
=entry
->next
) {
2587 if (pane
->treePane
&& !(entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
2590 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
2591 /* don't display entries "." and ".." in the left pane */
2592 if (pane
->treePane
&& entry
->data
.cFileName
[0] == '.')
2593 if (entry
->data
.cFileName
[1] == '\0' ||
2594 (entry
->data
.cFileName
[1] == '.' &&
2595 entry
->data
.cFileName
[2] == '\0'))
2598 /* filter directories in right pane */
2599 if (!pane
->treePane
&& !(filter_flags
&TF_DIRECTORIES
))
2603 /* filter using the file name pattern */
2605 if (!pattern_imatch(entry
->data
.cFileName
, pattern
))
2608 /* filter system and hidden files */
2609 if (!(filter_flags
&TF_HIDDEN
) && (entry
->data
.dwFileAttributes
&(FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
)))
2612 /* filter looking at the file type */
2613 if ((filter_flags
&(TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
)) != (TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
))
2614 switch(get_file_type(entry
->data
.cFileName
)) {
2616 if (!(filter_flags
& TF_PROGRAMS
))
2621 if (!(filter_flags
& TF_DOCUMENTS
))
2625 default: /* TF_OTHERS */
2626 if (!(filter_flags
& TF_OTHERS
))
2633 SendMessageW(pane
->hwnd
, LB_INSERTSTRING
, idx
, (LPARAM
)entry
);
2635 if (pane
->treePane
&& entry
->expanded
)
2636 idx
= insert_entries(pane
, entry
->down
, pattern
, filter_flags
, idx
);
2639 ShowWindow(pane
->hwnd
, SW_SHOW
);
2644 static void set_space_status(void)
2646 ULARGE_INTEGER ulFreeBytesToCaller
, ulTotalBytes
, ulFreeBytes
;
2647 WCHAR fmt
[64], b1
[64], b2
[64], buffer
[BUFFER_LEN
];
2649 if (GetDiskFreeSpaceExW(NULL
, &ulFreeBytesToCaller
, &ulTotalBytes
, &ulFreeBytes
)) {
2652 args
[0] = (DWORD_PTR
)StrFormatByteSizeW(ulFreeBytesToCaller
.QuadPart
, b1
, sizeof(b1
)/sizeof(*b1
));
2653 args
[1] = (DWORD_PTR
)StrFormatByteSizeW(ulTotalBytes
.QuadPart
, b2
, sizeof(b2
)/sizeof(*b2
));
2655 FormatMessageW(FORMAT_MESSAGE_FROM_STRING
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
2656 RS(fmt
,IDS_FREE_SPACE_FMT
), 0, 0, buffer
,
2657 sizeof(buffer
)/sizeof(*buffer
), (__ms_va_list
*)args
);
2659 lstrcpyW(buffer
, sQMarks
);
2661 SendMessageW(Globals
.hstatusbar
, SB_SETTEXTW
, 0, (LPARAM
)buffer
);
2665 static WNDPROC g_orgTreeWndProc
;
2667 static void create_tree_window(HWND parent
, Pane
* pane
, UINT id
, UINT id_header
, LPCWSTR pattern
, int filter_flags
)
2669 static const WCHAR sListBox
[] = {'L','i','s','t','B','o','x','\0'};
2671 static BOOL s_init
= FALSE
;
2672 Entry
* entry
= pane
->root
;
2674 pane
->hwnd
= CreateWindowW(sListBox
, sEmpty
, WS_CHILD
|WS_VISIBLE
|WS_HSCROLL
|WS_VSCROLL
|
2675 LBS_DISABLENOSCROLL
|LBS_NOINTEGRALHEIGHT
|LBS_OWNERDRAWFIXED
|LBS_NOTIFY
,
2676 0, 0, 0, 0, parent
, (HMENU
)ULongToHandle(id
), Globals
.hInstance
, 0);
2678 SetWindowLongPtrW(pane
->hwnd
, GWLP_USERDATA
, (LPARAM
)pane
);
2679 g_orgTreeWndProc
= (WNDPROC
)SetWindowLongPtrW(pane
->hwnd
, GWLP_WNDPROC
, (LPARAM
)TreeWndProc
);
2681 SendMessageW(pane
->hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, FALSE
);
2683 /* insert entries into listbox */
2685 insert_entries(pane
, entry
, pattern
, filter_flags
, -1);
2687 /* calculate column widths */
2690 init_output(pane
->hwnd
);
2693 calc_widths(pane
, TRUE
);
2695 pane
->hwndHeader
= create_header(parent
, pane
, id_header
);
2699 static void InitChildWindow(ChildWnd
* child
)
2701 create_tree_window(child
->hwnd
, &child
->left
, IDW_TREE_LEFT
, IDW_HEADER_LEFT
, NULL
, TF_ALL
);
2702 create_tree_window(child
->hwnd
, &child
->right
, IDW_TREE_RIGHT
, IDW_HEADER_RIGHT
, child
->filter_pattern
, child
->filter_flags
);
2706 static void format_date(const FILETIME
* ft
, WCHAR
* buffer
, int visible_cols
)
2714 if (!ft
->dwLowDateTime
&& !ft
->dwHighDateTime
)
2717 if (!FileTimeToLocalFileTime(ft
, &lft
))
2718 {err
: lstrcpyW(buffer
,sQMarks
); return;}
2720 if (!FileTimeToSystemTime(&lft
, &systime
))
2723 if (visible_cols
& COL_DATE
) {
2724 len
= GetDateFormatW(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
, BUFFER_LEN
);
2729 if (visible_cols
& COL_TIME
) {
2731 buffer
[len
-1] = ' ';
2733 buffer
[len
++] = ' ';
2735 if (!GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
+len
, BUFFER_LEN
-len
))
2741 static void calc_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
)
2743 RECT rt
= {0, 0, 0, 0};
2745 DrawTextW(dis
->hDC
, str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
2747 if (rt
.right
> pane
->widths
[col
])
2748 pane
->widths
[col
] = rt
.right
;
2751 static void calc_tabbed_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
)
2753 RECT rt
= {0, 0, 0, 0};
2755 DrawTextW(dis
->hDC
, str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2756 /*FIXME rt (0,0) ??? */
2758 if (rt
.right
> pane
->widths
[col
])
2759 pane
->widths
[col
] = rt
.right
;
2763 static void output_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
, DWORD flags
)
2765 int x
= dis
->rcItem
.left
;
2768 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2769 rt
.top
= dis
->rcItem
.top
;
2770 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2771 rt
.bottom
= dis
->rcItem
.bottom
;
2773 DrawTextW(dis
->hDC
, str
, -1, &rt
, DT_SINGLELINE
|DT_NOPREFIX
|flags
);
2776 static void output_tabbed_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
)
2778 int x
= dis
->rcItem
.left
;
2781 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2782 rt
.top
= dis
->rcItem
.top
;
2783 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2784 rt
.bottom
= dis
->rcItem
.bottom
;
2786 DrawTextW(dis
->hDC
, str
, -1, &rt
, DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2789 static void output_number(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
)
2791 int x
= dis
->rcItem
.left
;
2798 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2799 rt
.top
= dis
->rcItem
.top
;
2800 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2801 rt
.bottom
= dis
->rcItem
.bottom
;
2806 /* insert number separator characters */
2807 pos
= lstrlenW(s
) % 3;
2813 *d
++ = Globals
.num_sep
;
2817 DrawTextW(dis
->hDC
, b
, d
-b
, &rt
, DT_RIGHT
|DT_SINGLELINE
|DT_NOPREFIX
|DT_END_ELLIPSIS
);
2821 static BOOL
is_exe_file(LPCWSTR ext
)
2823 static const WCHAR executable_extensions
[][4] = {
2834 WCHAR ext_buffer
[_MAX_EXT
];
2835 const WCHAR (*p
)[4];
2839 for(s
=ext
+1,d
=ext_buffer
; (*d
=tolower(*s
)); s
++)
2842 for(p
=executable_extensions
; (*p
)[0]; p
++)
2843 if (!lstrcmpiW(ext_buffer
, *p
))
2849 static BOOL
is_registered_type(LPCWSTR ext
)
2851 /* check if there exists a classname for this file extension in the registry */
2852 if (!RegQueryValueW(HKEY_CLASSES_ROOT
, ext
, NULL
, NULL
))
2858 static enum FILE_TYPE
get_file_type(LPCWSTR filename
)
2860 LPCWSTR ext
= strrchrW(filename
, '.');
2864 if (is_exe_file(ext
))
2865 return FT_EXECUTABLE
;
2866 else if (is_registered_type(ext
))
2873 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
)
2875 WCHAR buffer
[BUFFER_LEN
];
2877 int visible_cols
= pane
->visible_cols
;
2878 COLORREF bkcolor
, textcolor
;
2879 RECT focusRect
= dis
->rcItem
;
2886 attrs
= entry
->data
.dwFileAttributes
;
2888 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) {
2889 if (entry
->data
.cFileName
[0] == '.' && entry
->data
.cFileName
[1] == '.'
2890 && entry
->data
.cFileName
[2] == '\0')
2891 img
= IMG_FOLDER_UP
;
2892 else if (entry
->data
.cFileName
[0] == '.' && entry
->data
.cFileName
[1] == '\0')
2893 img
= IMG_FOLDER_CUR
;
2894 else if (pane
->treePane
&& (dis
->itemState
&ODS_FOCUS
))
2895 img
= IMG_OPEN_FOLDER
;
2899 switch(get_file_type(entry
->data
.cFileName
)) {
2900 case FT_EXECUTABLE
: img
= IMG_EXECUTABLE
; break;
2901 case FT_DOCUMENT
: img
= IMG_DOCUMENT
; break;
2902 default: img
= IMG_FILE
;
2910 if (pane
->treePane
) {
2912 img_pos
= dis
->rcItem
.left
+ entry
->level
*(IMAGE_WIDTH
+TREE_LINE_DX
);
2914 if (calcWidthCol
== -1) {
2916 int y
= dis
->rcItem
.top
+ IMAGE_HEIGHT
/2;
2919 HRGN hrgn_org
= CreateRectRgn(0, 0, 0, 0);
2922 rt_clip
.left
= dis
->rcItem
.left
;
2923 rt_clip
.top
= dis
->rcItem
.top
;
2924 rt_clip
.right
= dis
->rcItem
.left
+pane
->widths
[col
];
2925 rt_clip
.bottom
= dis
->rcItem
.bottom
;
2927 hrgn
= CreateRectRgnIndirect(&rt_clip
);
2929 if (!GetClipRgn(dis
->hDC
, hrgn_org
)) {
2930 DeleteObject(hrgn_org
);
2934 ExtSelectClipRgn(dis
->hDC
, hrgn
, RGN_AND
);
2937 if ((up
=entry
->up
) != NULL
) {
2938 MoveToEx(dis
->hDC
, img_pos
-IMAGE_WIDTH
/2, y
, 0);
2939 LineTo(dis
->hDC
, img_pos
-2, y
);
2941 x
= img_pos
- IMAGE_WIDTH
/2;
2944 x
-= IMAGE_WIDTH
+TREE_LINE_DX
;
2947 && (up
->next
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
2949 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
2950 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
2952 } while((up
=up
->up
) != NULL
);
2955 x
= img_pos
- IMAGE_WIDTH
/2;
2957 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
2958 LineTo(dis
->hDC
, x
, y
);
2961 && (entry
->next
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
2962 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
2964 SelectClipRgn(dis
->hDC
, hrgn_org
);
2965 if (hrgn_org
) DeleteObject(hrgn_org
);
2966 } else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
) {
2967 int right
= img_pos
+ IMAGE_WIDTH
- TREE_LINE_DX
;
2969 if (right
> pane
->widths
[col
])
2970 pane
->widths
[col
] = right
;
2973 img_pos
= dis
->rcItem
.left
;
2976 img_pos
= dis
->rcItem
.left
;
2978 if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2979 pane
->widths
[col
] = IMAGE_WIDTH
;
2982 if (calcWidthCol
== -1) {
2983 focusRect
.left
= img_pos
-2;
2985 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
)
2986 textcolor
= COLOR_COMPRESSED
;
2988 textcolor
= RGB(0,0,0);
2990 if (dis
->itemState
& ODS_FOCUS
) {
2991 textcolor
= RGB(255,255,255);
2992 bkcolor
= COLOR_SELECTION
;
2994 bkcolor
= RGB(255,255,255);
2997 hbrush
= CreateSolidBrush(bkcolor
);
2998 FillRect(dis
->hDC
, &focusRect
, hbrush
);
2999 DeleteObject(hbrush
);
3001 SetBkMode(dis
->hDC
, TRANSPARENT
);
3002 SetTextColor(dis
->hDC
, textcolor
);
3004 cx
= pane
->widths
[col
];
3006 if (cx
&& img
!=IMG_NONE
) {
3007 if (cx
> IMAGE_WIDTH
)
3010 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
3011 DrawIconEx(dis
->hDC
, img_pos
, dis
->rcItem
.top
, entry
->hicon
, cx
, GetSystemMetrics(SM_CYSMICON
), 0, 0, DI_NORMAL
);
3013 ImageList_DrawEx(Globals
.himl
, img
, dis
->hDC
,
3014 img_pos
, dis
->rcItem
.top
, cx
,
3015 IMAGE_HEIGHT
, bkcolor
, CLR_DEFAULT
, ILD_NORMAL
);
3024 /* output file name */
3025 if (calcWidthCol
== -1)
3026 output_text(pane
, dis
, col
, entry
->data
.cFileName
, 0);
3027 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3028 calc_width(pane
, dis
, col
, entry
->data
.cFileName
);
3032 /* display file size */
3033 if (visible_cols
& COL_SIZE
) {
3034 format_longlong( buffer
, ((ULONGLONG
)entry
->data
.nFileSizeHigh
<< 32) | entry
->data
.nFileSizeLow
);
3036 if (calcWidthCol
== -1)
3037 output_number(pane
, dis
, col
, buffer
);
3038 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3039 calc_width(pane
, dis
, col
, buffer
);/*TODO: not ever time enough */
3044 /* display file date */
3045 if (visible_cols
& (COL_DATE
|COL_TIME
)) {
3046 format_date(&entry
->data
.ftCreationTime
, buffer
, visible_cols
);
3047 if (calcWidthCol
== -1)
3048 output_text(pane
, dis
, col
, buffer
, 0);
3049 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3050 calc_width(pane
, dis
, col
, buffer
);
3053 format_date(&entry
->data
.ftLastAccessTime
, buffer
, visible_cols
);
3054 if (calcWidthCol
== -1)
3055 output_text(pane
, dis
, col
, buffer
, 0);
3056 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3057 calc_width(pane
, dis
, col
, buffer
);
3060 format_date(&entry
->data
.ftLastWriteTime
, buffer
, visible_cols
);
3061 if (calcWidthCol
== -1)
3062 output_text(pane
, dis
, col
, buffer
, 0);
3063 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3064 calc_width(pane
, dis
, col
, buffer
);
3068 if (entry
->bhfi_valid
) {
3069 if (visible_cols
& COL_INDEX
) {
3070 static const WCHAR fmtlow
[] = {'%','X',0};
3071 static const WCHAR fmthigh
[] = {'%','X','%','0','8','X',0};
3073 if (entry
->bhfi
.nFileIndexHigh
)
3074 wsprintfW(buffer
, fmthigh
,
3075 entry
->bhfi
.nFileIndexHigh
, entry
->bhfi
.nFileIndexLow
);
3077 wsprintfW(buffer
, fmtlow
, entry
->bhfi
.nFileIndexLow
);
3079 if (calcWidthCol
== -1)
3080 output_text(pane
, dis
, col
, buffer
, DT_RIGHT
);
3081 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3082 calc_width(pane
, dis
, col
, buffer
);
3087 if (visible_cols
& COL_LINKS
) {
3088 wsprintfW(buffer
, sNumFmt
, entry
->bhfi
.nNumberOfLinks
);
3090 if (calcWidthCol
== -1)
3091 output_text(pane
, dis
, col
, buffer
, DT_CENTER
);
3092 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3093 calc_width(pane
, dis
, col
, buffer
);
3100 /* show file attributes */
3101 if (visible_cols
& COL_ATTRIBUTES
) {
3102 static const WCHAR s11Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3103 lstrcpyW(buffer
, s11Tabs
);
3105 if (attrs
& FILE_ATTRIBUTE_NORMAL
) buffer
[ 0] = 'N';
3107 if (attrs
& FILE_ATTRIBUTE_READONLY
) buffer
[ 2] = 'R';
3108 if (attrs
& FILE_ATTRIBUTE_HIDDEN
) buffer
[ 4] = 'H';
3109 if (attrs
& FILE_ATTRIBUTE_SYSTEM
) buffer
[ 6] = 'S';
3110 if (attrs
& FILE_ATTRIBUTE_ARCHIVE
) buffer
[ 8] = 'A';
3111 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
) buffer
[10] = 'C';
3112 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) buffer
[12] = 'D';
3113 if (attrs
& FILE_ATTRIBUTE_ENCRYPTED
) buffer
[14] = 'E';
3114 if (attrs
& FILE_ATTRIBUTE_TEMPORARY
) buffer
[16] = 'T';
3115 if (attrs
& FILE_ATTRIBUTE_SPARSE_FILE
) buffer
[18] = 'P';
3116 if (attrs
& FILE_ATTRIBUTE_REPARSE_POINT
) buffer
[20] = 'Q';
3117 if (attrs
& FILE_ATTRIBUTE_OFFLINE
) buffer
[22] = 'O';
3118 if (attrs
& FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
) buffer
[24] = 'X';
3121 if (calcWidthCol
== -1)
3122 output_tabbed_text(pane
, dis
, col
, buffer
);
3123 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3124 calc_tabbed_width(pane
, dis
, col
, buffer
);
3130 static void set_header(Pane
* pane
)
3133 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3136 item
.mask
= HDI_WIDTH
;
3138 for (i
= 0; i
< COLUMNS
; ++i
) {
3139 if (pane
->positions
[i
] >= scroll_pos
) {
3140 item
.cxy
= pane
->widths
[i
];
3141 } else if (pane
->positions
[i
+1] <= scroll_pos
) {
3144 item
.cxy
= pane
->positions
[i
+1] - scroll_pos
;
3146 pane
->widths_shown
[i
] = item
.cxy
;
3147 SendMessageW(pane
->hwndHeader
, HDM_SETITEMW
, i
, (LPARAM
)&item
);
3151 static LRESULT
pane_notify(Pane
* pane
, NMHDR
* pnmh
)
3153 switch(pnmh
->code
) {
3154 case HDN_ITEMCHANGEDW
: {
3155 LPNMHEADERW phdn
= (LPNMHEADERW
)pnmh
;
3156 int idx
= phdn
->iItem
;
3157 int dx
= phdn
->pitem
->cxy
- pane
->widths_shown
[idx
];
3161 GetClientRect(pane
->hwnd
, &clnt
);
3163 pane
->widths
[idx
] += dx
;
3164 pane
->widths_shown
[idx
] += dx
;
3166 for(i
=idx
; ++i
<=COLUMNS
; )
3167 pane
->positions
[i
] += dx
;
3170 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3174 rt_scr
.left
= pane
->positions
[idx
+1]-scroll_pos
;
3176 rt_scr
.right
= clnt
.right
;
3177 rt_scr
.bottom
= clnt
.bottom
;
3179 rt_clip
.left
= pane
->positions
[idx
]-scroll_pos
;
3181 rt_clip
.right
= clnt
.right
;
3182 rt_clip
.bottom
= clnt
.bottom
;
3184 if (rt_scr
.left
< 0) rt_scr
.left
= 0;
3185 if (rt_clip
.left
< 0) rt_clip
.left
= 0;
3187 ScrollWindowEx(pane
->hwnd
, dx
, 0, &rt_scr
, &rt_clip
, 0, 0, SW_INVALIDATE
);
3189 rt_clip
.right
= pane
->positions
[idx
+1];
3190 RedrawWindow(pane
->hwnd
, &rt_clip
, 0, RDW_INVALIDATE
|RDW_UPDATENOW
);
3192 if (pnmh
->code
== HDN_ENDTRACKW
) {
3193 SendMessageW(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, pane
->positions
[COLUMNS
], 0);
3195 if (GetScrollPos(pane
->hwnd
, SB_HORZ
) != scroll_pos
)
3203 case HDN_DIVIDERDBLCLICKW
: {
3204 LPNMHEADERW phdn
= (LPNMHEADERW
)pnmh
;
3207 calc_single_width(pane
, phdn
->iItem
);
3208 item
.mask
= HDI_WIDTH
;
3209 item
.cxy
= pane
->widths
[phdn
->iItem
];
3211 SendMessageW(pane
->hwndHeader
, HDM_SETITEMW
, phdn
->iItem
, (LPARAM
)&item
);
3212 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3219 static void scan_entry(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3221 WCHAR path
[MAX_PATH
];
3222 HCURSOR old_cursor
= SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_WAIT
));
3224 /* delete sub entries in left pane */
3226 LRESULT res
= SendMessageW(child
->left
.hwnd
, LB_GETITEMDATA
, idx
+1, 0);
3227 Entry
* sub
= (Entry
*) res
;
3229 if (res
==LB_ERR
|| !sub
|| sub
->level
<=entry
->level
)
3232 SendMessageW(child
->left
.hwnd
, LB_DELETESTRING
, idx
+1, 0);
3235 /* empty right pane */
3236 SendMessageW(child
->right
.hwnd
, LB_RESETCONTENT
, 0, 0);
3238 /* release memory */
3239 free_entries(entry
);
3241 /* read contents from disk */
3242 if (entry
->etype
== ET_SHELL
)
3244 read_directory(entry
, NULL
, child
->sortOrder
, hwnd
);
3248 get_path(entry
, path
);
3249 read_directory(entry
, path
, child
->sortOrder
, hwnd
);
3252 /* insert found entries in right pane */
3253 insert_entries(&child
->right
, entry
->down
, child
->filter_pattern
, child
->filter_flags
, -1);
3254 calc_widths(&child
->right
, FALSE
);
3255 set_header(&child
->right
);
3257 child
->header_wdths_ok
= FALSE
;
3259 SetCursor(old_cursor
);
3263 /* expand a directory entry */
3265 static BOOL
expand_entry(ChildWnd
* child
, Entry
* dir
)
3270 if (!dir
|| dir
->expanded
|| !dir
->down
)
3275 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='\0' && p
->next
) {
3278 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='.' &&
3279 p
->data
.cFileName
[2]=='\0' && p
->next
)
3283 /* no subdirectories ? */
3284 if (!(p
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
3287 idx
= SendMessageW(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)dir
);
3289 dir
->expanded
= TRUE
;
3291 /* insert entries in left pane */
3292 insert_entries(&child
->left
, p
, NULL
, TF_ALL
, idx
);
3294 if (!child
->header_wdths_ok
) {
3295 if (calc_widths(&child
->left
, FALSE
)) {
3296 set_header(&child
->left
);
3298 child
->header_wdths_ok
= TRUE
;
3306 static void collapse_entry(Pane
* pane
, Entry
* dir
)
3311 idx
= SendMessageW(pane
->hwnd
, LB_FINDSTRING
, 0, (LPARAM
)dir
);
3313 ShowWindow(pane
->hwnd
, SW_HIDE
);
3315 /* hide sub entries */
3317 LRESULT res
= SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, idx
+1, 0);
3318 Entry
* sub
= (Entry
*) res
;
3320 if (res
==LB_ERR
|| !sub
|| sub
->level
<=dir
->level
)
3323 SendMessageW(pane
->hwnd
, LB_DELETESTRING
, idx
+1, 0);
3326 dir
->expanded
= FALSE
;
3328 ShowWindow(pane
->hwnd
, SW_SHOW
);
3332 static void refresh_right_pane(ChildWnd
* child
)
3334 SendMessageW(child
->right
.hwnd
, LB_RESETCONTENT
, 0, 0);
3335 insert_entries(&child
->right
, child
->right
.root
, child
->filter_pattern
, child
->filter_flags
, -1);
3336 calc_widths(&child
->right
, FALSE
);
3338 set_header(&child
->right
);
3341 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3343 WCHAR path
[MAX_PATH
];
3350 child
->left
.cur
= entry
;
3352 child
->right
.root
= entry
->down
? entry
->down
: entry
;
3353 child
->right
.cur
= entry
;
3355 if (!entry
->scanned
)
3356 scan_entry(child
, entry
, idx
, hwnd
);
3358 refresh_right_pane(child
);
3360 get_path(entry
, path
);
3361 lstrcpyW(child
->path
, path
);
3363 if (child
->hwnd
) /* only change window title, if the window already exists */
3364 SetWindowTextW(child
->hwnd
, path
);
3367 if (SetCurrentDirectoryW(path
))
3372 static void refresh_child(ChildWnd
* child
)
3374 WCHAR path
[MAX_PATH
], drv
[_MAX_DRIVE
+1];
3378 get_path(child
->left
.cur
, path
);
3379 _wsplitpath(path
, drv
, NULL
, NULL
, NULL
);
3381 child
->right
.root
= NULL
;
3383 scan_entry(child
, &child
->root
.entry
, 0, child
->hwnd
);
3385 if (child
->root
.entry
.etype
== ET_SHELL
)
3387 LPITEMIDLIST local_pidl
= get_path_pidl(path
,child
->hwnd
);
3389 entry
= read_tree(&child
->root
, NULL
, local_pidl
, drv
, child
->sortOrder
, child
->hwnd
);
3394 entry
= read_tree(&child
->root
, path
, NULL
, drv
, child
->sortOrder
, child
->hwnd
);
3397 entry
= &child
->root
.entry
;
3399 insert_entries(&child
->left
, child
->root
.entry
.down
, NULL
, TF_ALL
, 0);
3401 set_curdir(child
, entry
, 0, child
->hwnd
);
3403 idx
= SendMessageW(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)child
->left
.cur
);
3404 SendMessageW(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
3408 static void create_drive_bar(void)
3410 TBBUTTON drivebarBtn
= {0, 0, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0};
3411 WCHAR b1
[BUFFER_LEN
];
3415 GetLogicalDriveStringsW(BUFFER_LEN
, Globals
.drives
);
3417 Globals
.hdrivebar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
,
3418 IDW_DRIVEBAR
, 2, Globals
.hInstance
, IDB_DRIVEBAR
, &drivebarBtn
,
3419 0, 16, 13, 16, 13, sizeof(TBBUTTON
));
3422 /* insert unix file system button */
3426 SendMessageW(Globals
.hdrivebar
, TB_ADDSTRINGW
, 0, (LPARAM
)b1
);
3428 drivebarBtn
.idCommand
= ID_DRIVE_UNIX_FS
;
3429 SendMessageW(Globals
.hdrivebar
, TB_INSERTBUTTONW
, btn
++, (LPARAM
)&drivebarBtn
);
3430 drivebarBtn
.iString
++;
3432 /* insert shell namespace button */
3433 load_string(b1
, sizeof(b1
)/sizeof(b1
[0]), IDS_SHELL
);
3434 b1
[lstrlenW(b1
)+1] = '\0';
3435 SendMessageW(Globals
.hdrivebar
, TB_ADDSTRINGW
, 0, (LPARAM
)b1
);
3437 drivebarBtn
.idCommand
= ID_DRIVE_SHELL_NS
;
3438 SendMessageW(Globals
.hdrivebar
, TB_INSERTBUTTONW
, btn
++, (LPARAM
)&drivebarBtn
);
3439 drivebarBtn
.iString
++;
3441 /* register windows drive root strings */
3442 SendMessageW(Globals
.hdrivebar
, TB_ADDSTRINGW
, 0, (LPARAM
)Globals
.drives
);
3444 drivebarBtn
.idCommand
= ID_DRIVE_FIRST
;
3446 for(p
=Globals
.drives
; *p
; ) {
3447 switch(GetDriveTypeW(p
)) {
3448 case DRIVE_REMOVABLE
: drivebarBtn
.iBitmap
= 1; break;
3449 case DRIVE_CDROM
: drivebarBtn
.iBitmap
= 3; break;
3450 case DRIVE_REMOTE
: drivebarBtn
.iBitmap
= 4; break;
3451 case DRIVE_RAMDISK
: drivebarBtn
.iBitmap
= 5; break;
3452 default:/*DRIVE_FIXED*/ drivebarBtn
.iBitmap
= 2;
3455 SendMessageW(Globals
.hdrivebar
, TB_INSERTBUTTONW
, btn
++, (LPARAM
)&drivebarBtn
);
3456 drivebarBtn
.idCommand
++;
3457 drivebarBtn
.iString
++;
3463 static void refresh_drives(void)
3467 /* destroy drive bar */
3468 DestroyWindow(Globals
.hdrivebar
);
3469 Globals
.hdrivebar
= 0;
3471 /* re-create drive bar */
3474 /* update window layout */
3475 GetClientRect(Globals
.hMainWnd
, &rect
);
3476 SendMessageW(Globals
.hMainWnd
, WM_SIZE
, 0, MAKELONG(rect
.right
, rect
.bottom
));
3480 static BOOL
launch_file(HWND hwnd
, LPCWSTR cmd
, UINT nCmdShow
)
3482 HINSTANCE hinst
= ShellExecuteW(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3484 if (PtrToUlong(hinst
) <= 32) {
3485 display_error(hwnd
, GetLastError());
3493 static BOOL
launch_entry(Entry
* entry
, HWND hwnd
, UINT nCmdShow
)
3495 WCHAR cmd
[MAX_PATH
];
3497 if (entry
->etype
== ET_SHELL
) {
3500 SHELLEXECUTEINFOW shexinfo
;
3502 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFOW
);
3503 shexinfo
.fMask
= SEE_MASK_IDLIST
;
3504 shexinfo
.hwnd
= hwnd
;
3505 shexinfo
.lpVerb
= NULL
;
3506 shexinfo
.lpFile
= NULL
;
3507 shexinfo
.lpParameters
= NULL
;
3508 shexinfo
.lpDirectory
= NULL
;
3509 shexinfo
.nShow
= nCmdShow
;
3510 shexinfo
.lpIDList
= get_to_absolute_pidl(entry
, hwnd
);
3512 if (!ShellExecuteExW(&shexinfo
)) {
3513 display_error(hwnd
, GetLastError());
3517 if (shexinfo
.lpIDList
!= entry
->pidl
)
3518 IMalloc_Free(Globals
.iMalloc
, shexinfo
.lpIDList
);
3523 get_path(entry
, cmd
);
3525 /* start program, open document... */
3526 return launch_file(hwnd
, cmd
, nCmdShow
);
3530 static void activate_entry(ChildWnd
* child
, Pane
* pane
, HWND hwnd
)
3532 Entry
* entry
= pane
->cur
;
3537 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
3538 int scanned_old
= entry
->scanned
;
3542 int idx
= SendMessageW(child
->left
.hwnd
, LB_GETCURSEL
, 0, 0);
3543 scan_entry(child
, entry
, idx
, hwnd
);
3546 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='\0')
3549 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='.' && entry
->data
.cFileName
[2]=='\0') {
3550 entry
= child
->left
.cur
->up
;
3551 collapse_entry(&child
->left
, entry
);
3553 } else if (entry
->expanded
)
3554 collapse_entry(pane
, child
->left
.cur
);
3556 expand_entry(child
, child
->left
.cur
);
3558 if (!pane
->treePane
) focus_entry
: {
3559 int idxstart
= SendMessageW(child
->left
.hwnd
, LB_GETCURSEL
, 0, 0);
3560 int idx
= SendMessageW(child
->left
.hwnd
, LB_FINDSTRING
, idxstart
, (LPARAM
)entry
);
3561 SendMessageW(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
3562 set_curdir(child
, entry
, idx
, hwnd
);
3567 calc_widths(pane
, FALSE
);
3572 if (GetKeyState(VK_MENU
) < 0)
3573 show_properties_dlg(entry
, child
->hwnd
);
3575 launch_entry(entry
, child
->hwnd
, SW_SHOWNORMAL
);
3580 static BOOL
pane_command(Pane
* pane
, UINT cmd
)
3584 if (pane
->visible_cols
) {
3585 pane
->visible_cols
= 0;
3586 calc_widths(pane
, TRUE
);
3588 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3589 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
|MF_CHECKED
);
3590 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
);
3594 case ID_VIEW_ALL_ATTRIBUTES
:
3595 if (pane
->visible_cols
!= COL_ALL
) {
3596 pane
->visible_cols
= COL_ALL
;
3597 calc_widths(pane
, TRUE
);
3599 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3600 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
);
3601 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
|MF_CHECKED
);
3605 case ID_PREFERRED_SIZES
: {
3606 calc_widths(pane
, TRUE
);
3608 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3611 /* TODO: more command ids... */
3621 static void set_sort_order(ChildWnd
* child
, SORT_ORDER sortOrder
)
3623 if (child
->sortOrder
!= sortOrder
) {
3624 child
->sortOrder
= sortOrder
;
3625 refresh_child(child
);
3629 static void update_view_menu(ChildWnd
* child
)
3631 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_NAME
, child
->sortOrder
==SORT_NAME
? MF_CHECKED
: MF_UNCHECKED
);
3632 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_TYPE
, child
->sortOrder
==SORT_EXT
? MF_CHECKED
: MF_UNCHECKED
);
3633 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_SIZE
, child
->sortOrder
==SORT_SIZE
? MF_CHECKED
: MF_UNCHECKED
);
3634 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_DATE
, child
->sortOrder
==SORT_DATE
? MF_CHECKED
: MF_UNCHECKED
);
3638 static BOOL
is_directory(LPCWSTR target
)
3640 /*TODO correctly handle UNIX paths */
3641 DWORD target_attr
= GetFileAttributesW(target
);
3643 if (target_attr
== INVALID_FILE_ATTRIBUTES
)
3646 return (target_attr
& FILE_ATTRIBUTE_DIRECTORY
) != 0;
3649 static BOOL
prompt_target(Pane
* pane
, LPWSTR source
, LPWSTR target
)
3651 WCHAR path
[MAX_PATH
];
3654 get_path(pane
->cur
, path
);
3656 if (DialogBoxParamW(Globals
.hInstance
, MAKEINTRESOURCEW(IDD_SELECT_DESTINATION
), pane
->hwnd
, DestinationDlgProc
, (LPARAM
)path
) != IDOK
)
3659 get_path(pane
->cur
, source
);
3661 /* convert relative targets to absolute paths */
3662 if (path
[0]!='/' && path
[1]!=':') {
3663 get_path(pane
->cur
->up
, target
);
3664 len
= lstrlenW(target
);
3666 if (target
[len
-1]!='\\' && target
[len
-1]!='/')
3667 target
[len
++] = '/';
3669 lstrcpyW(target
+len
, path
);
3671 lstrcpyW(target
, path
);
3673 /* If the target already exists as directory, create a new target below this. */
3674 if (is_directory(path
)) {
3675 WCHAR fname
[_MAX_FNAME
], ext
[_MAX_EXT
];
3676 static const WCHAR sAppend
[] = {'%','s','/','%','s','%','s','\0'};
3678 _wsplitpath(source
, NULL
, NULL
, fname
, ext
);
3680 wsprintfW(target
, sAppend
, path
, fname
, ext
);
3687 static IContextMenu2
* s_pctxmenu2
= NULL
;
3688 static IContextMenu3
* s_pctxmenu3
= NULL
;
3690 static void CtxMenu_reset(void)
3696 static IContextMenu
* CtxMenu_query_interfaces(IContextMenu
* pcm1
)
3698 IContextMenu
* pcm
= NULL
;
3702 if (IContextMenu_QueryInterface(pcm1
, &IID_IContextMenu3
, (void**)&pcm
) == NOERROR
)
3703 s_pctxmenu3
= (LPCONTEXTMENU3
)pcm
;
3704 else if (IContextMenu_QueryInterface(pcm1
, &IID_IContextMenu2
, (void**)&pcm
) == NOERROR
)
3705 s_pctxmenu2
= (LPCONTEXTMENU2
)pcm
;
3708 IContextMenu_Release(pcm1
);
3714 static BOOL
CtxMenu_HandleMenuMsg(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3717 if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3
, nmsg
, wparam
, lparam
)))
3722 if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2
, nmsg
, wparam
, lparam
)))
3728 static HRESULT
ShellFolderContextMenu(IShellFolder
* shell_folder
, HWND hwndParent
, int cidl
, LPCITEMIDLIST
* apidl
, int x
, int y
)
3731 BOOL executed
= FALSE
;
3733 HRESULT hr
= IShellFolder_GetUIObjectOf(shell_folder
, hwndParent
, cidl
, apidl
, &IID_IContextMenu
, NULL
, (LPVOID
*)&pcm
);
3735 if (SUCCEEDED(hr
)) {
3736 HMENU hmenu
= CreatePopupMenu();
3738 pcm
= CtxMenu_query_interfaces(pcm
);
3741 hr
= IContextMenu_QueryContextMenu(pcm
, hmenu
, 0, FCIDM_SHVIEWFIRST
, FCIDM_SHVIEWLAST
, CMF_NORMAL
);
3743 if (SUCCEEDED(hr
)) {
3744 UINT idCmd
= TrackPopupMenu(hmenu
, TPM_LEFTALIGN
|TPM_RETURNCMD
|TPM_RIGHTBUTTON
, x
, y
, 0, hwndParent
, NULL
);
3749 CMINVOKECOMMANDINFO cmi
;
3751 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFO
);
3753 cmi
.hwnd
= hwndParent
;
3754 cmi
.lpVerb
= (LPCSTR
)(INT_PTR
)(idCmd
- FCIDM_SHVIEWFIRST
);
3755 cmi
.lpParameters
= NULL
;
3756 cmi
.lpDirectory
= NULL
;
3757 cmi
.nShow
= SW_SHOWNORMAL
;
3761 hr
= IContextMenu_InvokeCommand(pcm
, &cmi
);
3768 IContextMenu_Release(pcm
);
3771 return FAILED(hr
)? hr
: executed
? S_OK
: S_FALSE
;
3774 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3776 ChildWnd
* child
= (ChildWnd
*)GetWindowLongPtrW(hwnd
, GWLP_USERDATA
);
3781 LPDRAWITEMSTRUCT dis
= (LPDRAWITEMSTRUCT
)lparam
;
3782 Entry
* entry
= (Entry
*) dis
->itemData
;
3784 if (dis
->CtlID
== IDW_TREE_LEFT
)
3785 draw_item(&child
->left
, dis
, entry
, -1);
3786 else if (dis
->CtlID
== IDW_TREE_RIGHT
)
3787 draw_item(&child
->right
, dis
, entry
, -1);
3789 goto draw_menu_item
;
3794 InitChildWindow(child
);
3798 free_child_window(child
);
3799 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, 0);
3806 GetClientRect(hwnd
, &rt
);
3807 BeginPaint(hwnd
, &ps
);
3808 rt
.left
= child
->split_pos
-SPLIT_WIDTH
/2;
3809 rt
.right
= child
->split_pos
+SPLIT_WIDTH
/2+1;
3810 lastBrush
= SelectObject(ps
.hdc
, GetStockObject(COLOR_SPLITBAR
));
3811 Rectangle(ps
.hdc
, rt
.left
, rt
.top
-1, rt
.right
, rt
.bottom
+1);
3812 SelectObject(ps
.hdc
, lastBrush
);
3813 EndPaint(hwnd
, &ps
);
3817 if (LOWORD(lparam
) == HTCLIENT
) {
3820 ScreenToClient(hwnd
, &pt
);
3822 if (pt
.x
>=child
->split_pos
-SPLIT_WIDTH
/2 && pt
.x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
3823 SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_SIZEWE
));
3829 case WM_LBUTTONDOWN
: {
3831 int x
= (short)LOWORD(lparam
);
3833 GetClientRect(hwnd
, &rt
);
3835 if (x
>=child
->split_pos
-SPLIT_WIDTH
/2 && x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
3836 last_split
= child
->split_pos
;
3843 if (GetCapture() == hwnd
)
3848 if (wparam
== VK_ESCAPE
)
3849 if (GetCapture() == hwnd
) {
3851 child
->split_pos
= last_split
;
3852 GetClientRect(hwnd
, &rt
);
3853 resize_tree(child
, rt
.right
, rt
.bottom
);
3856 SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_ARROW
));
3861 if (GetCapture() == hwnd
) {
3863 int x
= (short)LOWORD(lparam
);
3865 GetClientRect(hwnd
, &rt
);
3867 if (x
>=0 && x
<rt
.right
) {
3868 child
->split_pos
= x
;
3869 resize_tree(child
, rt
.right
, rt
.bottom
);
3870 rt
.left
= x
-SPLIT_WIDTH
/2;
3871 rt
.right
= x
+SPLIT_WIDTH
/2+1;
3872 InvalidateRect(hwnd
, &rt
, FALSE
);
3873 UpdateWindow(child
->left
.hwnd
);
3875 UpdateWindow(child
->right
.hwnd
);
3880 case WM_GETMINMAXINFO
:
3881 DefMDIChildProcW(hwnd
, nmsg
, wparam
, lparam
);
3883 {LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
3885 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
3886 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
3890 if (SetCurrentDirectoryW(child
->path
))
3892 SetFocus(child
->focus_pane
? child
->right
.hwnd
: child
->left
.hwnd
);
3895 case WM_DISPATCH_COMMAND
: {
3896 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
3898 switch(LOWORD(wparam
)) {
3899 case ID_WINDOW_NEW
: {
3900 ChildWnd
* new_child
= alloc_child_window(child
->path
, NULL
, hwnd
);
3902 if (!create_child_window(new_child
))
3903 HeapFree(GetProcessHeap(), 0, new_child
);
3909 refresh_child(child
);
3913 activate_entry(child
, pane
, hwnd
);
3916 case ID_FILE_MOVE
: {
3917 WCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
3919 if (prompt_target(pane
, source
, target
)) {
3920 SHFILEOPSTRUCTW shfo
= {hwnd
, FO_MOVE
, source
, target
};
3922 source
[lstrlenW(source
)+1] = '\0';
3923 target
[lstrlenW(target
)+1] = '\0';
3925 if (!SHFileOperationW(&shfo
))
3926 refresh_child(child
);
3930 case ID_FILE_COPY
: {
3931 WCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
3933 if (prompt_target(pane
, source
, target
)) {
3934 SHFILEOPSTRUCTW shfo
= {hwnd
, FO_COPY
, source
, target
};
3936 source
[lstrlenW(source
)+1] = '\0';
3937 target
[lstrlenW(target
)+1] = '\0';
3939 if (!SHFileOperationW(&shfo
))
3940 refresh_child(child
);
3944 case ID_FILE_DELETE
: {
3945 WCHAR path
[BUFFER_LEN
];
3946 SHFILEOPSTRUCTW shfo
= {hwnd
, FO_DELETE
, path
, NULL
, FOF_ALLOWUNDO
};
3948 get_path(pane
->cur
, path
);
3950 path
[lstrlenW(path
)+1] = '\0';
3952 if (!SHFileOperationW(&shfo
))
3953 refresh_child(child
);
3956 case ID_VIEW_SORT_NAME
:
3957 set_sort_order(child
, SORT_NAME
);
3960 case ID_VIEW_SORT_TYPE
:
3961 set_sort_order(child
, SORT_EXT
);
3964 case ID_VIEW_SORT_SIZE
:
3965 set_sort_order(child
, SORT_SIZE
);
3968 case ID_VIEW_SORT_DATE
:
3969 set_sort_order(child
, SORT_DATE
);
3972 case ID_VIEW_FILTER
: {
3973 struct FilterDialog dlg
;
3975 memset(&dlg
, 0, sizeof(struct FilterDialog
));
3976 lstrcpyW(dlg
.pattern
, child
->filter_pattern
);
3977 dlg
.flags
= child
->filter_flags
;
3979 if (DialogBoxParamW(Globals
.hInstance
, MAKEINTRESOURCEW(IDD_DIALOG_VIEW_TYPE
), hwnd
, FilterDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
3980 lstrcpyW(child
->filter_pattern
, dlg
.pattern
);
3981 child
->filter_flags
= dlg
.flags
;
3982 refresh_right_pane(child
);
3986 case ID_VIEW_SPLIT
: {
3987 last_split
= child
->split_pos
;
3991 case ID_EDIT_PROPERTIES
:
3992 show_properties_dlg(pane
->cur
, child
->hwnd
);
3996 return pane_command(pane
, LOWORD(wparam
));
4002 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4004 switch(HIWORD(wparam
)) {
4005 case LBN_SELCHANGE
: {
4006 int idx
= SendMessageW(pane
->hwnd
, LB_GETCURSEL
, 0, 0);
4007 Entry
* entry
= (Entry
*)SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, idx
, 0);
4009 if (pane
== &child
->left
)
4010 set_curdir(child
, entry
, idx
, hwnd
);
4016 activate_entry(child
, pane
, hwnd
);
4022 NMHDR
* pnmh
= (NMHDR
*) lparam
;
4023 return pane_notify(pnmh
->idFrom
==IDW_HEADER_LEFT
? &child
->left
: &child
->right
, pnmh
);}
4025 case WM_CONTEXTMENU
: {
4030 /* first select the current item in the listbox */
4031 HWND hpanel
= (HWND
) wparam
;
4032 pt_clnt
.x
= pt
.x
= (short)LOWORD(lparam
);
4033 pt_clnt
.y
= pt
.y
= (short)HIWORD(lparam
);
4034 ScreenToClient(hpanel
, &pt_clnt
);
4035 SendMessageW(hpanel
, WM_LBUTTONDOWN
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4036 SendMessageW(hpanel
, WM_LBUTTONUP
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4038 /* now create the popup menu using shell namespace and IContextMenu */
4039 pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4040 idx
= SendMessageW(pane
->hwnd
, LB_GETCURSEL
, 0, 0);
4043 Entry
* entry
= (Entry
*)SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, idx
, 0);
4045 LPITEMIDLIST pidl_abs
= get_to_absolute_pidl(entry
, hwnd
);
4048 IShellFolder
* parentFolder
;
4049 LPCITEMIDLIST pidlLast
;
4051 /* get and use the parent folder to display correct context menu in all cases */
4052 if (SUCCEEDED(SHBindToParent(pidl_abs
, &IID_IShellFolder
, (LPVOID
*)&parentFolder
, &pidlLast
))) {
4053 if (ShellFolderContextMenu(parentFolder
, hwnd
, 1, &pidlLast
, pt
.x
, pt
.y
) == S_OK
)
4054 refresh_child(child
);
4056 IShellFolder_Release(parentFolder
);
4059 IMalloc_Free(Globals
.iMalloc
, pidl_abs
);
4064 case WM_MEASUREITEM
:
4066 if (!wparam
) /* Is the message menu-related? */
4067 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4072 case WM_INITMENUPOPUP
:
4073 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4076 update_view_menu(child
);
4079 case WM_MENUCHAR
: /* only supported by IContextMenu3 */
4081 LRESULT lResult
= 0;
4083 IContextMenu3_HandleMenuMsg2(s_pctxmenu3
, nmsg
, wparam
, lparam
, &lResult
);
4091 if (wparam
!= SIZE_MINIMIZED
)
4092 resize_tree(child
, LOWORD(lparam
), HIWORD(lparam
));
4096 return DefMDIChildProcW(hwnd
, nmsg
, wparam
, lparam
);
4103 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4105 ChildWnd
* child
= (ChildWnd
*)GetWindowLongPtrW(GetParent(hwnd
), GWLP_USERDATA
);
4106 Pane
* pane
= (Pane
*)GetWindowLongPtrW(hwnd
, GWLP_USERDATA
);
4115 child
->focus_pane
= pane
==&child
->right
? 1: 0;
4116 SendMessageW(hwnd
, LB_SETSEL
, TRUE
, 1);
4117 /*TODO: check menu items */
4121 if (wparam
== VK_TAB
) {
4122 /*TODO: SetFocus(Globals.hdrivebar) */
4123 SetFocus(child
->focus_pane
? child
->left
.hwnd
: child
->right
.hwnd
);
4127 return CallWindowProcW(g_orgTreeWndProc
, hwnd
, nmsg
, wparam
, lparam
);
4131 static void InitInstance(HINSTANCE hinstance
)
4133 static const WCHAR sFont
[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4135 WNDCLASSEXW wcFrame
;
4139 INITCOMMONCONTROLSEX icc
= {
4140 sizeof(INITCOMMONCONTROLSEX
),
4146 setlocale(LC_COLLATE
, ""); /* set collating rules to local settings for compareName */
4148 InitCommonControlsEx(&icc
);
4151 /* register frame window class */
4153 wcFrame
.cbSize
= sizeof(WNDCLASSEXW
);
4155 wcFrame
.lpfnWndProc
= FrameWndProc
;
4156 wcFrame
.cbClsExtra
= 0;
4157 wcFrame
.cbWndExtra
= 0;
4158 wcFrame
.hInstance
= hinstance
;
4159 wcFrame
.hIcon
= LoadIconW(hinstance
, MAKEINTRESOURCEW(IDI_WINEFILE
));
4160 wcFrame
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
4161 wcFrame
.hbrBackground
= 0;
4162 wcFrame
.lpszMenuName
= 0;
4163 wcFrame
.lpszClassName
= sWINEFILEFRAME
;
4164 wcFrame
.hIconSm
= LoadImageW(hinstance
, MAKEINTRESOURCEW(IDI_WINEFILE
), IMAGE_ICON
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
4166 Globals
.hframeClass
= RegisterClassExW(&wcFrame
);
4169 /* register tree windows class */
4171 wcChild
.style
= CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
;
4172 wcChild
.lpfnWndProc
= ChildWndProc
;
4173 wcChild
.cbClsExtra
= 0;
4174 wcChild
.cbWndExtra
= 0;
4175 wcChild
.hInstance
= hinstance
;
4176 wcChild
.hIcon
= LoadIconW(hinstance
, MAKEINTRESOURCEW(IDI_WINEFILE
));
4177 wcChild
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
4178 wcChild
.hbrBackground
= 0;
4179 wcChild
.lpszMenuName
= 0;
4180 wcChild
.lpszClassName
= sWINEFILETREE
;
4182 RegisterClassW(&wcChild
);
4185 Globals
.haccel
= LoadAcceleratorsW(hinstance
, MAKEINTRESOURCEW(IDA_WINEFILE
));
4187 Globals
.hfont
= CreateFontW(-MulDiv(8,GetDeviceCaps(hdc
,LOGPIXELSY
),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont
);
4191 Globals
.hInstance
= hinstance
;
4194 CoGetMalloc(MEMCTX_TASK
, &Globals
.iMalloc
);
4195 SHGetDesktopFolder(&Globals
.iDesktop
);
4196 Globals
.cfStrFName
= RegisterClipboardFormatW(CFSTR_FILENAMEW
);
4198 /* load column strings */
4201 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_NAME
);
4202 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_SIZE
);
4203 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_CDATE
);
4204 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_ADATE
);
4205 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_MDATE
);
4206 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_IDX
);
4207 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_LINKS
);
4208 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_ATTR
);
4209 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_SEC
);
4213 static BOOL
show_frame(HWND hwndParent
, int cmdshow
, LPCWSTR path
)
4215 static const WCHAR sMDICLIENT
[] = {'M','D','I','C','L','I','E','N','T','\0'};
4217 WCHAR buffer
[MAX_PATH
], b1
[BUFFER_LEN
];
4219 HMENU hMenuFrame
, hMenuWindow
;
4222 CLIENTCREATESTRUCT ccs
;
4224 if (Globals
.hMainWnd
)
4227 opts
= load_registry_settings();
4228 hMenuFrame
= LoadMenuW(Globals
.hInstance
, MAKEINTRESOURCEW(IDM_WINEFILE
));
4229 hMenuWindow
= GetSubMenu(hMenuFrame
, GetMenuItemCount(hMenuFrame
)-2);
4231 Globals
.hMenuFrame
= hMenuFrame
;
4232 Globals
.hMenuView
= GetSubMenu(hMenuFrame
, 2);
4233 Globals
.hMenuOptions
= GetSubMenu(hMenuFrame
, 3);
4235 ccs
.hWindowMenu
= hMenuWindow
;
4236 ccs
.idFirstChild
= IDW_FIRST_CHILD
;
4239 /* create main window */
4240 Globals
.hMainWnd
= CreateWindowExW(0, MAKEINTRESOURCEW(Globals
.hframeClass
), RS(b1
,IDS_WINEFILE
), WS_OVERLAPPEDWINDOW
,
4241 opts
.start_x
, opts
.start_y
, opts
.width
, opts
.height
,
4242 hwndParent
, Globals
.hMenuFrame
, Globals
.hInstance
, 0/*lpParam*/);
4245 Globals
.hmdiclient
= CreateWindowExW(0, sMDICLIENT
, NULL
,
4246 WS_CHILD
|WS_CLIPCHILDREN
|WS_VSCROLL
|WS_HSCROLL
|WS_VISIBLE
|WS_BORDER
,
4248 Globals
.hMainWnd
, 0, Globals
.hInstance
, &ccs
);
4250 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_DRIVE_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4251 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_SAVESETTINGS
, MF_BYCOMMAND
);
4256 TBBUTTON toolbarBtns
[] = {
4257 {0, 0, 0, BTNS_SEP
, {0, 0}, 0, 0},
4258 {0, ID_WINDOW_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4259 {1, ID_WINDOW_CASCADE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4260 {2, ID_WINDOW_TILE_HORZ
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4261 {3, ID_WINDOW_TILE_VERT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4264 Globals
.htoolbar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
,
4265 IDW_TOOLBAR
, 2, Globals
.hInstance
, IDB_TOOLBAR
, toolbarBtns
,
4266 sizeof(toolbarBtns
)/sizeof(TBBUTTON
), 16, 15, 16, 15, sizeof(TBBUTTON
));
4267 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_TOOL_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4270 Globals
.hstatusbar
= CreateStatusWindowW(WS_CHILD
|WS_VISIBLE
, 0, Globals
.hMainWnd
, IDW_STATUSBAR
);
4271 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
4273 /*TODO: read paths from registry */
4275 if (!path
|| !*path
) {
4276 GetCurrentDirectoryW(MAX_PATH
, buffer
);
4280 ShowWindow(Globals
.hMainWnd
, cmdshow
);
4283 /* Shell Namespace as default: */
4284 child
= alloc_child_window(path
, get_path_pidl(path
,Globals
.hMainWnd
), Globals
.hMainWnd
);
4286 child
= alloc_child_window(path
, NULL
, Globals
.hMainWnd
);
4289 child
->pos
.showCmd
= SW_SHOWMAXIMIZED
;
4290 child
->pos
.rcNormalPosition
.left
= 0;
4291 child
->pos
.rcNormalPosition
.top
= 0;
4292 child
->pos
.rcNormalPosition
.right
= 320;
4293 child
->pos
.rcNormalPosition
.bottom
= 280;
4295 if (!create_child_window(child
)) {
4296 HeapFree(GetProcessHeap(), 0, child
);
4300 SetWindowPlacement(child
->hwnd
, &child
->pos
);
4302 Globals
.himl
= ImageList_LoadImageW(Globals
.hInstance
, MAKEINTRESOURCEW(IDB_IMAGES
), 16, 0, RGB(0,255,0), IMAGE_BITMAP
, 0);
4304 Globals
.prescan_node
= FALSE
;
4306 UpdateWindow(Globals
.hMainWnd
);
4308 if (child
->hwnd
&& path
&& path
[0])
4311 WCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
4312 WCHAR fullname
[_MAX_FNAME
+_MAX_EXT
+1];
4314 memset(name
,0,sizeof(name
));
4315 memset(name
,0,sizeof(ext
));
4316 _wsplitpath(path
, drv
, dir
, name
, ext
);
4319 count
= SendMessageW(child
->right
.hwnd
, LB_GETCOUNT
, 0, 0);
4320 lstrcpyW(fullname
,name
);
4321 lstrcatW(fullname
,ext
);
4323 for (index
= 0; index
< count
; index
++)
4325 Entry
* entry
= (Entry
*)SendMessageW(child
->right
.hwnd
, LB_GETITEMDATA
, index
, 0);
4326 if (lstrcmpW(entry
->data
.cFileName
,fullname
)==0 ||
4327 lstrcmpW(entry
->data
.cAlternateFileName
,fullname
)==0)
4329 SendMessageW(child
->right
.hwnd
, LB_SETCURSEL
, index
, 0);
4330 SetFocus(child
->right
.hwnd
);
4339 static void ExitInstance(void)
4341 IShellFolder_Release(Globals
.iDesktop
);
4342 IMalloc_Release(Globals
.iMalloc
);
4345 DeleteObject(Globals
.hfont
);
4346 ImageList_Destroy(Globals
.himl
);
4349 int APIENTRY
wWinMain(HINSTANCE hinstance
, HINSTANCE previnstance
, LPWSTR cmdline
, int cmdshow
)
4353 InitInstance(hinstance
);
4355 if( !show_frame(0, cmdshow
, cmdline
) )
4361 while(GetMessageW(&msg
, 0, 0, 0)) {
4362 if (Globals
.hmdiclient
&& TranslateMDISysAccel(Globals
.hmdiclient
, &msg
))
4365 if (Globals
.hMainWnd
&& TranslateAcceleratorW(Globals
.hMainWnd
, Globals
.haccel
, &msg
))
4368 TranslateMessage(&msg
);
4369 DispatchMessageW(&msg
);