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 GetWindowPlacement(hwnd
, &wp
);
1928 prect
->left
= prect
->top
= 0;
1929 prect
->right
= wp
.rcNormalPosition
.right
-wp
.rcNormalPosition
.left
-
1930 2*(GetSystemMetrics(SM_CXSIZEFRAME
)+GetSystemMetrics(SM_CXEDGE
));
1931 prect
->bottom
= wp
.rcNormalPosition
.bottom
-wp
.rcNormalPosition
.top
-
1932 2*(GetSystemMetrics(SM_CYSIZEFRAME
)+GetSystemMetrics(SM_CYEDGE
))-
1933 GetSystemMetrics(SM_CYCAPTION
)-GetSystemMetrics(SM_CYMENUSIZE
);
1936 if (IsWindowVisible(Globals
.htoolbar
)) {
1937 GetClientRect(Globals
.htoolbar
, &rt
);
1938 prect
->top
+= rt
.bottom
+2;
1941 if (IsWindowVisible(Globals
.hdrivebar
)) {
1942 GetClientRect(Globals
.hdrivebar
, &rt
);
1943 prect
->top
+= rt
.bottom
+2;
1946 if (IsWindowVisible(Globals
.hstatusbar
)) {
1947 GetClientRect(Globals
.hstatusbar
, &rt
);
1948 prect
->bottom
-= rt
.bottom
;
1952 static BOOL
toggle_fullscreen(HWND hwnd
)
1956 if ((g_fullscreen
.mode
=!g_fullscreen
.mode
)) {
1957 GetWindowRect(hwnd
, &g_fullscreen
.orgPos
);
1958 g_fullscreen
.wasZoomed
= IsZoomed(hwnd
);
1960 Frame_CalcFrameClient(hwnd
, &rt
);
1961 MapWindowPoints( hwnd
, 0, (POINT
*)&rt
, 2 );
1963 rt
.left
= g_fullscreen
.orgPos
.left
-rt
.left
;
1964 rt
.top
= g_fullscreen
.orgPos
.top
-rt
.top
;
1965 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+g_fullscreen
.orgPos
.right
-rt
.right
;
1966 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+g_fullscreen
.orgPos
.bottom
-rt
.bottom
;
1968 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
1970 MoveWindow(hwnd
, g_fullscreen
.orgPos
.left
, g_fullscreen
.orgPos
.top
,
1971 g_fullscreen
.orgPos
.right
-g_fullscreen
.orgPos
.left
,
1972 g_fullscreen
.orgPos
.bottom
-g_fullscreen
.orgPos
.top
, TRUE
);
1974 if (g_fullscreen
.wasZoomed
)
1975 ShowWindow(hwnd
, WS_MAXIMIZE
);
1978 return g_fullscreen
.mode
;
1981 static void fullscreen_move(HWND hwnd
)
1984 GetWindowRect(hwnd
, &pos
);
1986 Frame_CalcFrameClient(hwnd
, &rt
);
1987 MapWindowPoints( hwnd
, 0, (POINT
*)&rt
, 2 );
1989 rt
.left
= pos
.left
-rt
.left
;
1990 rt
.top
= pos
.top
-rt
.top
;
1991 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+pos
.right
-rt
.right
;
1992 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+pos
.bottom
-rt
.bottom
;
1994 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
1997 static void toggle_child(HWND hwnd
, UINT cmd
, HWND hchild
)
1999 BOOL vis
= IsWindowVisible(hchild
);
2001 CheckMenuItem(Globals
.hMenuOptions
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
2003 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
2005 if (g_fullscreen
.mode
)
2006 fullscreen_move(hwnd
);
2008 resize_frame_client(hwnd
);
2011 static BOOL
activate_drive_window(LPCWSTR path
)
2013 WCHAR drv1
[_MAX_DRIVE
], drv2
[_MAX_DRIVE
];
2016 _wsplitpath(path
, drv1
, 0, 0, 0);
2018 /* search for an already open window for the same drive */
2019 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2020 ChildWnd
* child
= (ChildWnd
*)GetWindowLongPtrW(child_wnd
, GWLP_USERDATA
);
2023 _wsplitpath(child
->root
.path
, drv2
, 0, 0, 0);
2025 if (!lstrcmpiW(drv2
, drv1
)) {
2026 SendMessageW(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2028 if (IsIconic(child_wnd
))
2029 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2039 static BOOL
activate_fs_window(LPCWSTR filesys
)
2043 /* search for an already open window of the given file system name */
2044 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2045 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtrW(child_wnd
, GWLP_USERDATA
);
2048 if (!lstrcmpiW(child
->root
.fs
, filesys
)) {
2049 SendMessageW(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2051 if (IsIconic(child_wnd
))
2052 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2062 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
2064 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2068 if (Globals
.saveSettings
)
2069 save_registry_settings();
2071 DestroyWindow(hwnd
);
2073 /* clear handle variables */
2074 Globals
.hMenuFrame
= 0;
2075 Globals
.hMenuView
= 0;
2076 Globals
.hMenuOptions
= 0;
2077 Globals
.hMainWnd
= 0;
2078 Globals
.hmdiclient
= 0;
2079 Globals
.hdrivebar
= 0;
2086 case WM_INITMENUPOPUP
: {
2087 HWND hwndClient
= (HWND
)SendMessageW(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2089 if (!SendMessageW(hwndClient
, WM_INITMENUPOPUP
, wparam
, lparam
))
2094 UINT cmd
= LOWORD(wparam
);
2095 HWND hwndClient
= (HWND
)SendMessageW(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2097 if (SendMessageW(hwndClient
, WM_DISPATCH_COMMAND
, wparam
, lparam
))
2100 if (cmd
>=ID_DRIVE_FIRST
&& cmd
<=ID_DRIVE_FIRST
+0xFF) {
2101 WCHAR drv
[_MAX_DRIVE
], path
[MAX_PATH
];
2103 LPCWSTR root
= Globals
.drives
;
2106 for(i
=cmd
-ID_DRIVE_FIRST
; i
--; root
++)
2110 if (activate_drive_window(root
))
2113 _wsplitpath(root
, drv
, 0, 0, 0);
2115 if (!SetCurrentDirectoryW(drv
)) {
2116 display_error(hwnd
, GetLastError());
2120 GetCurrentDirectoryW(MAX_PATH
, path
); /*TODO: store last directory per drive */
2121 child
= alloc_child_window(path
, NULL
, hwnd
);
2123 if (!create_child_window(child
))
2124 HeapFree(GetProcessHeap(), 0, child
);
2125 } else switch(cmd
) {
2127 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
2130 case ID_WINDOW_NEW
: {
2131 WCHAR path
[MAX_PATH
];
2134 GetCurrentDirectoryW(MAX_PATH
, path
);
2135 child
= alloc_child_window(path
, NULL
, hwnd
);
2137 if (!create_child_window(child
))
2138 HeapFree(GetProcessHeap(), 0, child
);
2145 case ID_WINDOW_CASCADE
:
2146 SendMessageW(Globals
.hmdiclient
, WM_MDICASCADE
, 0, 0);
2149 case ID_WINDOW_TILE_HORZ
:
2150 SendMessageW(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
2153 case ID_WINDOW_TILE_VERT
:
2154 SendMessageW(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
2157 case ID_WINDOW_ARRANGE
:
2158 SendMessageW(Globals
.hmdiclient
, WM_MDIICONARRANGE
, 0, 0);
2161 case ID_SELECT_FONT
:
2165 case ID_VIEW_TOOL_BAR
:
2166 toggle_child(hwnd
, cmd
, Globals
.htoolbar
);
2169 case ID_VIEW_DRIVE_BAR
:
2170 toggle_child(hwnd
, cmd
, Globals
.hdrivebar
);
2173 case ID_VIEW_STATUSBAR
:
2174 toggle_child(hwnd
, cmd
, Globals
.hstatusbar
);
2177 case ID_VIEW_SAVESETTINGS
:
2178 Globals
.saveSettings
= !Globals
.saveSettings
;
2179 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_SAVESETTINGS
,
2180 Globals
.saveSettings
? MF_CHECKED
: MF_UNCHECKED
);
2184 WineFile_OnRun( hwnd
);
2187 case ID_CONNECT_NETWORK_DRIVE
: {
2188 DWORD ret
= WNetConnectionDialog(hwnd
, RESOURCETYPE_DISK
);
2189 if (ret
== NO_ERROR
)
2191 else if (ret
!= (DWORD
)-1) {
2192 if (ret
== ERROR_EXTENDED_ERROR
)
2193 display_network_error(hwnd
);
2195 display_error(hwnd
, ret
);
2199 case ID_DISCONNECT_NETWORK_DRIVE
: {
2200 DWORD ret
= WNetDisconnectDialog(hwnd
, RESOURCETYPE_DISK
);
2201 if (ret
== NO_ERROR
)
2203 else if (ret
!= (DWORD
)-1) {
2204 if (ret
== ERROR_EXTENDED_ERROR
)
2205 display_network_error(hwnd
);
2207 display_error(hwnd
, ret
);
2212 WinHelpW(hwnd
, RS(b1
,IDS_WINEFILE
), HELP_INDEX
, 0);
2215 case ID_VIEW_FULLSCREEN
:
2216 CheckMenuItem(Globals
.hMenuOptions
, cmd
, toggle_fullscreen(hwnd
)?MF_CHECKED
:0);
2220 case ID_DRIVE_UNIX_FS
: {
2221 WCHAR path
[MAX_PATH
];
2222 char cpath
[MAX_PATH
];
2225 if (activate_fs_window(RS(b1
,IDS_UNIXFS
)))
2228 getcwd(cpath
, MAX_PATH
);
2229 MultiByteToWideChar(CP_UNIXCP
, 0, cpath
, -1, path
, MAX_PATH
);
2230 child
= alloc_child_window(path
, NULL
, hwnd
);
2232 if (!create_child_window(child
))
2233 HeapFree(GetProcessHeap(), 0, child
);
2236 case ID_DRIVE_SHELL_NS
: {
2237 WCHAR path
[MAX_PATH
];
2240 if (activate_fs_window(RS(b1
,IDS_SHELL
)))
2243 GetCurrentDirectoryW(MAX_PATH
, path
);
2244 child
= alloc_child_window(path
, get_path_pidl(path
,hwnd
), hwnd
);
2246 if (!create_child_window(child
))
2247 HeapFree(GetProcessHeap(), 0, child
);
2250 /*TODO: There are even more menu items! */
2253 ShellAboutW(hwnd
, RS(b1
,IDS_WINEFILE
), NULL
,
2254 LoadImageW( Globals
.hInstance
, MAKEINTRESOURCEW(IDI_WINEFILE
),
2255 IMAGE_ICON
, 48, 48, LR_SHARED
));
2259 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2260 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2261 else */if ((cmd
<IDW_FIRST_CHILD
|| cmd
>=IDW_FIRST_CHILD
+0x100) &&
2262 (cmd
<SC_SIZE
|| cmd
>SC_RESTORE
))
2263 MessageBoxW(hwnd
, RS(b2
,IDS_NO_IMPL
), RS(b1
,IDS_WINEFILE
), MB_OK
);
2265 return DefFrameProcW(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2270 resize_frame(hwnd
, LOWORD(lparam
), HIWORD(lparam
));
2271 break; /* do not pass message to DefFrameProcW */
2273 case WM_DEVICECHANGE
:
2274 SendMessageW(hwnd
, WM_COMMAND
, MAKELONG(ID_REFRESH
,0), 0);
2277 case WM_GETMINMAXINFO
: {
2278 LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
2280 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2281 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2284 case FRM_CALC_CLIENT
:
2285 frame_get_clientspace(hwnd
, (PRECT
)lparam
);
2289 return DefFrameProcW(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2296 static WCHAR g_pos_names
[COLUMNS
][40] = {
2300 static const int g_pos_align
[] = {
2302 HDF_LEFT
, /* Name */
2303 HDF_RIGHT
, /* Size */
2304 HDF_LEFT
, /* CDate */
2305 HDF_LEFT
, /* ADate */
2306 HDF_LEFT
, /* MDate */
2307 HDF_LEFT
, /* Index */
2308 HDF_CENTER
, /* Links */
2309 HDF_CENTER
, /* Attributes */
2310 HDF_LEFT
/* Security */
2313 static void resize_tree(ChildWnd
* child
, int cx
, int cy
)
2315 HDWP hdwp
= BeginDeferWindowPos(4);
2325 cx
= child
->split_pos
+ SPLIT_WIDTH
/2;
2329 SendMessageW(child
->left
.hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hdl
);
2331 DeferWindowPos(hdwp
, child
->left
.hwndHeader
, wp
.hwndInsertAfter
,
2332 wp
.x
-1, wp
.y
, child
->split_pos
-SPLIT_WIDTH
/2+1, wp
.cy
, wp
.flags
);
2333 DeferWindowPos(hdwp
, child
->right
.hwndHeader
, wp
.hwndInsertAfter
,
2334 rt
.left
+cx
+1, wp
.y
, wp
.cx
-cx
+2, wp
.cy
, wp
.flags
);
2335 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
);
2336 DeferWindowPos(hdwp
, child
->right
.hwnd
, 0, rt
.left
+cx
+1, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
2338 EndDeferWindowPos(hdwp
);
2341 static HWND
create_header(HWND parent
, Pane
* pane
, UINT id
)
2346 HWND hwnd
= CreateWindowW(WC_HEADERW
, 0, WS_CHILD
|WS_VISIBLE
|HDS_HORZ
|HDS_FULLDRAG
/*TODO: |HDS_BUTTONS + sort orders*/,
2347 0, 0, 0, 0, parent
, (HMENU
)ULongToHandle(id
), Globals
.hInstance
, 0);
2351 SendMessageW(hwnd
, WM_SETFONT
, (WPARAM
)GetStockObject(DEFAULT_GUI_FONT
), FALSE
);
2353 hdi
.mask
= HDI_TEXT
|HDI_WIDTH
|HDI_FORMAT
;
2355 for(idx
=0; idx
<COLUMNS
; idx
++) {
2356 hdi
.pszText
= g_pos_names
[idx
];
2357 hdi
.fmt
= HDF_STRING
| g_pos_align
[idx
];
2358 hdi
.cxy
= pane
->widths
[idx
];
2359 pane
->widths_shown
[idx
] = hdi
.cxy
;
2360 SendMessageW(hwnd
, HDM_INSERTITEMW
, idx
, (LPARAM
)&hdi
);
2366 static void init_output(HWND hwnd
)
2368 static const WCHAR s1000
[] = {'1','0','0','0','\0'};
2371 HDC hdc
= GetDC(hwnd
);
2373 if (GetNumberFormatW(LOCALE_USER_DEFAULT
, 0, s1000
, 0, b
, 16) > 4)
2374 Globals
.num_sep
= b
[1];
2376 Globals
.num_sep
= '.';
2378 old_font
= SelectObject(hdc
, Globals
.hfont
);
2379 GetTextExtentPoint32W(hdc
, sSpace
, 1, &Globals
.spaceSize
);
2380 SelectObject(hdc
, old_font
);
2381 ReleaseDC(hwnd
, hdc
);
2384 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
);
2387 /* calculate preferred width for all visible columns */
2389 static BOOL
calc_widths(Pane
* pane
, BOOL anyway
)
2391 int col
, x
, cx
, spc
=3*Globals
.spaceSize
.cx
;
2392 int entries
= SendMessageW(pane
->hwnd
, LB_GETCOUNT
, 0, 0);
2393 int orgWidths
[COLUMNS
];
2394 int orgPositions
[COLUMNS
+1];
2400 memcpy(orgWidths
, pane
->widths
, sizeof(orgWidths
));
2401 memcpy(orgPositions
, pane
->positions
, sizeof(orgPositions
));
2404 for(col
=0; col
<COLUMNS
; col
++)
2405 pane
->widths
[col
] = 0;
2407 hdc
= GetDC(pane
->hwnd
);
2408 hfontOld
= SelectObject(hdc
, Globals
.hfont
);
2410 for(cnt
=0; cnt
<entries
; cnt
++) {
2411 Entry
* entry
= (Entry
*)SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, cnt
, 0);
2420 dis
.hwndItem
= pane
->hwnd
;
2422 SetRectEmpty(&dis
.rcItem
);
2423 /*dis.itemData = 0; */
2425 draw_item(pane
, &dis
, entry
, COLUMNS
);
2428 SelectObject(hdc
, hfontOld
);
2429 ReleaseDC(pane
->hwnd
, hdc
);
2432 for(col
=0; col
<COLUMNS
; col
++) {
2433 pane
->positions
[col
] = x
;
2434 cx
= pane
->widths
[col
];
2439 if (cx
< IMAGE_WIDTH
)
2442 pane
->widths
[col
] = cx
;
2448 pane
->positions
[COLUMNS
] = x
;
2450 SendMessageW(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, x
, 0);
2453 if (!anyway
&& !memcmp(orgWidths
, pane
->widths
, sizeof(orgWidths
)))
2456 /* don't move, if only collapsing an entry */
2457 if (!anyway
&& pane
->widths
[0]<orgWidths
[0] &&
2458 !memcmp(orgWidths
+1, pane
->widths
+1, sizeof(orgWidths
)-sizeof(int))) {
2459 pane
->widths
[0] = orgWidths
[0];
2460 memcpy(pane
->positions
, orgPositions
, sizeof(orgPositions
));
2465 InvalidateRect(pane
->hwnd
, 0, TRUE
);
2470 /* calculate one preferred column width */
2471 static void calc_single_width(Pane
* pane
, int col
)
2475 int entries
= SendMessageW(pane
->hwnd
, LB_GETCOUNT
, 0, 0);
2479 pane
->widths
[col
] = 0;
2481 hdc
= GetDC(pane
->hwnd
);
2482 hfontOld
= SelectObject(hdc
, Globals
.hfont
);
2484 for(cnt
=0; cnt
<entries
; cnt
++) {
2485 Entry
* entry
= (Entry
*)SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, cnt
, 0);
2493 dis
.hwndItem
= pane
->hwnd
;
2495 SetRectEmpty(&dis
.rcItem
);
2496 /*dis.itemData = 0; */
2498 draw_item(pane
, &dis
, entry
, col
);
2501 SelectObject(hdc
, hfontOld
);
2502 ReleaseDC(pane
->hwnd
, hdc
);
2504 cx
= pane
->widths
[col
];
2507 cx
+= 3*Globals
.spaceSize
.cx
;
2509 if (cx
< IMAGE_WIDTH
)
2513 pane
->widths
[col
] = cx
;
2515 x
= pane
->positions
[col
] + cx
;
2517 for(; col
<COLUMNS
-1; ) {
2518 pane
->positions
[++col
] = x
;
2519 x
+= pane
->widths
[col
];
2522 SendMessageW(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, x
, 0);
2525 static BOOL
pattern_match(LPCWSTR str
, LPCWSTR pattern
)
2527 for( ; *str
&&*pattern
; str
++,pattern
++) {
2528 if (*pattern
== '*') {
2530 while(*pattern
== '*');
2536 if (*str
==*pattern
&& pattern_match(str
, pattern
))
2541 else if (*str
!=*pattern
&& *pattern
!='?')
2545 if (*str
|| *pattern
)
2546 if (*pattern
!='*' || pattern
[1]!='\0')
2552 static BOOL
pattern_imatch(LPCWSTR str
, LPCWSTR pattern
)
2554 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2557 lstrcpyW(b2
, pattern
);
2561 return pattern_match(b1
, b2
);
2571 static enum FILE_TYPE
get_file_type(LPCWSTR filename
);
2574 /* insert listbox entries after index idx */
2576 static int insert_entries(Pane
* pane
, Entry
* dir
, LPCWSTR pattern
, int filter_flags
, int idx
)
2583 ShowWindow(pane
->hwnd
, SW_HIDE
);
2585 for(; entry
; entry
=entry
->next
) {
2586 if (pane
->treePane
&& !(entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
2589 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
2590 /* don't display entries "." and ".." in the left pane */
2591 if (pane
->treePane
&& entry
->data
.cFileName
[0] == '.')
2592 if (entry
->data
.cFileName
[1] == '\0' ||
2593 (entry
->data
.cFileName
[1] == '.' &&
2594 entry
->data
.cFileName
[2] == '\0'))
2597 /* filter directories in right pane */
2598 if (!pane
->treePane
&& !(filter_flags
&TF_DIRECTORIES
))
2602 /* filter using the file name pattern */
2604 if (!pattern_imatch(entry
->data
.cFileName
, pattern
))
2607 /* filter system and hidden files */
2608 if (!(filter_flags
&TF_HIDDEN
) && (entry
->data
.dwFileAttributes
&(FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
)))
2611 /* filter looking at the file type */
2612 if ((filter_flags
&(TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
)) != (TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
))
2613 switch(get_file_type(entry
->data
.cFileName
)) {
2615 if (!(filter_flags
& TF_PROGRAMS
))
2620 if (!(filter_flags
& TF_DOCUMENTS
))
2624 default: /* TF_OTHERS */
2625 if (!(filter_flags
& TF_OTHERS
))
2632 SendMessageW(pane
->hwnd
, LB_INSERTSTRING
, idx
, (LPARAM
)entry
);
2634 if (pane
->treePane
&& entry
->expanded
)
2635 idx
= insert_entries(pane
, entry
->down
, pattern
, filter_flags
, idx
);
2638 ShowWindow(pane
->hwnd
, SW_SHOW
);
2643 static void set_space_status(void)
2645 ULARGE_INTEGER ulFreeBytesToCaller
, ulTotalBytes
, ulFreeBytes
;
2646 WCHAR fmt
[64], b1
[64], b2
[64], buffer
[BUFFER_LEN
];
2648 if (GetDiskFreeSpaceExW(NULL
, &ulFreeBytesToCaller
, &ulTotalBytes
, &ulFreeBytes
)) {
2651 args
[0] = (DWORD_PTR
)StrFormatByteSizeW(ulFreeBytesToCaller
.QuadPart
, b1
, sizeof(b1
)/sizeof(*b1
));
2652 args
[1] = (DWORD_PTR
)StrFormatByteSizeW(ulTotalBytes
.QuadPart
, b2
, sizeof(b2
)/sizeof(*b2
));
2654 FormatMessageW(FORMAT_MESSAGE_FROM_STRING
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
2655 RS(fmt
,IDS_FREE_SPACE_FMT
), 0, 0, buffer
,
2656 sizeof(buffer
)/sizeof(*buffer
), (__ms_va_list
*)args
);
2658 lstrcpyW(buffer
, sQMarks
);
2660 SendMessageW(Globals
.hstatusbar
, SB_SETTEXTW
, 0, (LPARAM
)buffer
);
2664 static WNDPROC g_orgTreeWndProc
;
2666 static void create_tree_window(HWND parent
, Pane
* pane
, UINT id
, UINT id_header
, LPCWSTR pattern
, int filter_flags
)
2668 static const WCHAR sListBox
[] = {'L','i','s','t','B','o','x','\0'};
2670 static BOOL s_init
= FALSE
;
2671 Entry
* entry
= pane
->root
;
2673 pane
->hwnd
= CreateWindowW(sListBox
, sEmpty
, WS_CHILD
|WS_VISIBLE
|WS_HSCROLL
|WS_VSCROLL
|
2674 LBS_DISABLENOSCROLL
|LBS_NOINTEGRALHEIGHT
|LBS_OWNERDRAWFIXED
|LBS_NOTIFY
,
2675 0, 0, 0, 0, parent
, (HMENU
)ULongToHandle(id
), Globals
.hInstance
, 0);
2677 SetWindowLongPtrW(pane
->hwnd
, GWLP_USERDATA
, (LPARAM
)pane
);
2678 g_orgTreeWndProc
= (WNDPROC
)SetWindowLongPtrW(pane
->hwnd
, GWLP_WNDPROC
, (LPARAM
)TreeWndProc
);
2680 SendMessageW(pane
->hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, FALSE
);
2682 /* insert entries into listbox */
2684 insert_entries(pane
, entry
, pattern
, filter_flags
, -1);
2686 /* calculate column widths */
2689 init_output(pane
->hwnd
);
2692 calc_widths(pane
, TRUE
);
2694 pane
->hwndHeader
= create_header(parent
, pane
, id_header
);
2698 static void InitChildWindow(ChildWnd
* child
)
2700 create_tree_window(child
->hwnd
, &child
->left
, IDW_TREE_LEFT
, IDW_HEADER_LEFT
, NULL
, TF_ALL
);
2701 create_tree_window(child
->hwnd
, &child
->right
, IDW_TREE_RIGHT
, IDW_HEADER_RIGHT
, child
->filter_pattern
, child
->filter_flags
);
2705 static void format_date(const FILETIME
* ft
, WCHAR
* buffer
, int visible_cols
)
2713 if (!ft
->dwLowDateTime
&& !ft
->dwHighDateTime
)
2716 if (!FileTimeToLocalFileTime(ft
, &lft
))
2717 {err
: lstrcpyW(buffer
,sQMarks
); return;}
2719 if (!FileTimeToSystemTime(&lft
, &systime
))
2722 if (visible_cols
& COL_DATE
) {
2723 len
= GetDateFormatW(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
, BUFFER_LEN
);
2728 if (visible_cols
& COL_TIME
) {
2730 buffer
[len
-1] = ' ';
2732 buffer
[len
++] = ' ';
2734 if (!GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
+len
, BUFFER_LEN
-len
))
2740 static void calc_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
)
2742 RECT rt
= {0, 0, 0, 0};
2744 DrawTextW(dis
->hDC
, str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
2746 if (rt
.right
> pane
->widths
[col
])
2747 pane
->widths
[col
] = rt
.right
;
2750 static void calc_tabbed_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
)
2752 RECT rt
= {0, 0, 0, 0};
2754 DrawTextW(dis
->hDC
, str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2755 /*FIXME rt (0,0) ??? */
2757 if (rt
.right
> pane
->widths
[col
])
2758 pane
->widths
[col
] = rt
.right
;
2762 static void output_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
, DWORD flags
)
2764 int x
= dis
->rcItem
.left
;
2767 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2768 rt
.top
= dis
->rcItem
.top
;
2769 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2770 rt
.bottom
= dis
->rcItem
.bottom
;
2772 DrawTextW(dis
->hDC
, str
, -1, &rt
, DT_SINGLELINE
|DT_NOPREFIX
|flags
);
2775 static void output_tabbed_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
)
2777 int x
= dis
->rcItem
.left
;
2780 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2781 rt
.top
= dis
->rcItem
.top
;
2782 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2783 rt
.bottom
= dis
->rcItem
.bottom
;
2785 DrawTextW(dis
->hDC
, str
, -1, &rt
, DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2788 static void output_number(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
)
2790 int x
= dis
->rcItem
.left
;
2797 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2798 rt
.top
= dis
->rcItem
.top
;
2799 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2800 rt
.bottom
= dis
->rcItem
.bottom
;
2805 /* insert number separator characters */
2806 pos
= lstrlenW(s
) % 3;
2812 *d
++ = Globals
.num_sep
;
2816 DrawTextW(dis
->hDC
, b
, d
-b
, &rt
, DT_RIGHT
|DT_SINGLELINE
|DT_NOPREFIX
|DT_END_ELLIPSIS
);
2820 static BOOL
is_exe_file(LPCWSTR ext
)
2822 static const WCHAR executable_extensions
[][4] = {
2833 WCHAR ext_buffer
[_MAX_EXT
];
2834 const WCHAR (*p
)[4];
2838 for(s
=ext
+1,d
=ext_buffer
; (*d
=tolower(*s
)); s
++)
2841 for(p
=executable_extensions
; (*p
)[0]; p
++)
2842 if (!lstrcmpiW(ext_buffer
, *p
))
2848 static BOOL
is_registered_type(LPCWSTR ext
)
2850 /* check if there exists a classname for this file extension in the registry */
2851 if (!RegQueryValueW(HKEY_CLASSES_ROOT
, ext
, NULL
, NULL
))
2857 static enum FILE_TYPE
get_file_type(LPCWSTR filename
)
2859 LPCWSTR ext
= strrchrW(filename
, '.');
2863 if (is_exe_file(ext
))
2864 return FT_EXECUTABLE
;
2865 else if (is_registered_type(ext
))
2872 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
)
2874 WCHAR buffer
[BUFFER_LEN
];
2876 int visible_cols
= pane
->visible_cols
;
2877 COLORREF bkcolor
, textcolor
;
2878 RECT focusRect
= dis
->rcItem
;
2885 attrs
= entry
->data
.dwFileAttributes
;
2887 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) {
2888 if (entry
->data
.cFileName
[0] == '.' && entry
->data
.cFileName
[1] == '.'
2889 && entry
->data
.cFileName
[2] == '\0')
2890 img
= IMG_FOLDER_UP
;
2891 else if (entry
->data
.cFileName
[0] == '.' && entry
->data
.cFileName
[1] == '\0')
2892 img
= IMG_FOLDER_CUR
;
2893 else if (pane
->treePane
&& (dis
->itemState
&ODS_FOCUS
))
2894 img
= IMG_OPEN_FOLDER
;
2898 switch(get_file_type(entry
->data
.cFileName
)) {
2899 case FT_EXECUTABLE
: img
= IMG_EXECUTABLE
; break;
2900 case FT_DOCUMENT
: img
= IMG_DOCUMENT
; break;
2901 default: img
= IMG_FILE
;
2909 if (pane
->treePane
) {
2911 img_pos
= dis
->rcItem
.left
+ entry
->level
*(IMAGE_WIDTH
+TREE_LINE_DX
);
2913 if (calcWidthCol
== -1) {
2915 int y
= dis
->rcItem
.top
+ IMAGE_HEIGHT
/2;
2918 HRGN hrgn_org
= CreateRectRgn(0, 0, 0, 0);
2921 rt_clip
.left
= dis
->rcItem
.left
;
2922 rt_clip
.top
= dis
->rcItem
.top
;
2923 rt_clip
.right
= dis
->rcItem
.left
+pane
->widths
[col
];
2924 rt_clip
.bottom
= dis
->rcItem
.bottom
;
2926 hrgn
= CreateRectRgnIndirect(&rt_clip
);
2928 if (!GetClipRgn(dis
->hDC
, hrgn_org
)) {
2929 DeleteObject(hrgn_org
);
2933 ExtSelectClipRgn(dis
->hDC
, hrgn
, RGN_AND
);
2936 if ((up
=entry
->up
) != NULL
) {
2937 MoveToEx(dis
->hDC
, img_pos
-IMAGE_WIDTH
/2, y
, 0);
2938 LineTo(dis
->hDC
, img_pos
-2, y
);
2940 x
= img_pos
- IMAGE_WIDTH
/2;
2943 x
-= IMAGE_WIDTH
+TREE_LINE_DX
;
2946 && (up
->next
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
2948 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
2949 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
2951 } while((up
=up
->up
) != NULL
);
2954 x
= img_pos
- IMAGE_WIDTH
/2;
2956 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
2957 LineTo(dis
->hDC
, x
, y
);
2960 && (entry
->next
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
2961 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
2963 SelectClipRgn(dis
->hDC
, hrgn_org
);
2964 if (hrgn_org
) DeleteObject(hrgn_org
);
2965 } else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
) {
2966 int right
= img_pos
+ IMAGE_WIDTH
- TREE_LINE_DX
;
2968 if (right
> pane
->widths
[col
])
2969 pane
->widths
[col
] = right
;
2972 img_pos
= dis
->rcItem
.left
;
2975 img_pos
= dis
->rcItem
.left
;
2977 if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2978 pane
->widths
[col
] = IMAGE_WIDTH
;
2981 if (calcWidthCol
== -1) {
2982 focusRect
.left
= img_pos
-2;
2984 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
)
2985 textcolor
= COLOR_COMPRESSED
;
2987 textcolor
= RGB(0,0,0);
2989 if (dis
->itemState
& ODS_FOCUS
) {
2990 textcolor
= RGB(255,255,255);
2991 bkcolor
= COLOR_SELECTION
;
2993 bkcolor
= RGB(255,255,255);
2996 hbrush
= CreateSolidBrush(bkcolor
);
2997 FillRect(dis
->hDC
, &focusRect
, hbrush
);
2998 DeleteObject(hbrush
);
3000 SetBkMode(dis
->hDC
, TRANSPARENT
);
3001 SetTextColor(dis
->hDC
, textcolor
);
3003 cx
= pane
->widths
[col
];
3005 if (cx
&& img
!=IMG_NONE
) {
3006 if (cx
> IMAGE_WIDTH
)
3009 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
3010 DrawIconEx(dis
->hDC
, img_pos
, dis
->rcItem
.top
, entry
->hicon
, cx
, GetSystemMetrics(SM_CYSMICON
), 0, 0, DI_NORMAL
);
3012 ImageList_DrawEx(Globals
.himl
, img
, dis
->hDC
,
3013 img_pos
, dis
->rcItem
.top
, cx
,
3014 IMAGE_HEIGHT
, bkcolor
, CLR_DEFAULT
, ILD_NORMAL
);
3023 /* output file name */
3024 if (calcWidthCol
== -1)
3025 output_text(pane
, dis
, col
, entry
->data
.cFileName
, 0);
3026 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3027 calc_width(pane
, dis
, col
, entry
->data
.cFileName
);
3031 /* display file size */
3032 if (visible_cols
& COL_SIZE
) {
3033 format_longlong( buffer
, ((ULONGLONG
)entry
->data
.nFileSizeHigh
<< 32) | entry
->data
.nFileSizeLow
);
3035 if (calcWidthCol
== -1)
3036 output_number(pane
, dis
, col
, buffer
);
3037 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3038 calc_width(pane
, dis
, col
, buffer
);/*TODO: not ever time enough */
3043 /* display file date */
3044 if (visible_cols
& (COL_DATE
|COL_TIME
)) {
3045 format_date(&entry
->data
.ftCreationTime
, buffer
, visible_cols
);
3046 if (calcWidthCol
== -1)
3047 output_text(pane
, dis
, col
, buffer
, 0);
3048 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3049 calc_width(pane
, dis
, col
, buffer
);
3052 format_date(&entry
->data
.ftLastAccessTime
, buffer
, visible_cols
);
3053 if (calcWidthCol
== -1)
3054 output_text(pane
, dis
, col
, buffer
, 0);
3055 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3056 calc_width(pane
, dis
, col
, buffer
);
3059 format_date(&entry
->data
.ftLastWriteTime
, buffer
, visible_cols
);
3060 if (calcWidthCol
== -1)
3061 output_text(pane
, dis
, col
, buffer
, 0);
3062 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3063 calc_width(pane
, dis
, col
, buffer
);
3067 if (entry
->bhfi_valid
) {
3068 if (visible_cols
& COL_INDEX
) {
3069 static const WCHAR fmtlow
[] = {'%','X',0};
3070 static const WCHAR fmthigh
[] = {'%','X','%','0','8','X',0};
3072 if (entry
->bhfi
.nFileIndexHigh
)
3073 wsprintfW(buffer
, fmthigh
,
3074 entry
->bhfi
.nFileIndexHigh
, entry
->bhfi
.nFileIndexLow
);
3076 wsprintfW(buffer
, fmtlow
, entry
->bhfi
.nFileIndexLow
);
3078 if (calcWidthCol
== -1)
3079 output_text(pane
, dis
, col
, buffer
, DT_RIGHT
);
3080 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3081 calc_width(pane
, dis
, col
, buffer
);
3086 if (visible_cols
& COL_LINKS
) {
3087 wsprintfW(buffer
, sNumFmt
, entry
->bhfi
.nNumberOfLinks
);
3089 if (calcWidthCol
== -1)
3090 output_text(pane
, dis
, col
, buffer
, DT_CENTER
);
3091 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3092 calc_width(pane
, dis
, col
, buffer
);
3099 /* show file attributes */
3100 if (visible_cols
& COL_ATTRIBUTES
) {
3101 static const WCHAR s11Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3102 lstrcpyW(buffer
, s11Tabs
);
3104 if (attrs
& FILE_ATTRIBUTE_NORMAL
) buffer
[ 0] = 'N';
3106 if (attrs
& FILE_ATTRIBUTE_READONLY
) buffer
[ 2] = 'R';
3107 if (attrs
& FILE_ATTRIBUTE_HIDDEN
) buffer
[ 4] = 'H';
3108 if (attrs
& FILE_ATTRIBUTE_SYSTEM
) buffer
[ 6] = 'S';
3109 if (attrs
& FILE_ATTRIBUTE_ARCHIVE
) buffer
[ 8] = 'A';
3110 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
) buffer
[10] = 'C';
3111 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) buffer
[12] = 'D';
3112 if (attrs
& FILE_ATTRIBUTE_ENCRYPTED
) buffer
[14] = 'E';
3113 if (attrs
& FILE_ATTRIBUTE_TEMPORARY
) buffer
[16] = 'T';
3114 if (attrs
& FILE_ATTRIBUTE_SPARSE_FILE
) buffer
[18] = 'P';
3115 if (attrs
& FILE_ATTRIBUTE_REPARSE_POINT
) buffer
[20] = 'Q';
3116 if (attrs
& FILE_ATTRIBUTE_OFFLINE
) buffer
[22] = 'O';
3117 if (attrs
& FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
) buffer
[24] = 'X';
3120 if (calcWidthCol
== -1)
3121 output_tabbed_text(pane
, dis
, col
, buffer
);
3122 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3123 calc_tabbed_width(pane
, dis
, col
, buffer
);
3129 static void set_header(Pane
* pane
)
3132 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3135 item
.mask
= HDI_WIDTH
;
3137 for (i
= 0; i
< COLUMNS
; ++i
) {
3138 if (pane
->positions
[i
] >= scroll_pos
) {
3139 item
.cxy
= pane
->widths
[i
];
3140 } else if (pane
->positions
[i
+1] <= scroll_pos
) {
3143 item
.cxy
= pane
->positions
[i
+1] - scroll_pos
;
3145 pane
->widths_shown
[i
] = item
.cxy
;
3146 SendMessageW(pane
->hwndHeader
, HDM_SETITEMW
, i
, (LPARAM
)&item
);
3150 static LRESULT
pane_notify(Pane
* pane
, NMHDR
* pnmh
)
3152 switch(pnmh
->code
) {
3153 case HDN_ITEMCHANGEDW
: {
3154 LPNMHEADERW phdn
= (LPNMHEADERW
)pnmh
;
3155 int idx
= phdn
->iItem
;
3156 int dx
= phdn
->pitem
->cxy
- pane
->widths_shown
[idx
];
3160 GetClientRect(pane
->hwnd
, &clnt
);
3162 pane
->widths
[idx
] += dx
;
3163 pane
->widths_shown
[idx
] += dx
;
3165 for(i
=idx
; ++i
<=COLUMNS
; )
3166 pane
->positions
[i
] += dx
;
3169 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3173 rt_scr
.left
= pane
->positions
[idx
+1]-scroll_pos
;
3175 rt_scr
.right
= clnt
.right
;
3176 rt_scr
.bottom
= clnt
.bottom
;
3178 rt_clip
.left
= pane
->positions
[idx
]-scroll_pos
;
3180 rt_clip
.right
= clnt
.right
;
3181 rt_clip
.bottom
= clnt
.bottom
;
3183 if (rt_scr
.left
< 0) rt_scr
.left
= 0;
3184 if (rt_clip
.left
< 0) rt_clip
.left
= 0;
3186 ScrollWindowEx(pane
->hwnd
, dx
, 0, &rt_scr
, &rt_clip
, 0, 0, SW_INVALIDATE
);
3188 rt_clip
.right
= pane
->positions
[idx
+1];
3189 RedrawWindow(pane
->hwnd
, &rt_clip
, 0, RDW_INVALIDATE
|RDW_UPDATENOW
);
3191 if (pnmh
->code
== HDN_ENDTRACKW
) {
3192 SendMessageW(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, pane
->positions
[COLUMNS
], 0);
3194 if (GetScrollPos(pane
->hwnd
, SB_HORZ
) != scroll_pos
)
3202 case HDN_DIVIDERDBLCLICKW
: {
3203 LPNMHEADERW phdn
= (LPNMHEADERW
)pnmh
;
3206 calc_single_width(pane
, phdn
->iItem
);
3207 item
.mask
= HDI_WIDTH
;
3208 item
.cxy
= pane
->widths
[phdn
->iItem
];
3210 SendMessageW(pane
->hwndHeader
, HDM_SETITEMW
, phdn
->iItem
, (LPARAM
)&item
);
3211 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3218 static void scan_entry(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3220 WCHAR path
[MAX_PATH
];
3221 HCURSOR old_cursor
= SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_WAIT
));
3223 /* delete sub entries in left pane */
3225 LRESULT res
= SendMessageW(child
->left
.hwnd
, LB_GETITEMDATA
, idx
+1, 0);
3226 Entry
* sub
= (Entry
*) res
;
3228 if (res
==LB_ERR
|| !sub
|| sub
->level
<=entry
->level
)
3231 SendMessageW(child
->left
.hwnd
, LB_DELETESTRING
, idx
+1, 0);
3234 /* empty right pane */
3235 SendMessageW(child
->right
.hwnd
, LB_RESETCONTENT
, 0, 0);
3237 /* release memory */
3238 free_entries(entry
);
3240 /* read contents from disk */
3241 if (entry
->etype
== ET_SHELL
)
3243 read_directory(entry
, NULL
, child
->sortOrder
, hwnd
);
3247 get_path(entry
, path
);
3248 read_directory(entry
, path
, child
->sortOrder
, hwnd
);
3251 /* insert found entries in right pane */
3252 insert_entries(&child
->right
, entry
->down
, child
->filter_pattern
, child
->filter_flags
, -1);
3253 calc_widths(&child
->right
, FALSE
);
3254 set_header(&child
->right
);
3256 child
->header_wdths_ok
= FALSE
;
3258 SetCursor(old_cursor
);
3262 /* expand a directory entry */
3264 static BOOL
expand_entry(ChildWnd
* child
, Entry
* dir
)
3269 if (!dir
|| dir
->expanded
|| !dir
->down
)
3274 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='\0' && p
->next
) {
3277 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='.' &&
3278 p
->data
.cFileName
[2]=='\0' && p
->next
)
3282 /* no subdirectories ? */
3283 if (!(p
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
3286 idx
= SendMessageW(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)dir
);
3288 dir
->expanded
= TRUE
;
3290 /* insert entries in left pane */
3291 insert_entries(&child
->left
, p
, NULL
, TF_ALL
, idx
);
3293 if (!child
->header_wdths_ok
) {
3294 if (calc_widths(&child
->left
, FALSE
)) {
3295 set_header(&child
->left
);
3297 child
->header_wdths_ok
= TRUE
;
3305 static void collapse_entry(Pane
* pane
, Entry
* dir
)
3310 idx
= SendMessageW(pane
->hwnd
, LB_FINDSTRING
, 0, (LPARAM
)dir
);
3312 ShowWindow(pane
->hwnd
, SW_HIDE
);
3314 /* hide sub entries */
3316 LRESULT res
= SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, idx
+1, 0);
3317 Entry
* sub
= (Entry
*) res
;
3319 if (res
==LB_ERR
|| !sub
|| sub
->level
<=dir
->level
)
3322 SendMessageW(pane
->hwnd
, LB_DELETESTRING
, idx
+1, 0);
3325 dir
->expanded
= FALSE
;
3327 ShowWindow(pane
->hwnd
, SW_SHOW
);
3331 static void refresh_right_pane(ChildWnd
* child
)
3333 SendMessageW(child
->right
.hwnd
, LB_RESETCONTENT
, 0, 0);
3334 insert_entries(&child
->right
, child
->right
.root
, child
->filter_pattern
, child
->filter_flags
, -1);
3335 calc_widths(&child
->right
, FALSE
);
3337 set_header(&child
->right
);
3340 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3342 WCHAR path
[MAX_PATH
];
3349 child
->left
.cur
= entry
;
3351 child
->right
.root
= entry
->down
? entry
->down
: entry
;
3352 child
->right
.cur
= entry
;
3354 if (!entry
->scanned
)
3355 scan_entry(child
, entry
, idx
, hwnd
);
3357 refresh_right_pane(child
);
3359 get_path(entry
, path
);
3360 lstrcpyW(child
->path
, path
);
3362 if (child
->hwnd
) /* only change window title, if the window already exists */
3363 SetWindowTextW(child
->hwnd
, path
);
3366 if (SetCurrentDirectoryW(path
))
3371 static void refresh_child(ChildWnd
* child
)
3373 WCHAR path
[MAX_PATH
], drv
[_MAX_DRIVE
+1];
3377 get_path(child
->left
.cur
, path
);
3378 _wsplitpath(path
, drv
, NULL
, NULL
, NULL
);
3380 child
->right
.root
= NULL
;
3382 scan_entry(child
, &child
->root
.entry
, 0, child
->hwnd
);
3384 if (child
->root
.entry
.etype
== ET_SHELL
)
3386 LPITEMIDLIST local_pidl
= get_path_pidl(path
,child
->hwnd
);
3388 entry
= read_tree(&child
->root
, NULL
, local_pidl
, drv
, child
->sortOrder
, child
->hwnd
);
3393 entry
= read_tree(&child
->root
, path
, NULL
, drv
, child
->sortOrder
, child
->hwnd
);
3396 entry
= &child
->root
.entry
;
3398 insert_entries(&child
->left
, child
->root
.entry
.down
, NULL
, TF_ALL
, 0);
3400 set_curdir(child
, entry
, 0, child
->hwnd
);
3402 idx
= SendMessageW(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)child
->left
.cur
);
3403 SendMessageW(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
3407 static void create_drive_bar(void)
3409 TBBUTTON drivebarBtn
= {0, 0, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0};
3410 WCHAR b1
[BUFFER_LEN
];
3414 GetLogicalDriveStringsW(BUFFER_LEN
, Globals
.drives
);
3416 Globals
.hdrivebar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
,
3417 IDW_DRIVEBAR
, 2, Globals
.hInstance
, IDB_DRIVEBAR
, &drivebarBtn
,
3418 0, 16, 13, 16, 13, sizeof(TBBUTTON
));
3421 /* insert unix file system button */
3425 SendMessageW(Globals
.hdrivebar
, TB_ADDSTRINGW
, 0, (LPARAM
)b1
);
3427 drivebarBtn
.idCommand
= ID_DRIVE_UNIX_FS
;
3428 SendMessageW(Globals
.hdrivebar
, TB_INSERTBUTTONW
, btn
++, (LPARAM
)&drivebarBtn
);
3429 drivebarBtn
.iString
++;
3431 /* insert shell namespace button */
3432 load_string(b1
, sizeof(b1
)/sizeof(b1
[0]), IDS_SHELL
);
3433 b1
[lstrlenW(b1
)+1] = '\0';
3434 SendMessageW(Globals
.hdrivebar
, TB_ADDSTRINGW
, 0, (LPARAM
)b1
);
3436 drivebarBtn
.idCommand
= ID_DRIVE_SHELL_NS
;
3437 SendMessageW(Globals
.hdrivebar
, TB_INSERTBUTTONW
, btn
++, (LPARAM
)&drivebarBtn
);
3438 drivebarBtn
.iString
++;
3440 /* register windows drive root strings */
3441 SendMessageW(Globals
.hdrivebar
, TB_ADDSTRINGW
, 0, (LPARAM
)Globals
.drives
);
3443 drivebarBtn
.idCommand
= ID_DRIVE_FIRST
;
3445 for(p
=Globals
.drives
; *p
; ) {
3446 switch(GetDriveTypeW(p
)) {
3447 case DRIVE_REMOVABLE
: drivebarBtn
.iBitmap
= 1; break;
3448 case DRIVE_CDROM
: drivebarBtn
.iBitmap
= 3; break;
3449 case DRIVE_REMOTE
: drivebarBtn
.iBitmap
= 4; break;
3450 case DRIVE_RAMDISK
: drivebarBtn
.iBitmap
= 5; break;
3451 default:/*DRIVE_FIXED*/ drivebarBtn
.iBitmap
= 2;
3454 SendMessageW(Globals
.hdrivebar
, TB_INSERTBUTTONW
, btn
++, (LPARAM
)&drivebarBtn
);
3455 drivebarBtn
.idCommand
++;
3456 drivebarBtn
.iString
++;
3462 static void refresh_drives(void)
3466 /* destroy drive bar */
3467 DestroyWindow(Globals
.hdrivebar
);
3468 Globals
.hdrivebar
= 0;
3470 /* re-create drive bar */
3473 /* update window layout */
3474 GetClientRect(Globals
.hMainWnd
, &rect
);
3475 SendMessageW(Globals
.hMainWnd
, WM_SIZE
, 0, MAKELONG(rect
.right
, rect
.bottom
));
3479 static BOOL
launch_file(HWND hwnd
, LPCWSTR cmd
, UINT nCmdShow
)
3481 HINSTANCE hinst
= ShellExecuteW(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3483 if (PtrToUlong(hinst
) <= 32) {
3484 display_error(hwnd
, GetLastError());
3492 static BOOL
launch_entry(Entry
* entry
, HWND hwnd
, UINT nCmdShow
)
3494 WCHAR cmd
[MAX_PATH
];
3496 if (entry
->etype
== ET_SHELL
) {
3499 SHELLEXECUTEINFOW shexinfo
;
3501 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFOW
);
3502 shexinfo
.fMask
= SEE_MASK_IDLIST
;
3503 shexinfo
.hwnd
= hwnd
;
3504 shexinfo
.lpVerb
= NULL
;
3505 shexinfo
.lpFile
= NULL
;
3506 shexinfo
.lpParameters
= NULL
;
3507 shexinfo
.lpDirectory
= NULL
;
3508 shexinfo
.nShow
= nCmdShow
;
3509 shexinfo
.lpIDList
= get_to_absolute_pidl(entry
, hwnd
);
3511 if (!ShellExecuteExW(&shexinfo
)) {
3512 display_error(hwnd
, GetLastError());
3516 if (shexinfo
.lpIDList
!= entry
->pidl
)
3517 IMalloc_Free(Globals
.iMalloc
, shexinfo
.lpIDList
);
3522 get_path(entry
, cmd
);
3524 /* start program, open document... */
3525 return launch_file(hwnd
, cmd
, nCmdShow
);
3529 static void activate_entry(ChildWnd
* child
, Pane
* pane
, HWND hwnd
)
3531 Entry
* entry
= pane
->cur
;
3536 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
3537 int scanned_old
= entry
->scanned
;
3541 int idx
= SendMessageW(child
->left
.hwnd
, LB_GETCURSEL
, 0, 0);
3542 scan_entry(child
, entry
, idx
, hwnd
);
3545 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='\0')
3548 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='.' && entry
->data
.cFileName
[2]=='\0') {
3549 entry
= child
->left
.cur
->up
;
3550 collapse_entry(&child
->left
, entry
);
3552 } else if (entry
->expanded
)
3553 collapse_entry(pane
, child
->left
.cur
);
3555 expand_entry(child
, child
->left
.cur
);
3557 if (!pane
->treePane
) focus_entry
: {
3558 int idxstart
= SendMessageW(child
->left
.hwnd
, LB_GETCURSEL
, 0, 0);
3559 int idx
= SendMessageW(child
->left
.hwnd
, LB_FINDSTRING
, idxstart
, (LPARAM
)entry
);
3560 SendMessageW(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
3561 set_curdir(child
, entry
, idx
, hwnd
);
3566 calc_widths(pane
, FALSE
);
3571 if (GetKeyState(VK_MENU
) < 0)
3572 show_properties_dlg(entry
, child
->hwnd
);
3574 launch_entry(entry
, child
->hwnd
, SW_SHOWNORMAL
);
3579 static BOOL
pane_command(Pane
* pane
, UINT cmd
)
3583 if (pane
->visible_cols
) {
3584 pane
->visible_cols
= 0;
3585 calc_widths(pane
, TRUE
);
3587 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3588 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
|MF_CHECKED
);
3589 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
);
3593 case ID_VIEW_ALL_ATTRIBUTES
:
3594 if (pane
->visible_cols
!= COL_ALL
) {
3595 pane
->visible_cols
= COL_ALL
;
3596 calc_widths(pane
, TRUE
);
3598 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3599 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
);
3600 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
|MF_CHECKED
);
3604 case ID_PREFERRED_SIZES
: {
3605 calc_widths(pane
, TRUE
);
3607 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3610 /* TODO: more command ids... */
3620 static void set_sort_order(ChildWnd
* child
, SORT_ORDER sortOrder
)
3622 if (child
->sortOrder
!= sortOrder
) {
3623 child
->sortOrder
= sortOrder
;
3624 refresh_child(child
);
3628 static void update_view_menu(ChildWnd
* child
)
3630 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_NAME
, child
->sortOrder
==SORT_NAME
? MF_CHECKED
: MF_UNCHECKED
);
3631 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_TYPE
, child
->sortOrder
==SORT_EXT
? MF_CHECKED
: MF_UNCHECKED
);
3632 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_SIZE
, child
->sortOrder
==SORT_SIZE
? MF_CHECKED
: MF_UNCHECKED
);
3633 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_DATE
, child
->sortOrder
==SORT_DATE
? MF_CHECKED
: MF_UNCHECKED
);
3637 static BOOL
is_directory(LPCWSTR target
)
3639 /*TODO correctly handle UNIX paths */
3640 DWORD target_attr
= GetFileAttributesW(target
);
3642 if (target_attr
== INVALID_FILE_ATTRIBUTES
)
3645 return (target_attr
& FILE_ATTRIBUTE_DIRECTORY
) != 0;
3648 static BOOL
prompt_target(Pane
* pane
, LPWSTR source
, LPWSTR target
)
3650 WCHAR path
[MAX_PATH
];
3653 get_path(pane
->cur
, path
);
3655 if (DialogBoxParamW(Globals
.hInstance
, MAKEINTRESOURCEW(IDD_SELECT_DESTINATION
), pane
->hwnd
, DestinationDlgProc
, (LPARAM
)path
) != IDOK
)
3658 get_path(pane
->cur
, source
);
3660 /* convert relative targets to absolute paths */
3661 if (path
[0]!='/' && path
[1]!=':') {
3662 get_path(pane
->cur
->up
, target
);
3663 len
= lstrlenW(target
);
3665 if (target
[len
-1]!='\\' && target
[len
-1]!='/')
3666 target
[len
++] = '/';
3668 lstrcpyW(target
+len
, path
);
3670 lstrcpyW(target
, path
);
3672 /* If the target already exists as directory, create a new target below this. */
3673 if (is_directory(path
)) {
3674 WCHAR fname
[_MAX_FNAME
], ext
[_MAX_EXT
];
3675 static const WCHAR sAppend
[] = {'%','s','/','%','s','%','s','\0'};
3677 _wsplitpath(source
, NULL
, NULL
, fname
, ext
);
3679 wsprintfW(target
, sAppend
, path
, fname
, ext
);
3686 static IContextMenu2
* s_pctxmenu2
= NULL
;
3687 static IContextMenu3
* s_pctxmenu3
= NULL
;
3689 static void CtxMenu_reset(void)
3695 static IContextMenu
* CtxMenu_query_interfaces(IContextMenu
* pcm1
)
3697 IContextMenu
* pcm
= NULL
;
3701 if (IContextMenu_QueryInterface(pcm1
, &IID_IContextMenu3
, (void**)&pcm
) == NOERROR
)
3702 s_pctxmenu3
= (LPCONTEXTMENU3
)pcm
;
3703 else if (IContextMenu_QueryInterface(pcm1
, &IID_IContextMenu2
, (void**)&pcm
) == NOERROR
)
3704 s_pctxmenu2
= (LPCONTEXTMENU2
)pcm
;
3707 IContextMenu_Release(pcm1
);
3713 static BOOL
CtxMenu_HandleMenuMsg(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3716 if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3
, nmsg
, wparam
, lparam
)))
3721 if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2
, nmsg
, wparam
, lparam
)))
3727 static HRESULT
ShellFolderContextMenu(IShellFolder
* shell_folder
, HWND hwndParent
, int cidl
, LPCITEMIDLIST
* apidl
, int x
, int y
)
3730 BOOL executed
= FALSE
;
3732 HRESULT hr
= IShellFolder_GetUIObjectOf(shell_folder
, hwndParent
, cidl
, apidl
, &IID_IContextMenu
, NULL
, (LPVOID
*)&pcm
);
3734 if (SUCCEEDED(hr
)) {
3735 HMENU hmenu
= CreatePopupMenu();
3737 pcm
= CtxMenu_query_interfaces(pcm
);
3740 hr
= IContextMenu_QueryContextMenu(pcm
, hmenu
, 0, FCIDM_SHVIEWFIRST
, FCIDM_SHVIEWLAST
, CMF_NORMAL
);
3742 if (SUCCEEDED(hr
)) {
3743 UINT idCmd
= TrackPopupMenu(hmenu
, TPM_LEFTALIGN
|TPM_RETURNCMD
|TPM_RIGHTBUTTON
, x
, y
, 0, hwndParent
, NULL
);
3748 CMINVOKECOMMANDINFO cmi
;
3750 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFO
);
3752 cmi
.hwnd
= hwndParent
;
3753 cmi
.lpVerb
= (LPCSTR
)(INT_PTR
)(idCmd
- FCIDM_SHVIEWFIRST
);
3754 cmi
.lpParameters
= NULL
;
3755 cmi
.lpDirectory
= NULL
;
3756 cmi
.nShow
= SW_SHOWNORMAL
;
3760 hr
= IContextMenu_InvokeCommand(pcm
, &cmi
);
3767 IContextMenu_Release(pcm
);
3770 return FAILED(hr
)? hr
: executed
? S_OK
: S_FALSE
;
3773 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3775 ChildWnd
* child
= (ChildWnd
*)GetWindowLongPtrW(hwnd
, GWLP_USERDATA
);
3780 LPDRAWITEMSTRUCT dis
= (LPDRAWITEMSTRUCT
)lparam
;
3781 Entry
* entry
= (Entry
*) dis
->itemData
;
3783 if (dis
->CtlID
== IDW_TREE_LEFT
)
3784 draw_item(&child
->left
, dis
, entry
, -1);
3785 else if (dis
->CtlID
== IDW_TREE_RIGHT
)
3786 draw_item(&child
->right
, dis
, entry
, -1);
3788 goto draw_menu_item
;
3793 InitChildWindow(child
);
3797 free_child_window(child
);
3798 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, 0);
3805 GetClientRect(hwnd
, &rt
);
3806 BeginPaint(hwnd
, &ps
);
3807 rt
.left
= child
->split_pos
-SPLIT_WIDTH
/2;
3808 rt
.right
= child
->split_pos
+SPLIT_WIDTH
/2+1;
3809 lastBrush
= SelectObject(ps
.hdc
, GetStockObject(COLOR_SPLITBAR
));
3810 Rectangle(ps
.hdc
, rt
.left
, rt
.top
-1, rt
.right
, rt
.bottom
+1);
3811 SelectObject(ps
.hdc
, lastBrush
);
3812 EndPaint(hwnd
, &ps
);
3816 if (LOWORD(lparam
) == HTCLIENT
) {
3819 ScreenToClient(hwnd
, &pt
);
3821 if (pt
.x
>=child
->split_pos
-SPLIT_WIDTH
/2 && pt
.x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
3822 SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_SIZEWE
));
3828 case WM_LBUTTONDOWN
: {
3830 int x
= (short)LOWORD(lparam
);
3832 GetClientRect(hwnd
, &rt
);
3834 if (x
>=child
->split_pos
-SPLIT_WIDTH
/2 && x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
3835 last_split
= child
->split_pos
;
3842 if (GetCapture() == hwnd
)
3847 if (wparam
== VK_ESCAPE
)
3848 if (GetCapture() == hwnd
) {
3850 child
->split_pos
= last_split
;
3851 GetClientRect(hwnd
, &rt
);
3852 resize_tree(child
, rt
.right
, rt
.bottom
);
3855 SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_ARROW
));
3860 if (GetCapture() == hwnd
) {
3862 int x
= (short)LOWORD(lparam
);
3864 GetClientRect(hwnd
, &rt
);
3866 if (x
>=0 && x
<rt
.right
) {
3867 child
->split_pos
= x
;
3868 resize_tree(child
, rt
.right
, rt
.bottom
);
3869 rt
.left
= x
-SPLIT_WIDTH
/2;
3870 rt
.right
= x
+SPLIT_WIDTH
/2+1;
3871 InvalidateRect(hwnd
, &rt
, FALSE
);
3872 UpdateWindow(child
->left
.hwnd
);
3874 UpdateWindow(child
->right
.hwnd
);
3879 case WM_GETMINMAXINFO
:
3880 DefMDIChildProcW(hwnd
, nmsg
, wparam
, lparam
);
3882 {LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
3884 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
3885 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
3889 if (SetCurrentDirectoryW(child
->path
))
3891 SetFocus(child
->focus_pane
? child
->right
.hwnd
: child
->left
.hwnd
);
3894 case WM_DISPATCH_COMMAND
: {
3895 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
3897 switch(LOWORD(wparam
)) {
3898 case ID_WINDOW_NEW
: {
3899 ChildWnd
* new_child
= alloc_child_window(child
->path
, NULL
, hwnd
);
3901 if (!create_child_window(new_child
))
3902 HeapFree(GetProcessHeap(), 0, new_child
);
3908 refresh_child(child
);
3912 activate_entry(child
, pane
, hwnd
);
3915 case ID_FILE_MOVE
: {
3916 WCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
3918 if (prompt_target(pane
, source
, target
)) {
3919 SHFILEOPSTRUCTW shfo
= {hwnd
, FO_MOVE
, source
, target
};
3921 source
[lstrlenW(source
)+1] = '\0';
3922 target
[lstrlenW(target
)+1] = '\0';
3924 if (!SHFileOperationW(&shfo
))
3925 refresh_child(child
);
3929 case ID_FILE_COPY
: {
3930 WCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
3932 if (prompt_target(pane
, source
, target
)) {
3933 SHFILEOPSTRUCTW shfo
= {hwnd
, FO_COPY
, source
, target
};
3935 source
[lstrlenW(source
)+1] = '\0';
3936 target
[lstrlenW(target
)+1] = '\0';
3938 if (!SHFileOperationW(&shfo
))
3939 refresh_child(child
);
3943 case ID_FILE_DELETE
: {
3944 WCHAR path
[BUFFER_LEN
];
3945 SHFILEOPSTRUCTW shfo
= {hwnd
, FO_DELETE
, path
, NULL
, FOF_ALLOWUNDO
};
3947 get_path(pane
->cur
, path
);
3949 path
[lstrlenW(path
)+1] = '\0';
3951 if (!SHFileOperationW(&shfo
))
3952 refresh_child(child
);
3955 case ID_VIEW_SORT_NAME
:
3956 set_sort_order(child
, SORT_NAME
);
3959 case ID_VIEW_SORT_TYPE
:
3960 set_sort_order(child
, SORT_EXT
);
3963 case ID_VIEW_SORT_SIZE
:
3964 set_sort_order(child
, SORT_SIZE
);
3967 case ID_VIEW_SORT_DATE
:
3968 set_sort_order(child
, SORT_DATE
);
3971 case ID_VIEW_FILTER
: {
3972 struct FilterDialog dlg
;
3974 memset(&dlg
, 0, sizeof(struct FilterDialog
));
3975 lstrcpyW(dlg
.pattern
, child
->filter_pattern
);
3976 dlg
.flags
= child
->filter_flags
;
3978 if (DialogBoxParamW(Globals
.hInstance
, MAKEINTRESOURCEW(IDD_DIALOG_VIEW_TYPE
), hwnd
, FilterDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
3979 lstrcpyW(child
->filter_pattern
, dlg
.pattern
);
3980 child
->filter_flags
= dlg
.flags
;
3981 refresh_right_pane(child
);
3985 case ID_VIEW_SPLIT
: {
3986 last_split
= child
->split_pos
;
3990 case ID_EDIT_PROPERTIES
:
3991 show_properties_dlg(pane
->cur
, child
->hwnd
);
3995 return pane_command(pane
, LOWORD(wparam
));
4001 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4003 switch(HIWORD(wparam
)) {
4004 case LBN_SELCHANGE
: {
4005 int idx
= SendMessageW(pane
->hwnd
, LB_GETCURSEL
, 0, 0);
4006 Entry
* entry
= (Entry
*)SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, idx
, 0);
4008 if (pane
== &child
->left
)
4009 set_curdir(child
, entry
, idx
, hwnd
);
4015 activate_entry(child
, pane
, hwnd
);
4021 NMHDR
* pnmh
= (NMHDR
*) lparam
;
4022 return pane_notify(pnmh
->idFrom
==IDW_HEADER_LEFT
? &child
->left
: &child
->right
, pnmh
);}
4024 case WM_CONTEXTMENU
: {
4029 /* first select the current item in the listbox */
4030 HWND hpanel
= (HWND
) wparam
;
4031 pt_clnt
.x
= pt
.x
= (short)LOWORD(lparam
);
4032 pt_clnt
.y
= pt
.y
= (short)HIWORD(lparam
);
4033 ScreenToClient(hpanel
, &pt_clnt
);
4034 SendMessageW(hpanel
, WM_LBUTTONDOWN
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4035 SendMessageW(hpanel
, WM_LBUTTONUP
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4037 /* now create the popup menu using shell namespace and IContextMenu */
4038 pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4039 idx
= SendMessageW(pane
->hwnd
, LB_GETCURSEL
, 0, 0);
4042 Entry
* entry
= (Entry
*)SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, idx
, 0);
4044 LPITEMIDLIST pidl_abs
= get_to_absolute_pidl(entry
, hwnd
);
4047 IShellFolder
* parentFolder
;
4048 LPCITEMIDLIST pidlLast
;
4050 /* get and use the parent folder to display correct context menu in all cases */
4051 if (SUCCEEDED(SHBindToParent(pidl_abs
, &IID_IShellFolder
, (LPVOID
*)&parentFolder
, &pidlLast
))) {
4052 if (ShellFolderContextMenu(parentFolder
, hwnd
, 1, &pidlLast
, pt
.x
, pt
.y
) == S_OK
)
4053 refresh_child(child
);
4055 IShellFolder_Release(parentFolder
);
4058 IMalloc_Free(Globals
.iMalloc
, pidl_abs
);
4063 case WM_MEASUREITEM
:
4065 if (!wparam
) /* Is the message menu-related? */
4066 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4071 case WM_INITMENUPOPUP
:
4072 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4075 update_view_menu(child
);
4078 case WM_MENUCHAR
: /* only supported by IContextMenu3 */
4080 LRESULT lResult
= 0;
4082 IContextMenu3_HandleMenuMsg2(s_pctxmenu3
, nmsg
, wparam
, lparam
, &lResult
);
4090 if (wparam
!= SIZE_MINIMIZED
)
4091 resize_tree(child
, LOWORD(lparam
), HIWORD(lparam
));
4095 return DefMDIChildProcW(hwnd
, nmsg
, wparam
, lparam
);
4102 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4104 ChildWnd
* child
= (ChildWnd
*)GetWindowLongPtrW(GetParent(hwnd
), GWLP_USERDATA
);
4105 Pane
* pane
= (Pane
*)GetWindowLongPtrW(hwnd
, GWLP_USERDATA
);
4114 child
->focus_pane
= pane
==&child
->right
? 1: 0;
4115 SendMessageW(hwnd
, LB_SETSEL
, TRUE
, 1);
4116 /*TODO: check menu items */
4120 if (wparam
== VK_TAB
) {
4121 /*TODO: SetFocus(Globals.hdrivebar) */
4122 SetFocus(child
->focus_pane
? child
->left
.hwnd
: child
->right
.hwnd
);
4126 return CallWindowProcW(g_orgTreeWndProc
, hwnd
, nmsg
, wparam
, lparam
);
4130 static void InitInstance(HINSTANCE hinstance
)
4132 static const WCHAR sFont
[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4134 WNDCLASSEXW wcFrame
;
4138 INITCOMMONCONTROLSEX icc
= {
4139 sizeof(INITCOMMONCONTROLSEX
),
4145 setlocale(LC_COLLATE
, ""); /* set collating rules to local settings for compareName */
4147 InitCommonControlsEx(&icc
);
4150 /* register frame window class */
4152 wcFrame
.cbSize
= sizeof(WNDCLASSEXW
);
4154 wcFrame
.lpfnWndProc
= FrameWndProc
;
4155 wcFrame
.cbClsExtra
= 0;
4156 wcFrame
.cbWndExtra
= 0;
4157 wcFrame
.hInstance
= hinstance
;
4158 wcFrame
.hIcon
= LoadIconW(hinstance
, MAKEINTRESOURCEW(IDI_WINEFILE
));
4159 wcFrame
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
4160 wcFrame
.hbrBackground
= 0;
4161 wcFrame
.lpszMenuName
= 0;
4162 wcFrame
.lpszClassName
= sWINEFILEFRAME
;
4163 wcFrame
.hIconSm
= LoadImageW(hinstance
, MAKEINTRESOURCEW(IDI_WINEFILE
), IMAGE_ICON
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
4165 Globals
.hframeClass
= RegisterClassExW(&wcFrame
);
4168 /* register tree windows class */
4170 wcChild
.style
= CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
;
4171 wcChild
.lpfnWndProc
= ChildWndProc
;
4172 wcChild
.cbClsExtra
= 0;
4173 wcChild
.cbWndExtra
= 0;
4174 wcChild
.hInstance
= hinstance
;
4175 wcChild
.hIcon
= LoadIconW(hinstance
, MAKEINTRESOURCEW(IDI_WINEFILE
));
4176 wcChild
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
4177 wcChild
.hbrBackground
= 0;
4178 wcChild
.lpszMenuName
= 0;
4179 wcChild
.lpszClassName
= sWINEFILETREE
;
4181 RegisterClassW(&wcChild
);
4184 Globals
.haccel
= LoadAcceleratorsW(hinstance
, MAKEINTRESOURCEW(IDA_WINEFILE
));
4186 Globals
.hfont
= CreateFontW(-MulDiv(8,GetDeviceCaps(hdc
,LOGPIXELSY
),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont
);
4190 Globals
.hInstance
= hinstance
;
4193 CoGetMalloc(MEMCTX_TASK
, &Globals
.iMalloc
);
4194 SHGetDesktopFolder(&Globals
.iDesktop
);
4195 Globals
.cfStrFName
= RegisterClipboardFormatW(CFSTR_FILENAMEW
);
4197 /* load column strings */
4200 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_NAME
);
4201 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_SIZE
);
4202 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_CDATE
);
4203 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_ADATE
);
4204 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_MDATE
);
4205 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_IDX
);
4206 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_LINKS
);
4207 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_ATTR
);
4208 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_SEC
);
4212 static BOOL
show_frame(HWND hwndParent
, int cmdshow
, LPCWSTR path
)
4214 static const WCHAR sMDICLIENT
[] = {'M','D','I','C','L','I','E','N','T','\0'};
4216 WCHAR buffer
[MAX_PATH
], b1
[BUFFER_LEN
];
4218 HMENU hMenuFrame
, hMenuWindow
;
4221 CLIENTCREATESTRUCT ccs
;
4223 if (Globals
.hMainWnd
)
4226 opts
= load_registry_settings();
4227 hMenuFrame
= LoadMenuW(Globals
.hInstance
, MAKEINTRESOURCEW(IDM_WINEFILE
));
4228 hMenuWindow
= GetSubMenu(hMenuFrame
, GetMenuItemCount(hMenuFrame
)-2);
4230 Globals
.hMenuFrame
= hMenuFrame
;
4231 Globals
.hMenuView
= GetSubMenu(hMenuFrame
, 2);
4232 Globals
.hMenuOptions
= GetSubMenu(hMenuFrame
, 3);
4234 ccs
.hWindowMenu
= hMenuWindow
;
4235 ccs
.idFirstChild
= IDW_FIRST_CHILD
;
4238 /* create main window */
4239 Globals
.hMainWnd
= CreateWindowExW(0, MAKEINTRESOURCEW(Globals
.hframeClass
), RS(b1
,IDS_WINEFILE
), WS_OVERLAPPEDWINDOW
,
4240 opts
.start_x
, opts
.start_y
, opts
.width
, opts
.height
,
4241 hwndParent
, Globals
.hMenuFrame
, Globals
.hInstance
, 0/*lpParam*/);
4244 Globals
.hmdiclient
= CreateWindowExW(0, sMDICLIENT
, NULL
,
4245 WS_CHILD
|WS_CLIPCHILDREN
|WS_VSCROLL
|WS_HSCROLL
|WS_VISIBLE
|WS_BORDER
,
4247 Globals
.hMainWnd
, 0, Globals
.hInstance
, &ccs
);
4249 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_DRIVE_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4250 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_SAVESETTINGS
, MF_BYCOMMAND
);
4255 TBBUTTON toolbarBtns
[] = {
4256 {0, 0, 0, BTNS_SEP
, {0, 0}, 0, 0},
4257 {0, ID_WINDOW_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4258 {1, ID_WINDOW_CASCADE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4259 {2, ID_WINDOW_TILE_HORZ
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4260 {3, ID_WINDOW_TILE_VERT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4263 Globals
.htoolbar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
,
4264 IDW_TOOLBAR
, 2, Globals
.hInstance
, IDB_TOOLBAR
, toolbarBtns
,
4265 sizeof(toolbarBtns
)/sizeof(TBBUTTON
), 16, 15, 16, 15, sizeof(TBBUTTON
));
4266 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_TOOL_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4269 Globals
.hstatusbar
= CreateStatusWindowW(WS_CHILD
|WS_VISIBLE
, 0, Globals
.hMainWnd
, IDW_STATUSBAR
);
4270 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
4272 /*TODO: read paths from registry */
4274 if (!path
|| !*path
) {
4275 GetCurrentDirectoryW(MAX_PATH
, buffer
);
4279 ShowWindow(Globals
.hMainWnd
, cmdshow
);
4282 /* Shell Namespace as default: */
4283 child
= alloc_child_window(path
, get_path_pidl(path
,Globals
.hMainWnd
), Globals
.hMainWnd
);
4285 child
= alloc_child_window(path
, NULL
, Globals
.hMainWnd
);
4288 child
->pos
.showCmd
= SW_SHOWMAXIMIZED
;
4289 child
->pos
.rcNormalPosition
.left
= 0;
4290 child
->pos
.rcNormalPosition
.top
= 0;
4291 child
->pos
.rcNormalPosition
.right
= 320;
4292 child
->pos
.rcNormalPosition
.bottom
= 280;
4294 if (!create_child_window(child
)) {
4295 HeapFree(GetProcessHeap(), 0, child
);
4299 SetWindowPlacement(child
->hwnd
, &child
->pos
);
4301 Globals
.himl
= ImageList_LoadImageW(Globals
.hInstance
, MAKEINTRESOURCEW(IDB_IMAGES
), 16, 0, RGB(0,255,0), IMAGE_BITMAP
, 0);
4303 Globals
.prescan_node
= FALSE
;
4305 UpdateWindow(Globals
.hMainWnd
);
4307 if (child
->hwnd
&& path
&& path
[0])
4310 WCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
4311 WCHAR fullname
[_MAX_FNAME
+_MAX_EXT
+1];
4313 memset(name
,0,sizeof(name
));
4314 memset(name
,0,sizeof(ext
));
4315 _wsplitpath(path
, drv
, dir
, name
, ext
);
4318 count
= SendMessageW(child
->right
.hwnd
, LB_GETCOUNT
, 0, 0);
4319 lstrcpyW(fullname
,name
);
4320 lstrcatW(fullname
,ext
);
4322 for (index
= 0; index
< count
; index
++)
4324 Entry
* entry
= (Entry
*)SendMessageW(child
->right
.hwnd
, LB_GETITEMDATA
, index
, 0);
4325 if (lstrcmpW(entry
->data
.cFileName
,fullname
)==0 ||
4326 lstrcmpW(entry
->data
.cAlternateFileName
,fullname
)==0)
4328 SendMessageW(child
->right
.hwnd
, LB_SETCURSEL
, index
, 0);
4329 SetFocus(child
->right
.hwnd
);
4338 static void ExitInstance(void)
4340 IShellFolder_Release(Globals
.iDesktop
);
4341 IMalloc_Release(Globals
.iMalloc
);
4344 DeleteObject(Globals
.hfont
);
4345 ImageList_Destroy(Globals
.himl
);
4348 int APIENTRY
wWinMain(HINSTANCE hinstance
, HINSTANCE previnstance
, LPWSTR cmdline
, int cmdshow
)
4352 InitInstance(hinstance
);
4354 if( !show_frame(0, cmdshow
, cmdline
) )
4360 while(GetMessageW(&msg
, 0, 0, 0)) {
4361 if (Globals
.hmdiclient
&& TranslateMDISysAccel(Globals
.hmdiclient
, &msg
))
4364 if (Globals
.hMainWnd
&& TranslateAcceleratorW(Globals
.hMainWnd
, Globals
.haccel
, &msg
))
4367 TranslateMessage(&msg
);
4368 DispatchMessageW(&msg
);