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 positions
[COLUMNS
+1];
133 int focus_pane
; /* 0: left 1: right */
136 BOOL header_wdths_ok
;
138 WCHAR path
[MAX_PATH
];
139 WCHAR filter_pattern
[MAX_PATH
];
143 SORT_ORDER sortOrder
;
148 static void read_directory(Entry
* dir
, LPCWSTR path
, SORT_ORDER sortOrder
, HWND hwnd
);
149 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
);
150 static void refresh_child(ChildWnd
* child
);
151 static void refresh_drives(void);
152 static void get_path(Entry
* dir
, PWSTR path
);
153 static void format_date(const FILETIME
* ft
, WCHAR
* buffer
, int visible_cols
);
155 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
156 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
157 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
161 WINEFILE_GLOBALS Globals
;
163 static int last_split
;
165 /* some common string constants */
166 static const WCHAR sEmpty
[] = {'\0'};
167 static const WCHAR sSpace
[] = {' ', '\0'};
168 static const WCHAR sNumFmt
[] = {'%','d','\0'};
169 static const WCHAR sQMarks
[] = {'?','?','?','\0'};
171 /* window class names */
172 static const WCHAR sWINEFILEFRAME
[] = {'W','F','S','_','F','r','a','m','e','\0'};
173 static const WCHAR sWINEFILETREE
[] = {'W','F','S','_','T','r','e','e','\0'};
175 static void format_longlong(LPWSTR ret
, ULONGLONG val
)
177 WCHAR buffer
[65], *p
= &buffer
[64];
181 *(--p
) = '0' + val
% 10;
188 /* load resource string */
189 static LPWSTR
load_string(LPWSTR buffer
, DWORD size
, UINT id
)
191 LoadStringW(Globals
.hInstance
, id
, buffer
, size
);
195 #define RS(b, i) load_string(b, sizeof(b)/sizeof(b[0]), i)
198 /* display error message for the specified WIN32 error code */
199 static void display_error(HWND hwnd
, DWORD error
)
201 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
204 if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_FROM_SYSTEM
,
205 0, error
, MAKELANGID(LANG_NEUTRAL
,SUBLANG_DEFAULT
), (PWSTR
)&msg
, 0, NULL
))
206 MessageBoxW(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
208 MessageBoxW(hwnd
, RS(b1
,IDS_ERROR
), RS(b2
,IDS_WINEFILE
), MB_OK
);
214 /* display network error message using WNetGetLastErrorW() */
215 static void display_network_error(HWND hwnd
)
217 WCHAR msg
[BUFFER_LEN
], provider
[BUFFER_LEN
], b2
[BUFFER_LEN
];
220 if (WNetGetLastErrorW(&error
, msg
, BUFFER_LEN
, provider
, BUFFER_LEN
) == NO_ERROR
)
221 MessageBoxW(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
224 static inline BOOL
get_check(HWND hwnd
, INT id
)
226 return BST_CHECKED
&SendMessageW(GetDlgItem(hwnd
, id
), BM_GETSTATE
, 0, 0);
229 static inline INT
set_check(HWND hwnd
, INT id
, BOOL on
)
231 return SendMessageW(GetDlgItem(hwnd
, id
), BM_SETCHECK
, on
?BST_CHECKED
:BST_UNCHECKED
, 0);
234 static inline void choose_font(HWND hwnd
)
236 WCHAR dlg_name
[BUFFER_LEN
], dlg_info
[BUFFER_LEN
];
240 HDC hdc
= GetDC(hwnd
);
242 GetObjectW(Globals
.hfont
, sizeof(LOGFONTW
), &lFont
);
244 chFont
.lStructSize
= sizeof(CHOOSEFONTW
);
245 chFont
.hwndOwner
= hwnd
;
247 chFont
.lpLogFont
= &lFont
;
248 chFont
.Flags
= CF_SCREENFONTS
| CF_FORCEFONTEXIST
| CF_LIMITSIZE
| CF_NOSCRIPTSEL
| CF_INITTOLOGFONTSTRUCT
| CF_NOVERTFONTS
;
249 chFont
.rgbColors
= RGB(0,0,0);
250 chFont
.lCustData
= 0;
251 chFont
.lpfnHook
= NULL
;
252 chFont
.lpTemplateName
= NULL
;
253 chFont
.hInstance
= Globals
.hInstance
;
254 chFont
.lpszStyle
= NULL
;
255 chFont
.nFontType
= SIMULATED_FONTTYPE
;
257 chFont
.nSizeMax
= 24;
259 if (ChooseFontW(&chFont
)) {
263 DeleteObject(Globals
.hfont
);
264 Globals
.hfont
= CreateFontIndirectW(&lFont
);
265 hFontOld
= SelectObject(hdc
, Globals
.hfont
);
266 GetTextExtentPoint32W(hdc
, sSpace
, 1, &Globals
.spaceSize
);
268 /* change font in all open child windows */
269 for(childWnd
=GetWindow(Globals
.hmdiclient
,GW_CHILD
); childWnd
; childWnd
=GetNextWindow(childWnd
,GW_HWNDNEXT
)) {
270 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtrW(childWnd
, GWLP_USERDATA
);
271 SendMessageW(child
->left
.hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, TRUE
);
272 SendMessageW(child
->right
.hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, TRUE
);
273 SendMessageW(child
->left
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
274 SendMessageW(child
->right
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
275 InvalidateRect(child
->left
.hwnd
, NULL
, TRUE
);
276 InvalidateRect(child
->right
.hwnd
, NULL
, TRUE
);
279 SelectObject(hdc
, hFontOld
);
281 else if (CommDlgExtendedError()) {
282 LoadStringW(Globals
.hInstance
, IDS_FONT_SEL_DLG_NAME
, dlg_name
, BUFFER_LEN
);
283 LoadStringW(Globals
.hInstance
, IDS_FONT_SEL_ERROR
, dlg_info
, BUFFER_LEN
);
284 MessageBoxW(hwnd
, dlg_info
, dlg_name
, MB_OK
);
287 ReleaseDC(hwnd
, hdc
);
291 /* allocate and initialise a directory entry */
292 static Entry
* alloc_entry(void)
294 Entry
* entry
= HeapAlloc(GetProcessHeap(), 0, sizeof(Entry
));
297 entry
->folder
= NULL
;
303 /* free a directory entry */
304 static void free_entry(Entry
* entry
)
306 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
307 DestroyIcon(entry
->hicon
);
309 if (entry
->folder
&& entry
->folder
!=Globals
.iDesktop
)
310 IShellFolder_Release(entry
->folder
);
313 IMalloc_Free(Globals
.iMalloc
, entry
->pidl
);
315 HeapFree(GetProcessHeap(), 0, entry
);
318 /* recursively free all child entries */
319 static void free_entries(Entry
* dir
)
321 Entry
*entry
, *next
=dir
->down
;
337 static void read_directory_win(Entry
* dir
, LPCWSTR path
)
339 Entry
* first_entry
= NULL
;
343 int level
= dir
->level
+ 1;
344 WIN32_FIND_DATAW w32fd
;
348 WCHAR buffer
[MAX_PATH
], *p
;
349 for(p
=buffer
; *path
; )
356 hFind
= FindFirstFileW(buffer
, &w32fd
);
358 if (hFind
!= INVALID_HANDLE_VALUE
) {
360 entry
= alloc_entry();
368 memcpy(&entry
->data
, &w32fd
, sizeof(WIN32_FIND_DATAW
));
371 entry
->expanded
= FALSE
;
372 entry
->scanned
= FALSE
;
373 entry
->level
= level
;
374 entry
->etype
= ET_WINDOWS
;
375 entry
->bhfi_valid
= FALSE
;
377 lstrcpyW(p
, entry
->data
.cFileName
);
379 hFile
= CreateFileW(buffer
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
380 0, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0);
382 if (hFile
!= INVALID_HANDLE_VALUE
) {
383 if (GetFileInformationByHandle(hFile
, &entry
->bhfi
))
384 entry
->bhfi_valid
= TRUE
;
390 } while(FindNextFileW(hFind
, &w32fd
));
398 dir
->down
= first_entry
;
403 static Entry
* find_entry_win(Entry
* dir
, LPCWSTR name
)
407 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
409 LPCWSTR q
= entry
->data
.cFileName
;
412 if (!*p
|| *p
== '\\' || *p
== '/')
414 } while(tolower(*p
++) == tolower(*q
++));
417 q
= entry
->data
.cAlternateFileName
;
420 if (!*p
|| *p
== '\\' || *p
== '/')
422 } while(tolower(*p
++) == tolower(*q
++));
429 static Entry
* read_tree_win(Root
* root
, LPCWSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
431 WCHAR buffer
[MAX_PATH
];
432 Entry
* entry
= &root
->entry
;
436 HCURSOR old_cursor
= SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_WAIT
));
438 entry
->etype
= ET_WINDOWS
;
440 while(*s
&& *s
!= '\\' && *s
!= '/')
443 while(*s
== '\\' || *s
== '/')
449 read_directory(entry
, buffer
, sortOrder
, hwnd
);
452 entry
->expanded
= TRUE
;
457 entry
= find_entry_win(entry
, s
);
460 SetCursor(old_cursor
);
468 static BOOL
time_to_filetime(time_t t
, FILETIME
* ftime
)
470 struct tm
* tm
= gmtime(&t
);
476 stime
.wYear
= tm
->tm_year
+1900;
477 stime
.wMonth
= tm
->tm_mon
+1;
478 /* stime.wDayOfWeek */
479 stime
.wDay
= tm
->tm_mday
;
480 stime
.wHour
= tm
->tm_hour
;
481 stime
.wMinute
= tm
->tm_min
;
482 stime
.wSecond
= tm
->tm_sec
;
483 stime
.wMilliseconds
= 0;
485 return SystemTimeToFileTime(&stime
, ftime
);
488 static void read_directory_unix(Entry
* dir
, LPCWSTR path
)
490 Entry
* first_entry
= NULL
;
495 int level
= dir
->level
+ 1;
496 char cpath
[MAX_PATH
];
498 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, cpath
, MAX_PATH
, NULL
, NULL
);
499 pdir
= opendir(cpath
);
504 char buffer
[MAX_PATH
], *p
;
507 for(p
=buffer
,s
=cpath
; *s
; )
510 if (p
==buffer
|| p
[-1]!='/')
513 while((ent
=readdir(pdir
))) {
514 entry
= alloc_entry();
522 entry
->etype
= ET_UNIX
;
524 strcpy(p
, ent
->d_name
);
525 MultiByteToWideChar(CP_UNIXCP
, 0, p
, -1, entry
->data
.cFileName
, MAX_PATH
);
527 if (!stat(buffer
, &st
)) {
528 entry
->data
.dwFileAttributes
= p
[0]=='.'? FILE_ATTRIBUTE_HIDDEN
: 0;
530 if (S_ISDIR(st
.st_mode
))
531 entry
->data
.dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
533 entry
->data
.nFileSizeLow
= st
.st_size
& 0xFFFFFFFF;
534 entry
->data
.nFileSizeHigh
= st
.st_size
>> 32;
536 memset(&entry
->data
.ftCreationTime
, 0, sizeof(FILETIME
));
537 time_to_filetime(st
.st_atime
, &entry
->data
.ftLastAccessTime
);
538 time_to_filetime(st
.st_mtime
, &entry
->data
.ftLastWriteTime
);
540 entry
->bhfi
.nFileIndexLow
= ent
->d_ino
;
541 entry
->bhfi
.nFileIndexHigh
= 0;
543 entry
->bhfi
.nNumberOfLinks
= st
.st_nlink
;
545 entry
->bhfi_valid
= TRUE
;
547 entry
->data
.nFileSizeLow
= 0;
548 entry
->data
.nFileSizeHigh
= 0;
549 entry
->bhfi_valid
= FALSE
;
554 entry
->expanded
= FALSE
;
555 entry
->scanned
= FALSE
;
556 entry
->level
= level
;
567 dir
->down
= first_entry
;
571 static Entry
* find_entry_unix(Entry
* dir
, LPCWSTR name
)
575 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
577 LPCWSTR q
= entry
->data
.cFileName
;
580 if (!*p
|| *p
== '/')
582 } while(*p
++ == *q
++);
588 static Entry
* read_tree_unix(Root
* root
, LPCWSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
590 WCHAR buffer
[MAX_PATH
];
591 Entry
* entry
= &root
->entry
;
595 HCURSOR old_cursor
= SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_WAIT
));
597 entry
->etype
= ET_UNIX
;
600 while(*s
&& *s
!= '/')
609 read_directory(entry
, buffer
, sortOrder
, hwnd
);
612 entry
->expanded
= TRUE
;
617 entry
= find_entry_unix(entry
, s
);
620 SetCursor(old_cursor
);
625 #endif /* __WINE__ */
627 static void free_strret(STRRET
* str
)
629 if (str
->uType
== STRRET_WSTR
)
630 IMalloc_Free(Globals
.iMalloc
, str
->UNION_MEMBER(pOleStr
));
633 static LPWSTR
wcscpyn(LPWSTR dest
, LPCWSTR source
, size_t count
)
638 for(s
=source
; count
&&(*d
++=*s
++); )
644 static void get_strretW(STRRET
* str
, const SHITEMID
* shiid
, LPWSTR buffer
, int len
)
648 wcscpyn(buffer
, str
->UNION_MEMBER(pOleStr
), len
);
652 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), -1, buffer
, len
);
656 MultiByteToWideChar(CP_ACP
, 0, str
->UNION_MEMBER(cStr
), -1, buffer
, len
);
661 static HRESULT
name_from_pidl(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPWSTR buffer
, int len
, SHGDNF flags
)
665 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, flags
, &str
);
668 get_strretW(&str
, &pidl
->mkid
, buffer
, len
);
677 static HRESULT
path_from_pidlW(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPWSTR buffer
, int len
)
681 /* SHGDN_FORPARSING: get full path of id list */
682 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, SHGDN_FORPARSING
, &str
);
685 get_strretW(&str
, &pidl
->mkid
, buffer
, len
);
694 /* create an item id list from a file system path */
696 static LPITEMIDLIST
get_path_pidl(LPWSTR path
, HWND hwnd
)
701 LPWSTR buffer
= path
;
703 hr
= IShellFolder_ParseDisplayName(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
711 /* convert an item id list from relative to absolute (=relative to the desktop) format */
713 static LPITEMIDLIST
get_to_absolute_pidl(Entry
* entry
, HWND hwnd
)
715 if (entry
->up
&& entry
->up
->etype
==ET_SHELL
) {
716 LPITEMIDLIST idl
= NULL
;
719 idl
= ILCombine(ILClone(entry
->pidl
), idl
);
724 } else if (entry
->etype
== ET_WINDOWS
) {
725 WCHAR path
[MAX_PATH
];
727 get_path(entry
, path
);
729 return get_path_pidl(path
, hwnd
);
730 } else if (entry
->pidl
)
731 return ILClone(entry
->pidl
);
737 static HICON
extract_icon(IShellFolder
* folder
, LPCITEMIDLIST pidl
)
739 IExtractIconW
* pExtract
;
741 if (SUCCEEDED(IShellFolder_GetUIObjectOf(folder
, 0, 1, (LPCITEMIDLIST
*)&pidl
, &IID_IExtractIconW
, 0, (LPVOID
*)&pExtract
))) {
742 WCHAR path
[_MAX_PATH
];
747 if (SUCCEEDED(IExtractIconW_GetIconLocation(pExtract
, GIL_FORSHELL
, path
, _MAX_PATH
, &idx
, &flags
))) {
748 if (!(flags
& GIL_NOTFILENAME
)) {
750 idx
= 0; /* special case for some control panel applications */
752 if ((int)ExtractIconExW(path
, idx
, 0, &hicon
, 1) > 0)
753 flags
&= ~GIL_DONTCACHE
;
755 HICON hIconLarge
= 0;
757 HRESULT hr
= IExtractIconW_Extract(pExtract
, path
, idx
, &hIconLarge
, &hicon
, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON
)));
760 DestroyIcon(hIconLarge
);
771 static Entry
* find_entry_shell(Entry
* dir
, LPCITEMIDLIST pidl
)
775 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
776 if (entry
->pidl
->mkid
.cb
== pidl
->mkid
.cb
&&
777 !memcmp(entry
->pidl
, pidl
, entry
->pidl
->mkid
.cb
))
784 static Entry
* read_tree_shell(Root
* root
, LPITEMIDLIST pidl
, SORT_ORDER sortOrder
, HWND hwnd
)
786 Entry
* entry
= &root
->entry
;
788 LPITEMIDLIST next_pidl
= pidl
;
789 IShellFolder
* folder
;
790 IShellFolder
* child
= NULL
;
793 HCURSOR old_cursor
= SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_WAIT
));
795 entry
->etype
= ET_SHELL
;
796 folder
= Globals
.iDesktop
;
799 entry
->pidl
= next_pidl
;
800 entry
->folder
= folder
;
805 /* copy first element of item idlist */
806 next_pidl
= IMalloc_Alloc(Globals
.iMalloc
, pidl
->mkid
.cb
+sizeof(USHORT
));
807 memcpy(next_pidl
, pidl
, pidl
->mkid
.cb
);
808 ((LPITEMIDLIST
)((LPBYTE
)next_pidl
+pidl
->mkid
.cb
))->mkid
.cb
= 0;
810 hr
= IShellFolder_BindToObject(folder
, next_pidl
, 0, &IID_IShellFolder
, (void**)&child
);
814 read_directory(entry
, NULL
, sortOrder
, hwnd
);
817 entry
->expanded
= TRUE
;
819 next
= find_entry_shell(entry
, next_pidl
);
826 /* go to next element */
827 pidl
= (LPITEMIDLIST
) ((LPBYTE
)pidl
+pidl
->mkid
.cb
);
830 SetCursor(old_cursor
);
836 static void fill_w32fdata_shell(IShellFolder
* folder
, LPCITEMIDLIST pidl
, SFGAOF attribs
, WIN32_FIND_DATAW
* w32fdata
)
838 if (!(attribs
& SFGAO_FILESYSTEM
) ||
839 FAILED(SHGetDataFromIDListW(folder
, pidl
, SHGDFIL_FINDDATA
, w32fdata
, sizeof(WIN32_FIND_DATAW
)))) {
840 WIN32_FILE_ATTRIBUTE_DATA fad
;
841 IDataObject
* pDataObj
;
843 STGMEDIUM medium
= {0, {0}, 0};
844 FORMATETC fmt
= {Globals
.cfStrFName
, 0, DVASPECT_CONTENT
, -1, TYMED_HGLOBAL
};
846 HRESULT hr
= IShellFolder_GetUIObjectOf(folder
, 0, 1, &pidl
, &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
849 hr
= IDataObject_GetData(pDataObj
, &fmt
, &medium
);
851 IDataObject_Release(pDataObj
);
854 LPCWSTR path
= GlobalLock(medium
.UNION_MEMBER(hGlobal
));
855 UINT sem_org
= SetErrorMode(SEM_FAILCRITICALERRORS
);
857 if (GetFileAttributesExW(path
, GetFileExInfoStandard
, &fad
)) {
858 w32fdata
->dwFileAttributes
= fad
.dwFileAttributes
;
859 w32fdata
->ftCreationTime
= fad
.ftCreationTime
;
860 w32fdata
->ftLastAccessTime
= fad
.ftLastAccessTime
;
861 w32fdata
->ftLastWriteTime
= fad
.ftLastWriteTime
;
863 if (!(fad
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)) {
864 w32fdata
->nFileSizeLow
= fad
.nFileSizeLow
;
865 w32fdata
->nFileSizeHigh
= fad
.nFileSizeHigh
;
869 SetErrorMode(sem_org
);
871 GlobalUnlock(medium
.UNION_MEMBER(hGlobal
));
872 GlobalFree(medium
.UNION_MEMBER(hGlobal
));
877 if (attribs
& (SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
))
878 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
880 if (attribs
& SFGAO_READONLY
)
881 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_READONLY
;
883 if (attribs
& SFGAO_COMPRESSED
)
884 w32fdata
->dwFileAttributes
|= FILE_ATTRIBUTE_COMPRESSED
;
888 static void read_directory_shell(Entry
* dir
, HWND hwnd
)
890 IShellFolder
* folder
= dir
->folder
;
891 int level
= dir
->level
+ 1;
897 Entry
* first_entry
= NULL
;
904 hr
= IShellFolder_EnumObjects(folder
, hwnd
, SHCONTF_FOLDERS
|SHCONTF_NONFOLDERS
|SHCONTF_INCLUDEHIDDEN
|SHCONTF_SHAREABLE
|SHCONTF_STORAGE
, &idlist
);
908 #define FETCH_ITEM_COUNT 32
909 LPITEMIDLIST pidls
[FETCH_ITEM_COUNT
];
914 memset(pidls
, 0, sizeof(pidls
));
916 hr
= IEnumIDList_Next(idlist
, FETCH_ITEM_COUNT
, pidls
, &cnt
);
923 for(n
=0; n
<cnt
; ++n
) {
924 entry
= alloc_entry();
932 memset(&entry
->data
, 0, sizeof(WIN32_FIND_DATAW
));
933 entry
->bhfi_valid
= FALSE
;
935 attribs
= ~SFGAO_FILESYSTEM
; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
937 hr
= IShellFolder_GetAttributesOf(folder
, 1, (LPCITEMIDLIST
*)&pidls
[n
], &attribs
);
940 if (attribs
!= (SFGAOF
)~SFGAO_FILESYSTEM
) {
941 fill_w32fdata_shell(folder
, pidls
[n
], attribs
, &entry
->data
);
943 entry
->bhfi_valid
= TRUE
;
949 entry
->pidl
= pidls
[n
];
951 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
952 hr
= IShellFolder_BindToObject(folder
, pidls
[n
], 0, &IID_IShellFolder
, (void**)&child
);
955 entry
->folder
= child
;
957 entry
->folder
= NULL
;
960 entry
->folder
= NULL
;
962 if (!entry
->data
.cFileName
[0])
963 /*hr = */name_from_pidl(folder
, pidls
[n
], entry
->data
.cFileName
, MAX_PATH
, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
965 /* get display icons for files and virtual objects */
966 if (!(entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ||
967 !(attribs
& SFGAO_FILESYSTEM
)) {
968 entry
->hicon
= extract_icon(folder
, pidls
[n
]);
971 entry
->hicon
= (HICON
)-1; /* don't try again later */
976 entry
->expanded
= FALSE
;
977 entry
->scanned
= FALSE
;
978 entry
->level
= level
;
980 entry
->etype
= ET_SHELL
;
981 entry
->bhfi_valid
= FALSE
;
987 IEnumIDList_Release(idlist
);
993 dir
->down
= first_entry
;
997 /* sort order for different directory/file types */
1006 /* distinguish between ".", ".." and any other directory names */
1007 static int TypeOrderFromDirname(LPCWSTR name
)
1009 if (name
[0] == '.') {
1010 if (name
[1] == '\0')
1011 return TO_DOT
; /* "." */
1013 if (name
[1]=='.' && name
[2]=='\0')
1014 return TO_DOTDOT
; /* ".." */
1017 return TO_OTHER_DIR
; /* anything else */
1020 /* directories first... */
1021 static int compareType(const WIN32_FIND_DATAW
* fd1
, const WIN32_FIND_DATAW
* fd2
)
1023 int order1
= fd1
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1024 int order2
= fd2
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1026 /* Handle "." and ".." as special case and move them at the very first beginning. */
1027 if (order1
==TO_DIR
&& order2
==TO_DIR
) {
1028 order1
= TypeOrderFromDirname(fd1
->cFileName
);
1029 order2
= TypeOrderFromDirname(fd2
->cFileName
);
1032 return order2
==order1
? 0: order1
<order2
? -1: 1;
1036 static int compareName(const void* arg1
, const void* arg2
)
1038 const WIN32_FIND_DATAW
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1039 const WIN32_FIND_DATAW
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1041 int cmp
= compareType(fd1
, fd2
);
1045 return lstrcmpiW(fd1
->cFileName
, fd2
->cFileName
);
1048 static int compareExt(const void* arg1
, const void* arg2
)
1050 const WIN32_FIND_DATAW
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1051 const WIN32_FIND_DATAW
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1052 const WCHAR
*name1
, *name2
, *ext1
, *ext2
;
1054 int cmp
= compareType(fd1
, fd2
);
1058 name1
= fd1
->cFileName
;
1059 name2
= fd2
->cFileName
;
1061 ext1
= strrchrW(name1
, '.');
1062 ext2
= strrchrW(name2
, '.');
1074 cmp
= lstrcmpiW(ext1
, ext2
);
1078 return lstrcmpiW(name1
, name2
);
1081 static int compareSize(const void* arg1
, const void* arg2
)
1083 const WIN32_FIND_DATAW
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1084 const WIN32_FIND_DATAW
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1086 int cmp
= compareType(fd1
, fd2
);
1090 cmp
= fd2
->nFileSizeHigh
- fd1
->nFileSizeHigh
;
1097 cmp
= fd2
->nFileSizeLow
- fd1
->nFileSizeLow
;
1099 return cmp
<0? -1: cmp
>0? 1: 0;
1102 static int compareDate(const void* arg1
, const void* arg2
)
1104 const WIN32_FIND_DATAW
* fd1
= &(*(const Entry
* const*)arg1
)->data
;
1105 const WIN32_FIND_DATAW
* fd2
= &(*(const Entry
* const*)arg2
)->data
;
1107 int cmp
= compareType(fd1
, fd2
);
1111 return CompareFileTime(&fd2
->ftLastWriteTime
, &fd1
->ftLastWriteTime
);
1115 static int (*sortFunctions
[])(const void* arg1
, const void* arg2
) = {
1116 compareName
, /* SORT_NAME */
1117 compareExt
, /* SORT_EXT */
1118 compareSize
, /* SORT_SIZE */
1119 compareDate
/* SORT_DATE */
1123 static void SortDirectory(Entry
* dir
, SORT_ORDER sortOrder
)
1130 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1134 array
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(Entry
*));
1137 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1140 /* call qsort with the appropriate compare function */
1141 qsort(array
, len
, sizeof(array
[0]), sortFunctions
[sortOrder
]);
1143 dir
->down
= array
[0];
1145 for(p
=array
; --len
; p
++)
1150 HeapFree(GetProcessHeap(), 0, array
);
1155 static void read_directory(Entry
* dir
, LPCWSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
1157 WCHAR buffer
[MAX_PATH
];
1162 if (dir
->etype
== ET_SHELL
)
1164 read_directory_shell(dir
, hwnd
);
1166 if (Globals
.prescan_node
) {
1175 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1176 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1177 read_directory_shell(entry
, hwnd
);
1178 SortDirectory(entry
, sortOrder
);
1184 if (dir
->etype
== ET_UNIX
)
1186 read_directory_unix(dir
, path
);
1188 if (Globals
.prescan_node
) {
1197 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1198 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1199 lstrcpyW(d
, entry
->data
.cFileName
);
1200 read_directory_unix(entry
, buffer
);
1201 SortDirectory(entry
, sortOrder
);
1208 read_directory_win(dir
, path
);
1210 if (Globals
.prescan_node
) {
1219 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1220 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1221 lstrcpyW(d
, entry
->data
.cFileName
);
1222 read_directory_win(entry
, buffer
);
1223 SortDirectory(entry
, sortOrder
);
1228 SortDirectory(dir
, sortOrder
);
1232 static Entry
* read_tree(Root
* root
, LPCWSTR path
, LPITEMIDLIST pidl
, LPWSTR drv
, SORT_ORDER sortOrder
, HWND hwnd
)
1235 static const WCHAR sSlash
[] = {'/', '\0'};
1237 static const WCHAR sBackslash
[] = {'\\', '\0'};
1241 /* read shell namespace tree */
1242 root
->drive_type
= DRIVE_UNKNOWN
;
1245 load_string(root
->volname
, sizeof(root
->volname
)/sizeof(root
->volname
[0]), IDS_DESKTOP
);
1247 load_string(root
->fs
, sizeof(root
->fs
)/sizeof(root
->fs
[0]), IDS_SHELL
);
1249 return read_tree_shell(root
, pidl
, sortOrder
, hwnd
);
1255 /* read unix file system tree */
1256 root
->drive_type
= GetDriveTypeW(path
);
1258 lstrcatW(drv
, sSlash
);
1259 load_string(root
->volname
, sizeof(root
->volname
)/sizeof(root
->volname
[0]), IDS_ROOT_FS
);
1261 load_string(root
->fs
, sizeof(root
->fs
)/sizeof(root
->fs
[0]), IDS_UNIXFS
);
1263 lstrcpyW(root
->path
, sSlash
);
1265 return read_tree_unix(root
, path
, sortOrder
, hwnd
);
1269 /* read WIN32 file system tree */
1270 root
->drive_type
= GetDriveTypeW(path
);
1272 lstrcatW(drv
, sBackslash
);
1273 GetVolumeInformationW(drv
, root
->volname
, _MAX_FNAME
, 0, 0, &root
->fs_flags
, root
->fs
, _MAX_DIR
);
1275 lstrcpyW(root
->path
, drv
);
1277 return read_tree_win(root
, path
, sortOrder
, hwnd
);
1281 /* flags to filter different file types */
1283 TF_DIRECTORIES
= 0x01,
1285 TF_DOCUMENTS
= 0x04,
1292 static ChildWnd
* alloc_child_window(LPCWSTR path
, LPITEMIDLIST pidl
, HWND hwnd
)
1294 WCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
1295 WCHAR dir_path
[MAX_PATH
];
1296 static const WCHAR sAsterics
[] = {'*', '\0'};
1297 static const WCHAR sTitleFmt
[] = {'%','s',' ','-',' ','%','s','\0'};
1299 ChildWnd
* child
= HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd
));
1300 Root
* root
= &child
->root
;
1303 memset(child
, 0, sizeof(ChildWnd
));
1305 child
->left
.treePane
= TRUE
;
1306 child
->left
.visible_cols
= 0;
1308 child
->right
.treePane
= FALSE
;
1309 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_INDEX
|COL_LINKS
;
1311 child
->pos
.length
= sizeof(WINDOWPLACEMENT
);
1312 child
->pos
.flags
= 0;
1313 child
->pos
.showCmd
= SW_SHOWNORMAL
;
1314 child
->pos
.rcNormalPosition
.left
= CW_USEDEFAULT
;
1315 child
->pos
.rcNormalPosition
.top
= CW_USEDEFAULT
;
1316 child
->pos
.rcNormalPosition
.right
= CW_USEDEFAULT
;
1317 child
->pos
.rcNormalPosition
.bottom
= CW_USEDEFAULT
;
1319 child
->focus_pane
= 0;
1320 child
->split_pos
= DEFAULT_SPLIT_POS
;
1321 child
->sortOrder
= SORT_NAME
;
1322 child
->header_wdths_ok
= FALSE
;
1326 int pathlen
= strlenW(path
);
1327 const WCHAR
*npath
= path
;
1329 if (path
[0] == '"' && path
[pathlen
- 1] == '"')
1334 lstrcpynW(child
->path
, npath
, pathlen
+ 1);
1336 _wsplitpath(child
->path
, drv
, dir
, name
, ext
);
1339 lstrcpyW(child
->filter_pattern
, sAsterics
);
1340 child
->filter_flags
= TF_ALL
;
1342 root
->entry
.level
= 0;
1344 lstrcpyW(dir_path
, drv
);
1345 lstrcatW(dir_path
, dir
);
1346 entry
= read_tree(root
, dir_path
, pidl
, drv
, child
->sortOrder
, hwnd
);
1348 if (root
->entry
.etype
== ET_SHELL
)
1349 load_string(root
->entry
.data
.cFileName
, sizeof(root
->entry
.data
.cFileName
)/sizeof(root
->entry
.data
.cFileName
[0]), IDS_DESKTOP
);
1351 wsprintfW(root
->entry
.data
.cFileName
, sTitleFmt
, drv
, root
->fs
);
1353 root
->entry
.data
.dwFileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1355 child
->left
.root
= &root
->entry
;
1356 child
->right
.root
= NULL
;
1358 set_curdir(child
, entry
, 0, hwnd
);
1364 /* free all memory associated with a child window */
1365 static void free_child_window(ChildWnd
* child
)
1367 free_entries(&child
->root
.entry
);
1368 HeapFree(GetProcessHeap(), 0, child
);
1372 /* get full path of specified directory entry */
1373 static void get_path(Entry
* dir
, PWSTR path
)
1379 if (dir
->etype
== ET_SHELL
)
1389 hr
= IShellFolder_GetAttributesOf(dir
->folder
, 1, (LPCITEMIDLIST
*)&dir
->pidl
, &attribs
);
1391 if (SUCCEEDED(hr
) && (attribs
&SFGAO_FILESYSTEM
)) {
1392 IShellFolder
* parent
= dir
->up
? dir
->up
->folder
: Globals
.iDesktop
;
1394 hr
= path_from_pidlW(parent
, dir
->pidl
, path
, MAX_PATH
);
1399 for(entry
=dir
; entry
; level
++) {
1405 name
= entry
->data
.cFileName
;
1408 for(l
=0; *s
&& *s
!= '/' && *s
!= '\\'; s
++)
1414 memmove(path
+l
+1, path
, len
*sizeof(WCHAR
));
1415 memcpy(path
+1, name
, l
*sizeof(WCHAR
));
1418 if (entry
->etype
== ET_UNIX
)
1426 memmove(path
+l
, path
, len
*sizeof(WCHAR
));
1427 memcpy(path
, name
, l
*sizeof(WCHAR
));
1434 if (entry
->etype
== ET_UNIX
)
1444 static windowOptions
load_registry_settings(void)
1452 RegOpenKeyExW( HKEY_CURRENT_USER
, registry_key
,
1453 0, KEY_QUERY_VALUE
, &hKey
);
1455 size
= sizeof(DWORD
);
1457 if( RegQueryValueExW( hKey
, reg_start_x
, NULL
, &type
,
1458 (LPBYTE
) &opts
.start_x
, &size
) != ERROR_SUCCESS
)
1459 opts
.start_x
= CW_USEDEFAULT
;
1461 if( RegQueryValueExW( hKey
, reg_start_y
, NULL
, &type
,
1462 (LPBYTE
) &opts
.start_y
, &size
) != ERROR_SUCCESS
)
1463 opts
.start_y
= CW_USEDEFAULT
;
1465 if( RegQueryValueExW( hKey
, reg_width
, NULL
, &type
,
1466 (LPBYTE
) &opts
.width
, &size
) != ERROR_SUCCESS
)
1467 opts
.width
= CW_USEDEFAULT
;
1469 if( RegQueryValueExW( hKey
, reg_height
, NULL
, &type
,
1470 (LPBYTE
) &opts
.height
, &size
) != ERROR_SUCCESS
)
1471 opts
.height
= CW_USEDEFAULT
;
1472 size
=sizeof(logfont
);
1473 if( RegQueryValueExW( hKey
, reg_logfont
, NULL
, &type
,
1474 (LPBYTE
) &logfont
, &size
) != ERROR_SUCCESS
)
1475 GetObjectW(GetStockObject(DEFAULT_GUI_FONT
),sizeof(logfont
),&logfont
);
1477 RegCloseKey( hKey
);
1479 Globals
.hfont
= CreateFontIndirectW(&logfont
);
1483 static void save_registry_settings(void)
1490 wi
.cbSize
= sizeof( WINDOWINFO
);
1491 GetWindowInfo(Globals
.hMainWnd
, &wi
);
1492 width
= wi
.rcWindow
.right
- wi
.rcWindow
.left
;
1493 height
= wi
.rcWindow
.bottom
- wi
.rcWindow
.top
;
1495 if ( RegOpenKeyExW( HKEY_CURRENT_USER
, registry_key
,
1496 0, KEY_SET_VALUE
, &hKey
) != ERROR_SUCCESS
)
1498 /* Unable to save registry settings - try to create key */
1499 if ( RegCreateKeyExW( HKEY_CURRENT_USER
, registry_key
,
1500 0, NULL
, REG_OPTION_NON_VOLATILE
,
1501 KEY_SET_VALUE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
1503 /* FIXME: Cannot create key */
1507 /* Save all of the settings */
1508 RegSetValueExW( hKey
, reg_start_x
, 0, REG_DWORD
,
1509 (LPBYTE
) &wi
.rcWindow
.left
, sizeof(DWORD
) );
1510 RegSetValueExW( hKey
, reg_start_y
, 0, REG_DWORD
,
1511 (LPBYTE
) &wi
.rcWindow
.top
, sizeof(DWORD
) );
1512 RegSetValueExW( hKey
, reg_width
, 0, REG_DWORD
,
1513 (LPBYTE
) &width
, sizeof(DWORD
) );
1514 RegSetValueExW( hKey
, reg_height
, 0, REG_DWORD
,
1515 (LPBYTE
) &height
, sizeof(DWORD
) );
1516 GetObjectW(Globals
.hfont
, sizeof(logfont
), &logfont
);
1517 RegSetValueExW( hKey
, reg_logfont
, 0, REG_BINARY
,
1518 (LPBYTE
)&logfont
, sizeof(LOGFONTW
) );
1520 /* TODO: Save more settings here (List vs. Detailed View, etc.) */
1521 RegCloseKey( hKey
);
1524 static void resize_frame_rect(HWND hwnd
, PRECT prect
)
1529 if (IsWindowVisible(Globals
.htoolbar
)) {
1530 SendMessageW(Globals
.htoolbar
, WM_SIZE
, 0, 0);
1531 GetClientRect(Globals
.htoolbar
, &rt
);
1532 prect
->top
= rt
.bottom
+3;
1533 prect
->bottom
-= rt
.bottom
+3;
1536 if (IsWindowVisible(Globals
.hdrivebar
)) {
1537 SendMessageW(Globals
.hdrivebar
, WM_SIZE
, 0, 0);
1538 GetClientRect(Globals
.hdrivebar
, &rt
);
1539 new_top
= --prect
->top
+ rt
.bottom
+3;
1540 MoveWindow(Globals
.hdrivebar
, 0, prect
->top
, rt
.right
, new_top
, TRUE
);
1541 prect
->top
= new_top
;
1542 prect
->bottom
-= rt
.bottom
+2;
1545 if (IsWindowVisible(Globals
.hstatusbar
)) {
1546 int parts
[] = {300, 500};
1548 SendMessageW(Globals
.hstatusbar
, WM_SIZE
, 0, 0);
1549 SendMessageW(Globals
.hstatusbar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
1550 GetClientRect(Globals
.hstatusbar
, &rt
);
1551 prect
->bottom
-= rt
.bottom
;
1554 MoveWindow(Globals
.hmdiclient
, prect
->left
-1,prect
->top
-1,prect
->right
+2,prect
->bottom
+1, TRUE
);
1557 static void resize_frame(HWND hwnd
, int cx
, int cy
)
1566 resize_frame_rect(hwnd
, &rect
);
1569 static void resize_frame_client(HWND hwnd
)
1573 GetClientRect(hwnd
, &rect
);
1575 resize_frame_rect(hwnd
, &rect
);
1579 static HHOOK hcbthook
;
1580 static ChildWnd
* newchild
= NULL
;
1582 static LRESULT CALLBACK
CBTProc(int code
, WPARAM wparam
, LPARAM lparam
)
1584 if (code
==HCBT_CREATEWND
&& newchild
) {
1585 ChildWnd
* child
= newchild
;
1588 child
->hwnd
= (HWND
) wparam
;
1589 SetWindowLongPtrW(child
->hwnd
, GWLP_USERDATA
, (LPARAM
)child
);
1592 return CallNextHookEx(hcbthook
, code
, wparam
, lparam
);
1595 static HWND
create_child_window(ChildWnd
* child
)
1597 MDICREATESTRUCTW mcs
;
1600 mcs
.szClass
= sWINEFILETREE
;
1601 mcs
.szTitle
= child
->path
;
1602 mcs
.hOwner
= Globals
.hInstance
;
1603 mcs
.x
= child
->pos
.rcNormalPosition
.left
;
1604 mcs
.y
= child
->pos
.rcNormalPosition
.top
;
1605 mcs
.cx
= child
->pos
.rcNormalPosition
.right
-child
->pos
.rcNormalPosition
.left
;
1606 mcs
.cy
= child
->pos
.rcNormalPosition
.bottom
-child
->pos
.rcNormalPosition
.top
;
1610 hcbthook
= SetWindowsHookExW(WH_CBT
, CBTProc
, 0, GetCurrentThreadId());
1613 child
->hwnd
= (HWND
)SendMessageW(Globals
.hmdiclient
, WM_MDICREATE
, 0, (LPARAM
)&mcs
);
1615 UnhookWindowsHookEx(hcbthook
);
1619 UnhookWindowsHookEx(hcbthook
);
1621 SendMessageW(child
->left
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1622 SendMessageW(child
->right
.hwnd
, LB_SETITEMHEIGHT
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1624 idx
= SendMessageW(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)child
->left
.cur
);
1625 SendMessageW(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
1630 #define RFF_NODEFAULT 0x02 /* No default item selected. */
1632 static void WineFile_OnRun( HWND hwnd
)
1634 static const WCHAR shell32_dll
[] = {'S','H','E','L','L','3','2','.','D','L','L',0};
1635 void (WINAPI
*pRunFileDlgAW
)(HWND
, HICON
, LPWSTR
, LPWSTR
, LPWSTR
, DWORD
);
1636 HMODULE hshell
= GetModuleHandleW( shell32_dll
);
1638 pRunFileDlgAW
= (void*)GetProcAddress(hshell
, (LPCSTR
)61);
1639 if (pRunFileDlgAW
) pRunFileDlgAW( hwnd
, 0, NULL
, NULL
, NULL
, RFF_NODEFAULT
);
1642 static INT_PTR CALLBACK
DestinationDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1644 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1648 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, lparam
);
1649 SetWindowTextW(GetDlgItem(hwnd
, 201), (LPCWSTR
)lparam
);
1653 int id
= (int)wparam
;
1657 LPWSTR dest
= (LPWSTR
)GetWindowLongPtrW(hwnd
, GWLP_USERDATA
);
1658 GetWindowTextW(GetDlgItem(hwnd
, 201), dest
, MAX_PATH
);
1659 EndDialog(hwnd
, id
);
1663 EndDialog(hwnd
, id
);
1667 MessageBoxW(hwnd
, RS(b1
,IDS_NO_IMPL
), RS(b2
,IDS_WINEFILE
), MB_OK
);
1679 struct FilterDialog
{
1680 WCHAR pattern
[MAX_PATH
];
1684 static INT_PTR CALLBACK
FilterDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1686 static struct FilterDialog
* dlg
;
1690 dlg
= (struct FilterDialog
*) lparam
;
1691 SetWindowTextW(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
);
1692 set_check(hwnd
, IDC_VIEW_TYPE_DIRECTORIES
, dlg
->flags
&TF_DIRECTORIES
);
1693 set_check(hwnd
, IDC_VIEW_TYPE_PROGRAMS
, dlg
->flags
&TF_PROGRAMS
);
1694 set_check(hwnd
, IDC_VIEW_TYPE_DOCUMENTS
, dlg
->flags
&TF_DOCUMENTS
);
1695 set_check(hwnd
, IDC_VIEW_TYPE_OTHERS
, dlg
->flags
&TF_OTHERS
);
1696 set_check(hwnd
, IDC_VIEW_TYPE_HIDDEN
, dlg
->flags
&TF_HIDDEN
);
1700 int id
= (int)wparam
;
1705 GetWindowTextW(GetDlgItem(hwnd
, IDC_VIEW_PATTERN
), dlg
->pattern
, MAX_PATH
);
1707 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_DIRECTORIES
) ? TF_DIRECTORIES
: 0;
1708 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_PROGRAMS
) ? TF_PROGRAMS
: 0;
1709 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_DOCUMENTS
) ? TF_DOCUMENTS
: 0;
1710 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_OTHERS
) ? TF_OTHERS
: 0;
1711 flags
|= get_check(hwnd
, IDC_VIEW_TYPE_HIDDEN
) ? TF_HIDDEN
: 0;
1715 EndDialog(hwnd
, id
);
1716 } else if (id
== IDCANCEL
)
1717 EndDialog(hwnd
, id
);
1726 struct PropertiesDialog
{
1727 WCHAR path
[MAX_PATH
];
1732 /* Structure used to store enumerated languages and code pages. */
1733 struct LANGANDCODEPAGE
{
1738 static LPCSTR InfoStrings
[] = {
1754 static void PropDlg_DisplayValue(HWND hlbox
, HWND hedit
)
1756 int idx
= SendMessageW(hlbox
, LB_GETCURSEL
, 0, 0);
1758 if (idx
!= LB_ERR
) {
1759 LPCWSTR pValue
= (LPCWSTR
)SendMessageW(hlbox
, LB_GETITEMDATA
, idx
, 0);
1762 SetWindowTextW(hedit
, pValue
);
1766 static void CheckForFileInfo(struct PropertiesDialog
* dlg
, HWND hwnd
, LPCWSTR strFilename
)
1768 static const WCHAR sBackSlash
[] = {'\\','\0'};
1769 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'};
1770 static const WCHAR sStringFileInfo
[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1771 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1772 static const WCHAR sFmt
[] = {'%','d','.','%','d','.','%','d','.','%','d','\0'};
1773 DWORD dwVersionDataLen
= GetFileVersionInfoSizeW(strFilename
, NULL
);
1775 if (dwVersionDataLen
) {
1776 dlg
->pVersionData
= HeapAlloc(GetProcessHeap(), 0, dwVersionDataLen
);
1778 if (GetFileVersionInfoW(strFilename
, 0, dwVersionDataLen
, dlg
->pVersionData
)) {
1782 if (VerQueryValueW(dlg
->pVersionData
, sBackSlash
, &pVal
, &nValLen
)) {
1783 if (nValLen
== sizeof(VS_FIXEDFILEINFO
)) {
1784 VS_FIXEDFILEINFO
* pFixedFileInfo
= (VS_FIXEDFILEINFO
*)pVal
;
1785 WCHAR buffer
[BUFFER_LEN
];
1787 sprintfW(buffer
, sFmt
,
1788 HIWORD(pFixedFileInfo
->dwFileVersionMS
), LOWORD(pFixedFileInfo
->dwFileVersionMS
),
1789 HIWORD(pFixedFileInfo
->dwFileVersionLS
), LOWORD(pFixedFileInfo
->dwFileVersionLS
));
1791 SetDlgItemTextW(hwnd
, IDC_STATIC_PROP_VERSION
, buffer
);
1795 /* Read the list of languages and code pages. */
1796 if (VerQueryValueW(dlg
->pVersionData
, sTranslation
, &pVal
, &nValLen
)) {
1797 struct LANGANDCODEPAGE
* pTranslate
= (struct LANGANDCODEPAGE
*)pVal
;
1798 struct LANGANDCODEPAGE
* pEnd
= (struct LANGANDCODEPAGE
*)((LPBYTE
)pVal
+nValLen
);
1800 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
1802 /* Read the file description for each language and code page. */
1803 for(; pTranslate
<pEnd
; ++pTranslate
) {
1806 for(p
=InfoStrings
; *p
; ++p
) {
1807 WCHAR subblock
[200];
1812 LPCSTR pInfoString
= *p
;
1813 MultiByteToWideChar(CP_ACP
, 0, pInfoString
, -1, infoStr
, 100);
1814 wsprintfW(subblock
, sStringFileInfo
, pTranslate
->wLanguage
, pTranslate
->wCodePage
, infoStr
);
1816 /* Retrieve file description for language and code page */
1817 if (VerQueryValueW(dlg
->pVersionData
, subblock
, (PVOID
)&pTxt
, &nValLen
)) {
1818 int idx
= SendMessageW(hlbox
, LB_ADDSTRING
, 0L, (LPARAM
)infoStr
);
1819 SendMessageW(hlbox
, LB_SETITEMDATA
, idx
, (LPARAM
)pTxt
);
1824 SendMessageW(hlbox
, LB_SETCURSEL
, 0, 0);
1826 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
1832 static INT_PTR CALLBACK
PropertiesDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1834 static struct PropertiesDialog
* dlg
;
1837 case WM_INITDIALOG
: {
1838 static const WCHAR sByteFmt
[] = {'%','s',' ','B','y','t','e','s','\0'};
1839 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1840 LPWIN32_FIND_DATAW pWFD
;
1842 dlg
= (struct PropertiesDialog
*) lparam
;
1843 pWFD
= (LPWIN32_FIND_DATAW
)&dlg
->entry
.data
;
1845 GetWindowTextW(hwnd
, b1
, MAX_PATH
);
1846 wsprintfW(b2
, b1
, pWFD
->cFileName
);
1847 SetWindowTextW(hwnd
, b2
);
1849 format_date(&pWFD
->ftLastWriteTime
, b1
, COL_DATE
|COL_TIME
);
1850 SetWindowTextW(GetDlgItem(hwnd
, IDC_STATIC_PROP_LASTCHANGE
), b1
);
1852 format_longlong( b1
, ((ULONGLONG
)pWFD
->nFileSizeHigh
<< 32) | pWFD
->nFileSizeLow
);
1853 wsprintfW(b2
, sByteFmt
, b1
);
1854 SetWindowTextW(GetDlgItem(hwnd
, IDC_STATIC_PROP_SIZE
), b2
);
1856 SetWindowTextW(GetDlgItem(hwnd
, IDC_STATIC_PROP_FILENAME
), pWFD
->cFileName
);
1857 SetWindowTextW(GetDlgItem(hwnd
, IDC_STATIC_PROP_PATH
), dlg
->path
);
1859 set_check(hwnd
, IDC_CHECK_READONLY
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_READONLY
);
1860 set_check(hwnd
, IDC_CHECK_ARCHIVE
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_ARCHIVE
);
1861 set_check(hwnd
, IDC_CHECK_COMPRESSED
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_COMPRESSED
);
1862 set_check(hwnd
, IDC_CHECK_HIDDEN
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_HIDDEN
);
1863 set_check(hwnd
, IDC_CHECK_SYSTEM
, pWFD
->dwFileAttributes
&FILE_ATTRIBUTE_SYSTEM
);
1865 CheckForFileInfo(dlg
, hwnd
, dlg
->path
);
1869 int id
= (int)wparam
;
1871 switch(HIWORD(wparam
)) {
1872 case LBN_SELCHANGE
: {
1873 HWND hlbox
= GetDlgItem(hwnd
, IDC_LIST_PROP_VERSION_TYPES
);
1874 PropDlg_DisplayValue(hlbox
, GetDlgItem(hwnd
,IDC_LIST_PROP_VERSION_VALUES
));
1879 if (id
==IDOK
|| id
==IDCANCEL
)
1880 EndDialog(hwnd
, id
);
1886 HeapFree(GetProcessHeap(), 0, dlg
->pVersionData
);
1887 dlg
->pVersionData
= NULL
;
1894 static void show_properties_dlg(Entry
* entry
, HWND hwnd
)
1896 struct PropertiesDialog dlg
;
1898 memset(&dlg
, 0, sizeof(struct PropertiesDialog
));
1899 get_path(entry
, dlg
.path
);
1900 memcpy(&dlg
.entry
, entry
, sizeof(Entry
));
1902 DialogBoxParamW(Globals
.hInstance
, MAKEINTRESOURCEW(IDD_DIALOG_PROPERTIES
), hwnd
, PropertiesDialogDlgProc
, (LPARAM
)&dlg
);
1905 static struct FullScreenParameters
{
1915 static void frame_get_clientspace(HWND hwnd
, PRECT prect
)
1919 if (!IsIconic(hwnd
))
1920 GetClientRect(hwnd
, prect
);
1924 GetWindowPlacement(hwnd
, &wp
);
1926 prect
->left
= prect
->top
= 0;
1927 prect
->right
= wp
.rcNormalPosition
.right
-wp
.rcNormalPosition
.left
-
1928 2*(GetSystemMetrics(SM_CXSIZEFRAME
)+GetSystemMetrics(SM_CXEDGE
));
1929 prect
->bottom
= wp
.rcNormalPosition
.bottom
-wp
.rcNormalPosition
.top
-
1930 2*(GetSystemMetrics(SM_CYSIZEFRAME
)+GetSystemMetrics(SM_CYEDGE
))-
1931 GetSystemMetrics(SM_CYCAPTION
)-GetSystemMetrics(SM_CYMENUSIZE
);
1934 if (IsWindowVisible(Globals
.htoolbar
)) {
1935 GetClientRect(Globals
.htoolbar
, &rt
);
1936 prect
->top
+= rt
.bottom
+2;
1939 if (IsWindowVisible(Globals
.hdrivebar
)) {
1940 GetClientRect(Globals
.hdrivebar
, &rt
);
1941 prect
->top
+= rt
.bottom
+2;
1944 if (IsWindowVisible(Globals
.hstatusbar
)) {
1945 GetClientRect(Globals
.hstatusbar
, &rt
);
1946 prect
->bottom
-= rt
.bottom
;
1950 static BOOL
toggle_fullscreen(HWND hwnd
)
1954 if ((g_fullscreen
.mode
=!g_fullscreen
.mode
)) {
1955 GetWindowRect(hwnd
, &g_fullscreen
.orgPos
);
1956 g_fullscreen
.wasZoomed
= IsZoomed(hwnd
);
1958 Frame_CalcFrameClient(hwnd
, &rt
);
1959 MapWindowPoints( hwnd
, 0, (POINT
*)&rt
, 2 );
1961 rt
.left
= g_fullscreen
.orgPos
.left
-rt
.left
;
1962 rt
.top
= g_fullscreen
.orgPos
.top
-rt
.top
;
1963 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+g_fullscreen
.orgPos
.right
-rt
.right
;
1964 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+g_fullscreen
.orgPos
.bottom
-rt
.bottom
;
1966 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
1968 MoveWindow(hwnd
, g_fullscreen
.orgPos
.left
, g_fullscreen
.orgPos
.top
,
1969 g_fullscreen
.orgPos
.right
-g_fullscreen
.orgPos
.left
,
1970 g_fullscreen
.orgPos
.bottom
-g_fullscreen
.orgPos
.top
, TRUE
);
1972 if (g_fullscreen
.wasZoomed
)
1973 ShowWindow(hwnd
, WS_MAXIMIZE
);
1976 return g_fullscreen
.mode
;
1979 static void fullscreen_move(HWND hwnd
)
1982 GetWindowRect(hwnd
, &pos
);
1984 Frame_CalcFrameClient(hwnd
, &rt
);
1985 MapWindowPoints( hwnd
, 0, (POINT
*)&rt
, 2 );
1987 rt
.left
= pos
.left
-rt
.left
;
1988 rt
.top
= pos
.top
-rt
.top
;
1989 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+pos
.right
-rt
.right
;
1990 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+pos
.bottom
-rt
.bottom
;
1992 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
1995 static void toggle_child(HWND hwnd
, UINT cmd
, HWND hchild
)
1997 BOOL vis
= IsWindowVisible(hchild
);
1999 CheckMenuItem(Globals
.hMenuOptions
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
2001 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
2003 if (g_fullscreen
.mode
)
2004 fullscreen_move(hwnd
);
2006 resize_frame_client(hwnd
);
2009 static BOOL
activate_drive_window(LPCWSTR path
)
2011 WCHAR drv1
[_MAX_DRIVE
], drv2
[_MAX_DRIVE
];
2014 _wsplitpath(path
, drv1
, 0, 0, 0);
2016 /* search for an already open window for the same drive */
2017 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2018 ChildWnd
* child
= (ChildWnd
*)GetWindowLongPtrW(child_wnd
, GWLP_USERDATA
);
2021 _wsplitpath(child
->root
.path
, drv2
, 0, 0, 0);
2023 if (!lstrcmpiW(drv2
, drv1
)) {
2024 SendMessageW(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2026 if (IsIconic(child_wnd
))
2027 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2037 static BOOL
activate_fs_window(LPCWSTR filesys
)
2041 /* search for an already open window of the given file system name */
2042 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
2043 ChildWnd
* child
= (ChildWnd
*) GetWindowLongPtrW(child_wnd
, GWLP_USERDATA
);
2046 if (!lstrcmpiW(child
->root
.fs
, filesys
)) {
2047 SendMessageW(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
2049 if (IsIconic(child_wnd
))
2050 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
2060 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
2062 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2066 if (Globals
.saveSettings
)
2067 save_registry_settings();
2069 DestroyWindow(hwnd
);
2071 /* clear handle variables */
2072 Globals
.hMenuFrame
= 0;
2073 Globals
.hMenuView
= 0;
2074 Globals
.hMenuOptions
= 0;
2075 Globals
.hMainWnd
= 0;
2076 Globals
.hmdiclient
= 0;
2077 Globals
.hdrivebar
= 0;
2084 case WM_INITMENUPOPUP
: {
2085 HWND hwndClient
= (HWND
)SendMessageW(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2087 if (!SendMessageW(hwndClient
, WM_INITMENUPOPUP
, wparam
, lparam
))
2092 UINT cmd
= LOWORD(wparam
);
2093 HWND hwndClient
= (HWND
)SendMessageW(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
2095 if (SendMessageW(hwndClient
, WM_DISPATCH_COMMAND
, wparam
, lparam
))
2098 if (cmd
>=ID_DRIVE_FIRST
&& cmd
<=ID_DRIVE_FIRST
+0xFF) {
2099 WCHAR drv
[_MAX_DRIVE
], path
[MAX_PATH
];
2101 LPCWSTR root
= Globals
.drives
;
2104 for(i
=cmd
-ID_DRIVE_FIRST
; i
--; root
++)
2108 if (activate_drive_window(root
))
2111 _wsplitpath(root
, drv
, 0, 0, 0);
2113 if (!SetCurrentDirectoryW(drv
)) {
2114 display_error(hwnd
, GetLastError());
2118 GetCurrentDirectoryW(MAX_PATH
, path
); /*TODO: store last directory per drive */
2119 child
= alloc_child_window(path
, NULL
, hwnd
);
2121 if (!create_child_window(child
))
2122 HeapFree(GetProcessHeap(), 0, child
);
2123 } else switch(cmd
) {
2125 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
2128 case ID_WINDOW_NEW
: {
2129 WCHAR path
[MAX_PATH
];
2132 GetCurrentDirectoryW(MAX_PATH
, path
);
2133 child
= alloc_child_window(path
, NULL
, hwnd
);
2135 if (!create_child_window(child
))
2136 HeapFree(GetProcessHeap(), 0, child
);
2143 case ID_WINDOW_CASCADE
:
2144 SendMessageW(Globals
.hmdiclient
, WM_MDICASCADE
, 0, 0);
2147 case ID_WINDOW_TILE_HORZ
:
2148 SendMessageW(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
2151 case ID_WINDOW_TILE_VERT
:
2152 SendMessageW(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
2155 case ID_WINDOW_ARRANGE
:
2156 SendMessageW(Globals
.hmdiclient
, WM_MDIICONARRANGE
, 0, 0);
2159 case ID_SELECT_FONT
:
2163 case ID_VIEW_TOOL_BAR
:
2164 toggle_child(hwnd
, cmd
, Globals
.htoolbar
);
2167 case ID_VIEW_DRIVE_BAR
:
2168 toggle_child(hwnd
, cmd
, Globals
.hdrivebar
);
2171 case ID_VIEW_STATUSBAR
:
2172 toggle_child(hwnd
, cmd
, Globals
.hstatusbar
);
2175 case ID_VIEW_SAVESETTINGS
:
2176 Globals
.saveSettings
= !Globals
.saveSettings
;
2177 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_SAVESETTINGS
,
2178 Globals
.saveSettings
? MF_CHECKED
: MF_UNCHECKED
);
2182 WineFile_OnRun( hwnd
);
2185 case ID_CONNECT_NETWORK_DRIVE
: {
2186 DWORD ret
= WNetConnectionDialog(hwnd
, RESOURCETYPE_DISK
);
2187 if (ret
== NO_ERROR
)
2189 else if (ret
!= (DWORD
)-1) {
2190 if (ret
== ERROR_EXTENDED_ERROR
)
2191 display_network_error(hwnd
);
2193 display_error(hwnd
, ret
);
2197 case ID_DISCONNECT_NETWORK_DRIVE
: {
2198 DWORD ret
= WNetDisconnectDialog(hwnd
, RESOURCETYPE_DISK
);
2199 if (ret
== NO_ERROR
)
2201 else if (ret
!= (DWORD
)-1) {
2202 if (ret
== ERROR_EXTENDED_ERROR
)
2203 display_network_error(hwnd
);
2205 display_error(hwnd
, ret
);
2210 WinHelpW(hwnd
, RS(b1
,IDS_WINEFILE
), HELP_INDEX
, 0);
2213 case ID_VIEW_FULLSCREEN
:
2214 CheckMenuItem(Globals
.hMenuOptions
, cmd
, toggle_fullscreen(hwnd
)?MF_CHECKED
:0);
2218 case ID_DRIVE_UNIX_FS
: {
2219 WCHAR path
[MAX_PATH
];
2220 char cpath
[MAX_PATH
];
2223 if (activate_fs_window(RS(b1
,IDS_UNIXFS
)))
2226 getcwd(cpath
, MAX_PATH
);
2227 MultiByteToWideChar(CP_UNIXCP
, 0, cpath
, -1, path
, MAX_PATH
);
2228 child
= alloc_child_window(path
, NULL
, hwnd
);
2230 if (!create_child_window(child
))
2231 HeapFree(GetProcessHeap(), 0, child
);
2234 case ID_DRIVE_SHELL_NS
: {
2235 WCHAR path
[MAX_PATH
];
2238 if (activate_fs_window(RS(b1
,IDS_SHELL
)))
2241 GetCurrentDirectoryW(MAX_PATH
, path
);
2242 child
= alloc_child_window(path
, get_path_pidl(path
,hwnd
), hwnd
);
2244 if (!create_child_window(child
))
2245 HeapFree(GetProcessHeap(), 0, child
);
2248 /*TODO: There are even more menu items! */
2251 ShellAboutW(hwnd
, RS(b1
,IDS_WINEFILE
), NULL
,
2252 LoadImageW( Globals
.hInstance
, MAKEINTRESOURCEW(IDI_WINEFILE
),
2253 IMAGE_ICON
, 48, 48, LR_SHARED
));
2257 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2258 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2259 else */if ((cmd
<IDW_FIRST_CHILD
|| cmd
>=IDW_FIRST_CHILD
+0x100) &&
2260 (cmd
<SC_SIZE
|| cmd
>SC_RESTORE
))
2261 MessageBoxW(hwnd
, RS(b2
,IDS_NO_IMPL
), RS(b1
,IDS_WINEFILE
), MB_OK
);
2263 return DefFrameProcW(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2268 resize_frame(hwnd
, LOWORD(lparam
), HIWORD(lparam
));
2269 break; /* do not pass message to DefFrameProcW */
2271 case WM_DEVICECHANGE
:
2272 SendMessageW(hwnd
, WM_COMMAND
, MAKELONG(ID_REFRESH
,0), 0);
2275 case WM_GETMINMAXINFO
: {
2276 LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
2278 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2279 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2282 case FRM_CALC_CLIENT
:
2283 frame_get_clientspace(hwnd
, (PRECT
)lparam
);
2287 return DefFrameProcW(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2294 static WCHAR g_pos_names
[COLUMNS
][40] = {
2298 static const int g_pos_align
[] = {
2300 HDF_LEFT
, /* Name */
2301 HDF_RIGHT
, /* Size */
2302 HDF_LEFT
, /* CDate */
2303 HDF_LEFT
, /* ADate */
2304 HDF_LEFT
, /* MDate */
2305 HDF_LEFT
, /* Index */
2306 HDF_CENTER
, /* Links */
2307 HDF_CENTER
, /* Attributes */
2308 HDF_LEFT
/* Security */
2311 static void resize_tree(ChildWnd
* child
, int cx
, int cy
)
2313 HDWP hdwp
= BeginDeferWindowPos(4);
2323 cx
= child
->split_pos
+ SPLIT_WIDTH
/2;
2327 SendMessageW(child
->left
.hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hdl
);
2329 DeferWindowPos(hdwp
, child
->left
.hwndHeader
, wp
.hwndInsertAfter
,
2330 wp
.x
-1, wp
.y
, child
->split_pos
-SPLIT_WIDTH
/2+1, wp
.cy
, wp
.flags
);
2331 DeferWindowPos(hdwp
, child
->right
.hwndHeader
, wp
.hwndInsertAfter
,
2332 rt
.left
+cx
+1, wp
.y
, wp
.cx
-cx
+2, wp
.cy
, wp
.flags
);
2333 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
);
2334 DeferWindowPos(hdwp
, child
->right
.hwnd
, 0, rt
.left
+cx
+1, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
2336 EndDeferWindowPos(hdwp
);
2339 static HWND
create_header(HWND parent
, Pane
* pane
, UINT id
)
2344 HWND hwnd
= CreateWindowW(WC_HEADERW
, 0, WS_CHILD
|WS_VISIBLE
|HDS_HORZ
|HDS_FULLDRAG
/*TODO: |HDS_BUTTONS + sort orders*/,
2345 0, 0, 0, 0, parent
, (HMENU
)ULongToHandle(id
), Globals
.hInstance
, 0);
2349 SendMessageW(hwnd
, WM_SETFONT
, (WPARAM
)GetStockObject(DEFAULT_GUI_FONT
), FALSE
);
2351 hdi
.mask
= HDI_TEXT
|HDI_WIDTH
|HDI_FORMAT
;
2353 for(idx
=0; idx
<COLUMNS
; idx
++) {
2354 hdi
.pszText
= g_pos_names
[idx
];
2355 hdi
.fmt
= HDF_STRING
| g_pos_align
[idx
];
2356 hdi
.cxy
= pane
->widths
[idx
];
2357 SendMessageW(hwnd
, HDM_INSERTITEMW
, idx
, (LPARAM
)&hdi
);
2363 static void init_output(HWND hwnd
)
2365 static const WCHAR s1000
[] = {'1','0','0','0','\0'};
2368 HDC hdc
= GetDC(hwnd
);
2370 if (GetNumberFormatW(LOCALE_USER_DEFAULT
, 0, s1000
, 0, b
, 16) > 4)
2371 Globals
.num_sep
= b
[1];
2373 Globals
.num_sep
= '.';
2375 old_font
= SelectObject(hdc
, Globals
.hfont
);
2376 GetTextExtentPoint32W(hdc
, sSpace
, 1, &Globals
.spaceSize
);
2377 SelectObject(hdc
, old_font
);
2378 ReleaseDC(hwnd
, hdc
);
2381 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
);
2384 /* calculate preferred width for all visible columns */
2386 static BOOL
calc_widths(Pane
* pane
, BOOL anyway
)
2388 int col
, x
, cx
, spc
=3*Globals
.spaceSize
.cx
;
2389 int entries
= SendMessageW(pane
->hwnd
, LB_GETCOUNT
, 0, 0);
2390 int orgWidths
[COLUMNS
];
2391 int orgPositions
[COLUMNS
+1];
2397 memcpy(orgWidths
, pane
->widths
, sizeof(orgWidths
));
2398 memcpy(orgPositions
, pane
->positions
, sizeof(orgPositions
));
2401 for(col
=0; col
<COLUMNS
; col
++)
2402 pane
->widths
[col
] = 0;
2404 hdc
= GetDC(pane
->hwnd
);
2405 hfontOld
= SelectObject(hdc
, Globals
.hfont
);
2407 for(cnt
=0; cnt
<entries
; cnt
++) {
2408 Entry
* entry
= (Entry
*)SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, cnt
, 0);
2417 dis
.hwndItem
= pane
->hwnd
;
2419 dis
.rcItem
.left
= 0;
2421 dis
.rcItem
.right
= 0;
2422 dis
.rcItem
.bottom
= 0;
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 dis
.rcItem
.left
= 0;
2497 dis
.rcItem
.right
= 0;
2498 dis
.rcItem
.bottom
= 0;
2499 /*dis.itemData = 0; */
2501 draw_item(pane
, &dis
, entry
, col
);
2504 SelectObject(hdc
, hfontOld
);
2505 ReleaseDC(pane
->hwnd
, hdc
);
2507 cx
= pane
->widths
[col
];
2510 cx
+= 3*Globals
.spaceSize
.cx
;
2512 if (cx
< IMAGE_WIDTH
)
2516 pane
->widths
[col
] = cx
;
2518 x
= pane
->positions
[col
] + cx
;
2520 for(; col
<COLUMNS
-1; ) {
2521 pane
->positions
[++col
] = x
;
2522 x
+= pane
->widths
[col
];
2525 SendMessageW(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, x
, 0);
2528 static BOOL
pattern_match(LPCWSTR str
, LPCWSTR pattern
)
2530 for( ; *str
&&*pattern
; str
++,pattern
++) {
2531 if (*pattern
== '*') {
2533 while(*pattern
== '*');
2539 if (*str
==*pattern
&& pattern_match(str
, pattern
))
2544 else if (*str
!=*pattern
&& *pattern
!='?')
2548 if (*str
|| *pattern
)
2549 if (*pattern
!='*' || pattern
[1]!='\0')
2555 static BOOL
pattern_imatch(LPCWSTR str
, LPCWSTR pattern
)
2557 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2560 lstrcpyW(b2
, pattern
);
2564 return pattern_match(b1
, b2
);
2574 static enum FILE_TYPE
get_file_type(LPCWSTR filename
);
2577 /* insert listbox entries after index idx */
2579 static int insert_entries(Pane
* pane
, Entry
* dir
, LPCWSTR pattern
, int filter_flags
, int idx
)
2586 ShowWindow(pane
->hwnd
, SW_HIDE
);
2588 for(; entry
; entry
=entry
->next
) {
2589 if (pane
->treePane
&& !(entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
2592 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
2593 /* don't display entries "." and ".." in the left pane */
2594 if (pane
->treePane
&& entry
->data
.cFileName
[0] == '.')
2595 if (entry
->data
.cFileName
[1] == '\0' ||
2596 (entry
->data
.cFileName
[1] == '.' &&
2597 entry
->data
.cFileName
[2] == '\0'))
2600 /* filter directories in right pane */
2601 if (!pane
->treePane
&& !(filter_flags
&TF_DIRECTORIES
))
2605 /* filter using the file name pattern */
2607 if (!pattern_imatch(entry
->data
.cFileName
, pattern
))
2610 /* filter system and hidden files */
2611 if (!(filter_flags
&TF_HIDDEN
) && (entry
->data
.dwFileAttributes
&(FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
)))
2614 /* filter looking at the file type */
2615 if ((filter_flags
&(TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
)) != (TF_PROGRAMS
|TF_DOCUMENTS
|TF_OTHERS
))
2616 switch(get_file_type(entry
->data
.cFileName
)) {
2618 if (!(filter_flags
& TF_PROGRAMS
))
2623 if (!(filter_flags
& TF_DOCUMENTS
))
2627 default: /* TF_OTHERS */
2628 if (!(filter_flags
& TF_OTHERS
))
2635 SendMessageW(pane
->hwnd
, LB_INSERTSTRING
, idx
, (LPARAM
)entry
);
2637 if (pane
->treePane
&& entry
->expanded
)
2638 idx
= insert_entries(pane
, entry
->down
, pattern
, filter_flags
, idx
);
2641 ShowWindow(pane
->hwnd
, SW_SHOW
);
2647 static void format_bytes(LPWSTR buffer
, LONGLONG bytes
)
2649 static const WCHAR sFmtSmall
[] = {'%', 'u', 0};
2650 static const WCHAR sFmtBig
[] = {'%', '.', '1', 'f', ' ', '%', 's', '\0'};
2653 sprintfW(buffer
, sFmtSmall
, (DWORD
)bytes
);
2659 if (bytes
>= 1073741824) /* 1 GB */
2661 fBytes
= ((float)bytes
)/1073741824.f
+.5f
;
2662 resid
= IDS_UNIT_GB
;
2664 else if (bytes
>= 1048576) /* 1 MB */
2666 fBytes
= ((float)bytes
)/1048576.f
+.5f
;
2667 resid
= IDS_UNIT_MB
;
2669 else /* bytes >= 1024 */ /* 1 kB */
2671 fBytes
= ((float)bytes
)/1024.f
+.5f
;
2672 resid
= IDS_UNIT_KB
;
2674 LoadStringW(Globals
.hInstance
, resid
, unit
, sizeof(unit
)/sizeof(*unit
));
2675 sprintfW(buffer
, sFmtBig
, fBytes
, unit
);
2679 static void set_space_status(void)
2681 ULARGE_INTEGER ulFreeBytesToCaller
, ulTotalBytes
, ulFreeBytes
;
2682 WCHAR fmt
[64], b1
[64], b2
[64], buffer
[BUFFER_LEN
];
2684 if (GetDiskFreeSpaceExW(NULL
, &ulFreeBytesToCaller
, &ulTotalBytes
, &ulFreeBytes
)) {
2686 format_bytes(b1
, ulFreeBytesToCaller
.QuadPart
);
2687 format_bytes(b2
, ulTotalBytes
.QuadPart
);
2688 args
[0] = (DWORD_PTR
)b1
;
2689 args
[1] = (DWORD_PTR
)b2
;
2690 FormatMessageW(FORMAT_MESSAGE_FROM_STRING
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
2691 RS(fmt
,IDS_FREE_SPACE_FMT
), 0, 0, buffer
,
2692 sizeof(buffer
)/sizeof(*buffer
), (__ms_va_list
*)args
);
2694 lstrcpyW(buffer
, sQMarks
);
2696 SendMessageW(Globals
.hstatusbar
, SB_SETTEXTW
, 0, (LPARAM
)buffer
);
2700 static WNDPROC g_orgTreeWndProc
;
2702 static void create_tree_window(HWND parent
, Pane
* pane
, UINT id
, UINT id_header
, LPCWSTR pattern
, int filter_flags
)
2704 static const WCHAR sListBox
[] = {'L','i','s','t','B','o','x','\0'};
2706 static BOOL s_init
= FALSE
;
2707 Entry
* entry
= pane
->root
;
2709 pane
->hwnd
= CreateWindowW(sListBox
, sEmpty
, WS_CHILD
|WS_VISIBLE
|WS_HSCROLL
|WS_VSCROLL
|
2710 LBS_DISABLENOSCROLL
|LBS_NOINTEGRALHEIGHT
|LBS_OWNERDRAWFIXED
|LBS_NOTIFY
,
2711 0, 0, 0, 0, parent
, (HMENU
)ULongToHandle(id
), Globals
.hInstance
, 0);
2713 SetWindowLongPtrW(pane
->hwnd
, GWLP_USERDATA
, (LPARAM
)pane
);
2714 g_orgTreeWndProc
= (WNDPROC
)SetWindowLongPtrW(pane
->hwnd
, GWLP_WNDPROC
, (LPARAM
)TreeWndProc
);
2716 SendMessageW(pane
->hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hfont
, FALSE
);
2718 /* insert entries into listbox */
2720 insert_entries(pane
, entry
, pattern
, filter_flags
, -1);
2722 /* calculate column widths */
2725 init_output(pane
->hwnd
);
2728 calc_widths(pane
, TRUE
);
2730 pane
->hwndHeader
= create_header(parent
, pane
, id_header
);
2734 static void InitChildWindow(ChildWnd
* child
)
2736 create_tree_window(child
->hwnd
, &child
->left
, IDW_TREE_LEFT
, IDW_HEADER_LEFT
, NULL
, TF_ALL
);
2737 create_tree_window(child
->hwnd
, &child
->right
, IDW_TREE_RIGHT
, IDW_HEADER_RIGHT
, child
->filter_pattern
, child
->filter_flags
);
2741 static void format_date(const FILETIME
* ft
, WCHAR
* buffer
, int visible_cols
)
2749 if (!ft
->dwLowDateTime
&& !ft
->dwHighDateTime
)
2752 if (!FileTimeToLocalFileTime(ft
, &lft
))
2753 {err
: lstrcpyW(buffer
,sQMarks
); return;}
2755 if (!FileTimeToSystemTime(&lft
, &systime
))
2758 if (visible_cols
& COL_DATE
) {
2759 len
= GetDateFormatW(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
, BUFFER_LEN
);
2764 if (visible_cols
& COL_TIME
) {
2766 buffer
[len
-1] = ' ';
2768 buffer
[len
++] = ' ';
2770 if (!GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
+len
, BUFFER_LEN
-len
))
2776 static void calc_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
)
2778 RECT rt
= {0, 0, 0, 0};
2780 DrawTextW(dis
->hDC
, str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
2782 if (rt
.right
> pane
->widths
[col
])
2783 pane
->widths
[col
] = rt
.right
;
2786 static void calc_tabbed_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
)
2788 RECT rt
= {0, 0, 0, 0};
2790 DrawTextW(dis
->hDC
, str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2791 /*FIXME rt (0,0) ??? */
2793 if (rt
.right
> pane
->widths
[col
])
2794 pane
->widths
[col
] = rt
.right
;
2798 static void output_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
, DWORD flags
)
2800 int x
= dis
->rcItem
.left
;
2803 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2804 rt
.top
= dis
->rcItem
.top
;
2805 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2806 rt
.bottom
= dis
->rcItem
.bottom
;
2808 DrawTextW(dis
->hDC
, str
, -1, &rt
, DT_SINGLELINE
|DT_NOPREFIX
|flags
);
2811 static void output_tabbed_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
)
2813 int x
= dis
->rcItem
.left
;
2816 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2817 rt
.top
= dis
->rcItem
.top
;
2818 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2819 rt
.bottom
= dis
->rcItem
.bottom
;
2821 DrawTextW(dis
->hDC
, str
, -1, &rt
, DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2824 static void output_number(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCWSTR str
)
2826 int x
= dis
->rcItem
.left
;
2833 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2834 rt
.top
= dis
->rcItem
.top
;
2835 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2836 rt
.bottom
= dis
->rcItem
.bottom
;
2841 /* insert number separator characters */
2842 pos
= lstrlenW(s
) % 3;
2848 *d
++ = Globals
.num_sep
;
2852 DrawTextW(dis
->hDC
, b
, d
-b
, &rt
, DT_RIGHT
|DT_SINGLELINE
|DT_NOPREFIX
|DT_END_ELLIPSIS
);
2856 static BOOL
is_exe_file(LPCWSTR ext
)
2858 static const WCHAR executable_extensions
[][4] = {
2869 WCHAR ext_buffer
[_MAX_EXT
];
2870 const WCHAR (*p
)[4];
2874 for(s
=ext
+1,d
=ext_buffer
; (*d
=tolower(*s
)); s
++)
2877 for(p
=executable_extensions
; (*p
)[0]; p
++)
2878 if (!lstrcmpiW(ext_buffer
, *p
))
2884 static BOOL
is_registered_type(LPCWSTR ext
)
2886 /* check if there exists a classname for this file extension in the registry */
2887 if (!RegQueryValueW(HKEY_CLASSES_ROOT
, ext
, NULL
, NULL
))
2893 static enum FILE_TYPE
get_file_type(LPCWSTR filename
)
2895 LPCWSTR ext
= strrchrW(filename
, '.');
2899 if (is_exe_file(ext
))
2900 return FT_EXECUTABLE
;
2901 else if (is_registered_type(ext
))
2908 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
)
2910 WCHAR buffer
[BUFFER_LEN
];
2912 int visible_cols
= pane
->visible_cols
;
2913 COLORREF bkcolor
, textcolor
;
2914 RECT focusRect
= dis
->rcItem
;
2921 attrs
= entry
->data
.dwFileAttributes
;
2923 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) {
2924 if (entry
->data
.cFileName
[0] == '.' && entry
->data
.cFileName
[1] == '.'
2925 && entry
->data
.cFileName
[2] == '\0')
2926 img
= IMG_FOLDER_UP
;
2927 else if (entry
->data
.cFileName
[0] == '.' && entry
->data
.cFileName
[1] == '\0')
2928 img
= IMG_FOLDER_CUR
;
2929 else if (pane
->treePane
&& (dis
->itemState
&ODS_FOCUS
))
2930 img
= IMG_OPEN_FOLDER
;
2934 switch(get_file_type(entry
->data
.cFileName
)) {
2935 case FT_EXECUTABLE
: img
= IMG_EXECUTABLE
; break;
2936 case FT_DOCUMENT
: img
= IMG_DOCUMENT
; break;
2937 default: img
= IMG_FILE
;
2945 if (pane
->treePane
) {
2947 img_pos
= dis
->rcItem
.left
+ entry
->level
*(IMAGE_WIDTH
+TREE_LINE_DX
);
2949 if (calcWidthCol
== -1) {
2951 int y
= dis
->rcItem
.top
+ IMAGE_HEIGHT
/2;
2954 HRGN hrgn_org
= CreateRectRgn(0, 0, 0, 0);
2957 rt_clip
.left
= dis
->rcItem
.left
;
2958 rt_clip
.top
= dis
->rcItem
.top
;
2959 rt_clip
.right
= dis
->rcItem
.left
+pane
->widths
[col
];
2960 rt_clip
.bottom
= dis
->rcItem
.bottom
;
2962 hrgn
= CreateRectRgnIndirect(&rt_clip
);
2964 if (!GetClipRgn(dis
->hDC
, hrgn_org
)) {
2965 DeleteObject(hrgn_org
);
2969 ExtSelectClipRgn(dis
->hDC
, hrgn
, RGN_AND
);
2972 if ((up
=entry
->up
) != NULL
) {
2973 MoveToEx(dis
->hDC
, img_pos
-IMAGE_WIDTH
/2, y
, 0);
2974 LineTo(dis
->hDC
, img_pos
-2, y
);
2976 x
= img_pos
- IMAGE_WIDTH
/2;
2979 x
-= IMAGE_WIDTH
+TREE_LINE_DX
;
2982 && (up
->next
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
2984 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
2985 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
2987 } while((up
=up
->up
) != NULL
);
2990 x
= img_pos
- IMAGE_WIDTH
/2;
2992 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
2993 LineTo(dis
->hDC
, x
, y
);
2996 && (entry
->next
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
2997 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
2999 SelectClipRgn(dis
->hDC
, hrgn_org
);
3000 if (hrgn_org
) DeleteObject(hrgn_org
);
3001 } else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
) {
3002 int right
= img_pos
+ IMAGE_WIDTH
- TREE_LINE_DX
;
3004 if (right
> pane
->widths
[col
])
3005 pane
->widths
[col
] = right
;
3008 img_pos
= dis
->rcItem
.left
;
3011 img_pos
= dis
->rcItem
.left
;
3013 if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3014 pane
->widths
[col
] = IMAGE_WIDTH
;
3017 if (calcWidthCol
== -1) {
3018 focusRect
.left
= img_pos
-2;
3020 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
)
3021 textcolor
= COLOR_COMPRESSED
;
3023 textcolor
= RGB(0,0,0);
3025 if (dis
->itemState
& ODS_FOCUS
) {
3026 textcolor
= RGB(255,255,255);
3027 bkcolor
= COLOR_SELECTION
;
3029 bkcolor
= RGB(255,255,255);
3032 hbrush
= CreateSolidBrush(bkcolor
);
3033 FillRect(dis
->hDC
, &focusRect
, hbrush
);
3034 DeleteObject(hbrush
);
3036 SetBkMode(dis
->hDC
, TRANSPARENT
);
3037 SetTextColor(dis
->hDC
, textcolor
);
3039 cx
= pane
->widths
[col
];
3041 if (cx
&& img
!=IMG_NONE
) {
3042 if (cx
> IMAGE_WIDTH
)
3045 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
3046 DrawIconEx(dis
->hDC
, img_pos
, dis
->rcItem
.top
, entry
->hicon
, cx
, GetSystemMetrics(SM_CYSMICON
), 0, 0, DI_NORMAL
);
3048 ImageList_DrawEx(Globals
.himl
, img
, dis
->hDC
,
3049 img_pos
, dis
->rcItem
.top
, cx
,
3050 IMAGE_HEIGHT
, bkcolor
, CLR_DEFAULT
, ILD_NORMAL
);
3059 /* output file name */
3060 if (calcWidthCol
== -1)
3061 output_text(pane
, dis
, col
, entry
->data
.cFileName
, 0);
3062 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3063 calc_width(pane
, dis
, col
, entry
->data
.cFileName
);
3067 /* display file size */
3068 if (visible_cols
& COL_SIZE
) {
3069 format_longlong( buffer
, ((ULONGLONG
)entry
->data
.nFileSizeHigh
<< 32) | entry
->data
.nFileSizeLow
);
3071 if (calcWidthCol
== -1)
3072 output_number(pane
, dis
, col
, buffer
);
3073 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3074 calc_width(pane
, dis
, col
, buffer
);/*TODO: not ever time enough */
3079 /* display file date */
3080 if (visible_cols
& (COL_DATE
|COL_TIME
)) {
3081 format_date(&entry
->data
.ftCreationTime
, buffer
, visible_cols
);
3082 if (calcWidthCol
== -1)
3083 output_text(pane
, dis
, col
, buffer
, 0);
3084 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3085 calc_width(pane
, dis
, col
, buffer
);
3088 format_date(&entry
->data
.ftLastAccessTime
, buffer
, visible_cols
);
3089 if (calcWidthCol
== -1)
3090 output_text(pane
, dis
, col
, buffer
, 0);
3091 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3092 calc_width(pane
, dis
, col
, buffer
);
3095 format_date(&entry
->data
.ftLastWriteTime
, buffer
, visible_cols
);
3096 if (calcWidthCol
== -1)
3097 output_text(pane
, dis
, col
, buffer
, 0);
3098 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3099 calc_width(pane
, dis
, col
, buffer
);
3103 if (entry
->bhfi_valid
) {
3104 if (visible_cols
& COL_INDEX
) {
3105 static const WCHAR fmtlow
[] = {'%','X',0};
3106 static const WCHAR fmthigh
[] = {'%','X','%','0','8','X',0};
3108 if (entry
->bhfi
.nFileIndexHigh
)
3109 wsprintfW(buffer
, fmthigh
,
3110 entry
->bhfi
.nFileIndexHigh
, entry
->bhfi
.nFileIndexLow
);
3112 wsprintfW(buffer
, fmtlow
, entry
->bhfi
.nFileIndexLow
);
3114 if (calcWidthCol
== -1)
3115 output_text(pane
, dis
, col
, buffer
, DT_RIGHT
);
3116 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3117 calc_width(pane
, dis
, col
, buffer
);
3122 if (visible_cols
& COL_LINKS
) {
3123 wsprintfW(buffer
, sNumFmt
, entry
->bhfi
.nNumberOfLinks
);
3125 if (calcWidthCol
== -1)
3126 output_text(pane
, dis
, col
, buffer
, DT_CENTER
);
3127 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3128 calc_width(pane
, dis
, col
, buffer
);
3135 /* show file attributes */
3136 if (visible_cols
& COL_ATTRIBUTES
) {
3137 static const WCHAR s11Tabs
[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3138 lstrcpyW(buffer
, s11Tabs
);
3140 if (attrs
& FILE_ATTRIBUTE_NORMAL
) buffer
[ 0] = 'N';
3142 if (attrs
& FILE_ATTRIBUTE_READONLY
) buffer
[ 2] = 'R';
3143 if (attrs
& FILE_ATTRIBUTE_HIDDEN
) buffer
[ 4] = 'H';
3144 if (attrs
& FILE_ATTRIBUTE_SYSTEM
) buffer
[ 6] = 'S';
3145 if (attrs
& FILE_ATTRIBUTE_ARCHIVE
) buffer
[ 8] = 'A';
3146 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
) buffer
[10] = 'C';
3147 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) buffer
[12] = 'D';
3148 if (attrs
& FILE_ATTRIBUTE_ENCRYPTED
) buffer
[14] = 'E';
3149 if (attrs
& FILE_ATTRIBUTE_TEMPORARY
) buffer
[16] = 'T';
3150 if (attrs
& FILE_ATTRIBUTE_SPARSE_FILE
) buffer
[18] = 'P';
3151 if (attrs
& FILE_ATTRIBUTE_REPARSE_POINT
) buffer
[20] = 'Q';
3152 if (attrs
& FILE_ATTRIBUTE_OFFLINE
) buffer
[22] = 'O';
3153 if (attrs
& FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
) buffer
[24] = 'X';
3156 if (calcWidthCol
== -1)
3157 output_tabbed_text(pane
, dis
, col
, buffer
);
3158 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
3159 calc_tabbed_width(pane
, dis
, col
, buffer
);
3165 static void set_header(Pane
* pane
)
3168 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3171 item
.mask
= HDI_WIDTH
;
3174 for(; (i
< COLUMNS
) && (x
+pane
->widths
[i
] < scroll_pos
); i
++) {
3175 x
+= pane
->widths
[i
];
3176 SendMessageW(pane
->hwndHeader
, HDM_SETITEMW
, i
, (LPARAM
)&item
);
3180 x
+= pane
->widths
[i
];
3181 item
.cxy
= x
- scroll_pos
;
3182 SendMessageW(pane
->hwndHeader
, HDM_SETITEMW
, i
++, (LPARAM
)&item
);
3184 for(; i
< COLUMNS
; i
++) {
3185 item
.cxy
= pane
->widths
[i
];
3186 x
+= pane
->widths
[i
];
3187 SendMessageW(pane
->hwndHeader
, HDM_SETITEMW
, i
, (LPARAM
)&item
);
3192 static LRESULT
pane_notify(Pane
* pane
, NMHDR
* pnmh
)
3194 switch(pnmh
->code
) {
3195 case HDN_ITEMCHANGEDW
: {
3196 LPNMHEADERW phdn
= (LPNMHEADERW
)pnmh
;
3197 int idx
= phdn
->iItem
;
3198 int dx
= phdn
->pitem
->cxy
- pane
->widths
[idx
];
3202 GetClientRect(pane
->hwnd
, &clnt
);
3204 pane
->widths
[idx
] += dx
;
3206 for(i
=idx
; ++i
<=COLUMNS
; )
3207 pane
->positions
[i
] += dx
;
3210 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
3214 rt_scr
.left
= pane
->positions
[idx
+1]-scroll_pos
;
3216 rt_scr
.right
= clnt
.right
;
3217 rt_scr
.bottom
= clnt
.bottom
;
3219 rt_clip
.left
= pane
->positions
[idx
]-scroll_pos
;
3221 rt_clip
.right
= clnt
.right
;
3222 rt_clip
.bottom
= clnt
.bottom
;
3224 if (rt_scr
.left
< 0) rt_scr
.left
= 0;
3225 if (rt_clip
.left
< 0) rt_clip
.left
= 0;
3227 ScrollWindowEx(pane
->hwnd
, dx
, 0, &rt_scr
, &rt_clip
, 0, 0, SW_INVALIDATE
);
3229 rt_clip
.right
= pane
->positions
[idx
+1];
3230 RedrawWindow(pane
->hwnd
, &rt_clip
, 0, RDW_INVALIDATE
|RDW_UPDATENOW
);
3232 if (pnmh
->code
== HDN_ENDTRACKW
) {
3233 SendMessageW(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, pane
->positions
[COLUMNS
], 0);
3235 if (GetScrollPos(pane
->hwnd
, SB_HORZ
) != scroll_pos
)
3243 case HDN_DIVIDERDBLCLICKW
: {
3244 LPNMHEADERW phdn
= (LPNMHEADERW
)pnmh
;
3247 calc_single_width(pane
, phdn
->iItem
);
3248 item
.mask
= HDI_WIDTH
;
3249 item
.cxy
= pane
->widths
[phdn
->iItem
];
3251 SendMessageW(pane
->hwndHeader
, HDM_SETITEMW
, phdn
->iItem
, (LPARAM
)&item
);
3252 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3259 static void scan_entry(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3261 WCHAR path
[MAX_PATH
];
3262 HCURSOR old_cursor
= SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_WAIT
));
3264 /* delete sub entries in left pane */
3266 LRESULT res
= SendMessageW(child
->left
.hwnd
, LB_GETITEMDATA
, idx
+1, 0);
3267 Entry
* sub
= (Entry
*) res
;
3269 if (res
==LB_ERR
|| !sub
|| sub
->level
<=entry
->level
)
3272 SendMessageW(child
->left
.hwnd
, LB_DELETESTRING
, idx
+1, 0);
3275 /* empty right pane */
3276 SendMessageW(child
->right
.hwnd
, LB_RESETCONTENT
, 0, 0);
3278 /* release memory */
3279 free_entries(entry
);
3281 /* read contents from disk */
3282 if (entry
->etype
== ET_SHELL
)
3284 read_directory(entry
, NULL
, child
->sortOrder
, hwnd
);
3288 get_path(entry
, path
);
3289 read_directory(entry
, path
, child
->sortOrder
, hwnd
);
3292 /* insert found entries in right pane */
3293 insert_entries(&child
->right
, entry
->down
, child
->filter_pattern
, child
->filter_flags
, -1);
3294 calc_widths(&child
->right
, FALSE
);
3295 set_header(&child
->right
);
3297 child
->header_wdths_ok
= FALSE
;
3299 SetCursor(old_cursor
);
3303 /* expand a directory entry */
3305 static BOOL
expand_entry(ChildWnd
* child
, Entry
* dir
)
3310 if (!dir
|| dir
->expanded
|| !dir
->down
)
3315 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='\0' && p
->next
) {
3318 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='.' &&
3319 p
->data
.cFileName
[2]=='\0' && p
->next
)
3323 /* no subdirectories ? */
3324 if (!(p
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
3327 idx
= SendMessageW(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)dir
);
3329 dir
->expanded
= TRUE
;
3331 /* insert entries in left pane */
3332 insert_entries(&child
->left
, p
, NULL
, TF_ALL
, idx
);
3334 if (!child
->header_wdths_ok
) {
3335 if (calc_widths(&child
->left
, FALSE
)) {
3336 set_header(&child
->left
);
3338 child
->header_wdths_ok
= TRUE
;
3346 static void collapse_entry(Pane
* pane
, Entry
* dir
)
3351 idx
= SendMessageW(pane
->hwnd
, LB_FINDSTRING
, 0, (LPARAM
)dir
);
3353 ShowWindow(pane
->hwnd
, SW_HIDE
);
3355 /* hide sub entries */
3357 LRESULT res
= SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, idx
+1, 0);
3358 Entry
* sub
= (Entry
*) res
;
3360 if (res
==LB_ERR
|| !sub
|| sub
->level
<=dir
->level
)
3363 SendMessageW(pane
->hwnd
, LB_DELETESTRING
, idx
+1, 0);
3366 dir
->expanded
= FALSE
;
3368 ShowWindow(pane
->hwnd
, SW_SHOW
);
3372 static void refresh_right_pane(ChildWnd
* child
)
3374 SendMessageW(child
->right
.hwnd
, LB_RESETCONTENT
, 0, 0);
3375 insert_entries(&child
->right
, child
->right
.root
, child
->filter_pattern
, child
->filter_flags
, -1);
3376 calc_widths(&child
->right
, FALSE
);
3378 set_header(&child
->right
);
3381 static void set_curdir(ChildWnd
* child
, Entry
* entry
, int idx
, HWND hwnd
)
3383 WCHAR path
[MAX_PATH
];
3390 child
->left
.cur
= entry
;
3392 child
->right
.root
= entry
->down
? entry
->down
: entry
;
3393 child
->right
.cur
= entry
;
3395 if (!entry
->scanned
)
3396 scan_entry(child
, entry
, idx
, hwnd
);
3398 refresh_right_pane(child
);
3400 get_path(entry
, path
);
3401 lstrcpyW(child
->path
, path
);
3403 if (child
->hwnd
) /* only change window title, if the window already exists */
3404 SetWindowTextW(child
->hwnd
, path
);
3407 if (SetCurrentDirectoryW(path
))
3412 static void refresh_child(ChildWnd
* child
)
3414 WCHAR path
[MAX_PATH
], drv
[_MAX_DRIVE
+1];
3418 get_path(child
->left
.cur
, path
);
3419 _wsplitpath(path
, drv
, NULL
, NULL
, NULL
);
3421 child
->right
.root
= NULL
;
3423 scan_entry(child
, &child
->root
.entry
, 0, child
->hwnd
);
3425 if (child
->root
.entry
.etype
== ET_SHELL
)
3427 LPITEMIDLIST local_pidl
= get_path_pidl(path
,child
->hwnd
);
3429 entry
= read_tree(&child
->root
, NULL
, local_pidl
, drv
, child
->sortOrder
, child
->hwnd
);
3434 entry
= read_tree(&child
->root
, path
, NULL
, drv
, child
->sortOrder
, child
->hwnd
);
3437 entry
= &child
->root
.entry
;
3439 insert_entries(&child
->left
, child
->root
.entry
.down
, NULL
, TF_ALL
, 0);
3441 set_curdir(child
, entry
, 0, child
->hwnd
);
3443 idx
= SendMessageW(child
->left
.hwnd
, LB_FINDSTRING
, 0, (LPARAM
)child
->left
.cur
);
3444 SendMessageW(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
3448 static void create_drive_bar(void)
3450 TBBUTTON drivebarBtn
= {0, 0, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0};
3451 WCHAR b1
[BUFFER_LEN
];
3455 GetLogicalDriveStringsW(BUFFER_LEN
, Globals
.drives
);
3457 Globals
.hdrivebar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
,
3458 IDW_DRIVEBAR
, 2, Globals
.hInstance
, IDB_DRIVEBAR
, &drivebarBtn
,
3459 0, 16, 13, 16, 13, sizeof(TBBUTTON
));
3462 /* insert unix file system button */
3466 SendMessageW(Globals
.hdrivebar
, TB_ADDSTRINGW
, 0, (LPARAM
)b1
);
3468 drivebarBtn
.idCommand
= ID_DRIVE_UNIX_FS
;
3469 SendMessageW(Globals
.hdrivebar
, TB_INSERTBUTTONW
, btn
++, (LPARAM
)&drivebarBtn
);
3470 drivebarBtn
.iString
++;
3472 /* insert shell namespace button */
3473 load_string(b1
, sizeof(b1
)/sizeof(b1
[0]), IDS_SHELL
);
3474 b1
[lstrlenW(b1
)+1] = '\0';
3475 SendMessageW(Globals
.hdrivebar
, TB_ADDSTRINGW
, 0, (LPARAM
)b1
);
3477 drivebarBtn
.idCommand
= ID_DRIVE_SHELL_NS
;
3478 SendMessageW(Globals
.hdrivebar
, TB_INSERTBUTTONW
, btn
++, (LPARAM
)&drivebarBtn
);
3479 drivebarBtn
.iString
++;
3481 /* register windows drive root strings */
3482 SendMessageW(Globals
.hdrivebar
, TB_ADDSTRINGW
, 0, (LPARAM
)Globals
.drives
);
3484 drivebarBtn
.idCommand
= ID_DRIVE_FIRST
;
3486 for(p
=Globals
.drives
; *p
; ) {
3487 switch(GetDriveTypeW(p
)) {
3488 case DRIVE_REMOVABLE
: drivebarBtn
.iBitmap
= 1; break;
3489 case DRIVE_CDROM
: drivebarBtn
.iBitmap
= 3; break;
3490 case DRIVE_REMOTE
: drivebarBtn
.iBitmap
= 4; break;
3491 case DRIVE_RAMDISK
: drivebarBtn
.iBitmap
= 5; break;
3492 default:/*DRIVE_FIXED*/ drivebarBtn
.iBitmap
= 2;
3495 SendMessageW(Globals
.hdrivebar
, TB_INSERTBUTTONW
, btn
++, (LPARAM
)&drivebarBtn
);
3496 drivebarBtn
.idCommand
++;
3497 drivebarBtn
.iString
++;
3503 static void refresh_drives(void)
3507 /* destroy drive bar */
3508 DestroyWindow(Globals
.hdrivebar
);
3509 Globals
.hdrivebar
= 0;
3511 /* re-create drive bar */
3514 /* update window layout */
3515 GetClientRect(Globals
.hMainWnd
, &rect
);
3516 SendMessageW(Globals
.hMainWnd
, WM_SIZE
, 0, MAKELONG(rect
.right
, rect
.bottom
));
3520 static BOOL
launch_file(HWND hwnd
, LPCWSTR cmd
, UINT nCmdShow
)
3522 HINSTANCE hinst
= ShellExecuteW(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3524 if (PtrToUlong(hinst
) <= 32) {
3525 display_error(hwnd
, GetLastError());
3533 static BOOL
launch_entry(Entry
* entry
, HWND hwnd
, UINT nCmdShow
)
3535 WCHAR cmd
[MAX_PATH
];
3537 if (entry
->etype
== ET_SHELL
) {
3540 SHELLEXECUTEINFOW shexinfo
;
3542 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFOW
);
3543 shexinfo
.fMask
= SEE_MASK_IDLIST
;
3544 shexinfo
.hwnd
= hwnd
;
3545 shexinfo
.lpVerb
= NULL
;
3546 shexinfo
.lpFile
= NULL
;
3547 shexinfo
.lpParameters
= NULL
;
3548 shexinfo
.lpDirectory
= NULL
;
3549 shexinfo
.nShow
= nCmdShow
;
3550 shexinfo
.lpIDList
= get_to_absolute_pidl(entry
, hwnd
);
3552 if (!ShellExecuteExW(&shexinfo
)) {
3553 display_error(hwnd
, GetLastError());
3557 if (shexinfo
.lpIDList
!= entry
->pidl
)
3558 IMalloc_Free(Globals
.iMalloc
, shexinfo
.lpIDList
);
3563 get_path(entry
, cmd
);
3565 /* start program, open document... */
3566 return launch_file(hwnd
, cmd
, nCmdShow
);
3570 static void activate_entry(ChildWnd
* child
, Pane
* pane
, HWND hwnd
)
3572 Entry
* entry
= pane
->cur
;
3577 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
3578 int scanned_old
= entry
->scanned
;
3582 int idx
= SendMessageW(child
->left
.hwnd
, LB_GETCURSEL
, 0, 0);
3583 scan_entry(child
, entry
, idx
, hwnd
);
3586 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='\0')
3589 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='.' && entry
->data
.cFileName
[2]=='\0') {
3590 entry
= child
->left
.cur
->up
;
3591 collapse_entry(&child
->left
, entry
);
3593 } else if (entry
->expanded
)
3594 collapse_entry(pane
, child
->left
.cur
);
3596 expand_entry(child
, child
->left
.cur
);
3598 if (!pane
->treePane
) focus_entry
: {
3599 int idxstart
= SendMessageW(child
->left
.hwnd
, LB_GETCURSEL
, 0, 0);
3600 int idx
= SendMessageW(child
->left
.hwnd
, LB_FINDSTRING
, idxstart
, (LPARAM
)entry
);
3601 SendMessageW(child
->left
.hwnd
, LB_SETCURSEL
, idx
, 0);
3602 set_curdir(child
, entry
, idx
, hwnd
);
3607 calc_widths(pane
, FALSE
);
3612 if (GetKeyState(VK_MENU
) < 0)
3613 show_properties_dlg(entry
, child
->hwnd
);
3615 launch_entry(entry
, child
->hwnd
, SW_SHOWNORMAL
);
3620 static BOOL
pane_command(Pane
* pane
, UINT cmd
)
3624 if (pane
->visible_cols
) {
3625 pane
->visible_cols
= 0;
3626 calc_widths(pane
, TRUE
);
3628 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3629 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
|MF_CHECKED
);
3630 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
);
3634 case ID_VIEW_ALL_ATTRIBUTES
:
3635 if (pane
->visible_cols
!= COL_ALL
) {
3636 pane
->visible_cols
= COL_ALL
;
3637 calc_widths(pane
, TRUE
);
3639 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3640 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
);
3641 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
|MF_CHECKED
);
3645 case ID_PREFERRED_SIZES
: {
3646 calc_widths(pane
, TRUE
);
3648 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3651 /* TODO: more command ids... */
3661 static void set_sort_order(ChildWnd
* child
, SORT_ORDER sortOrder
)
3663 if (child
->sortOrder
!= sortOrder
) {
3664 child
->sortOrder
= sortOrder
;
3665 refresh_child(child
);
3669 static void update_view_menu(ChildWnd
* child
)
3671 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_NAME
, child
->sortOrder
==SORT_NAME
? MF_CHECKED
: MF_UNCHECKED
);
3672 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_TYPE
, child
->sortOrder
==SORT_EXT
? MF_CHECKED
: MF_UNCHECKED
);
3673 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_SIZE
, child
->sortOrder
==SORT_SIZE
? MF_CHECKED
: MF_UNCHECKED
);
3674 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SORT_DATE
, child
->sortOrder
==SORT_DATE
? MF_CHECKED
: MF_UNCHECKED
);
3678 static BOOL
is_directory(LPCWSTR target
)
3680 /*TODO correctly handle UNIX paths */
3681 DWORD target_attr
= GetFileAttributesW(target
);
3683 if (target_attr
== INVALID_FILE_ATTRIBUTES
)
3686 return (target_attr
& FILE_ATTRIBUTE_DIRECTORY
) != 0;
3689 static BOOL
prompt_target(Pane
* pane
, LPWSTR source
, LPWSTR target
)
3691 WCHAR path
[MAX_PATH
];
3694 get_path(pane
->cur
, path
);
3696 if (DialogBoxParamW(Globals
.hInstance
, MAKEINTRESOURCEW(IDD_SELECT_DESTINATION
), pane
->hwnd
, DestinationDlgProc
, (LPARAM
)path
) != IDOK
)
3699 get_path(pane
->cur
, source
);
3701 /* convert relative targets to absolute paths */
3702 if (path
[0]!='/' && path
[1]!=':') {
3703 get_path(pane
->cur
->up
, target
);
3704 len
= lstrlenW(target
);
3706 if (target
[len
-1]!='\\' && target
[len
-1]!='/')
3707 target
[len
++] = '/';
3709 lstrcpyW(target
+len
, path
);
3711 lstrcpyW(target
, path
);
3713 /* If the target already exists as directory, create a new target below this. */
3714 if (is_directory(path
)) {
3715 WCHAR fname
[_MAX_FNAME
], ext
[_MAX_EXT
];
3716 static const WCHAR sAppend
[] = {'%','s','/','%','s','%','s','\0'};
3718 _wsplitpath(source
, NULL
, NULL
, fname
, ext
);
3720 wsprintfW(target
, sAppend
, path
, fname
, ext
);
3727 static IContextMenu2
* s_pctxmenu2
= NULL
;
3728 static IContextMenu3
* s_pctxmenu3
= NULL
;
3730 static void CtxMenu_reset(void)
3736 static IContextMenu
* CtxMenu_query_interfaces(IContextMenu
* pcm1
)
3738 IContextMenu
* pcm
= NULL
;
3742 if (IContextMenu_QueryInterface(pcm1
, &IID_IContextMenu3
, (void**)&pcm
) == NOERROR
)
3743 s_pctxmenu3
= (LPCONTEXTMENU3
)pcm
;
3744 else if (IContextMenu_QueryInterface(pcm1
, &IID_IContextMenu2
, (void**)&pcm
) == NOERROR
)
3745 s_pctxmenu2
= (LPCONTEXTMENU2
)pcm
;
3748 IContextMenu_Release(pcm1
);
3754 static BOOL
CtxMenu_HandleMenuMsg(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3757 if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3
, nmsg
, wparam
, lparam
)))
3762 if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2
, nmsg
, wparam
, lparam
)))
3768 static HRESULT
ShellFolderContextMenu(IShellFolder
* shell_folder
, HWND hwndParent
, int cidl
, LPCITEMIDLIST
* apidl
, int x
, int y
)
3771 BOOL executed
= FALSE
;
3773 HRESULT hr
= IShellFolder_GetUIObjectOf(shell_folder
, hwndParent
, cidl
, apidl
, &IID_IContextMenu
, NULL
, (LPVOID
*)&pcm
);
3775 if (SUCCEEDED(hr
)) {
3776 HMENU hmenu
= CreatePopupMenu();
3778 pcm
= CtxMenu_query_interfaces(pcm
);
3781 hr
= IContextMenu_QueryContextMenu(pcm
, hmenu
, 0, FCIDM_SHVIEWFIRST
, FCIDM_SHVIEWLAST
, CMF_NORMAL
);
3783 if (SUCCEEDED(hr
)) {
3784 UINT idCmd
= TrackPopupMenu(hmenu
, TPM_LEFTALIGN
|TPM_RETURNCMD
|TPM_RIGHTBUTTON
, x
, y
, 0, hwndParent
, NULL
);
3789 CMINVOKECOMMANDINFO cmi
;
3791 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFO
);
3793 cmi
.hwnd
= hwndParent
;
3794 cmi
.lpVerb
= (LPCSTR
)(INT_PTR
)(idCmd
- FCIDM_SHVIEWFIRST
);
3795 cmi
.lpParameters
= NULL
;
3796 cmi
.lpDirectory
= NULL
;
3797 cmi
.nShow
= SW_SHOWNORMAL
;
3801 hr
= IContextMenu_InvokeCommand(pcm
, &cmi
);
3808 IContextMenu_Release(pcm
);
3811 return FAILED(hr
)? hr
: executed
? S_OK
: S_FALSE
;
3814 static LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3816 ChildWnd
* child
= (ChildWnd
*)GetWindowLongPtrW(hwnd
, GWLP_USERDATA
);
3821 LPDRAWITEMSTRUCT dis
= (LPDRAWITEMSTRUCT
)lparam
;
3822 Entry
* entry
= (Entry
*) dis
->itemData
;
3824 if (dis
->CtlID
== IDW_TREE_LEFT
)
3825 draw_item(&child
->left
, dis
, entry
, -1);
3826 else if (dis
->CtlID
== IDW_TREE_RIGHT
)
3827 draw_item(&child
->right
, dis
, entry
, -1);
3829 goto draw_menu_item
;
3834 InitChildWindow(child
);
3838 free_child_window(child
);
3839 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, 0);
3846 GetClientRect(hwnd
, &rt
);
3847 BeginPaint(hwnd
, &ps
);
3848 rt
.left
= child
->split_pos
-SPLIT_WIDTH
/2;
3849 rt
.right
= child
->split_pos
+SPLIT_WIDTH
/2+1;
3850 lastBrush
= SelectObject(ps
.hdc
, GetStockObject(COLOR_SPLITBAR
));
3851 Rectangle(ps
.hdc
, rt
.left
, rt
.top
-1, rt
.right
, rt
.bottom
+1);
3852 SelectObject(ps
.hdc
, lastBrush
);
3853 EndPaint(hwnd
, &ps
);
3857 if (LOWORD(lparam
) == HTCLIENT
) {
3860 ScreenToClient(hwnd
, &pt
);
3862 if (pt
.x
>=child
->split_pos
-SPLIT_WIDTH
/2 && pt
.x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
3863 SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_SIZEWE
));
3869 case WM_LBUTTONDOWN
: {
3871 int x
= (short)LOWORD(lparam
);
3873 GetClientRect(hwnd
, &rt
);
3875 if (x
>=child
->split_pos
-SPLIT_WIDTH
/2 && x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
3876 last_split
= child
->split_pos
;
3883 if (GetCapture() == hwnd
)
3888 if (wparam
== VK_ESCAPE
)
3889 if (GetCapture() == hwnd
) {
3891 child
->split_pos
= last_split
;
3892 GetClientRect(hwnd
, &rt
);
3893 resize_tree(child
, rt
.right
, rt
.bottom
);
3896 SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_ARROW
));
3901 if (GetCapture() == hwnd
) {
3903 int x
= (short)LOWORD(lparam
);
3905 GetClientRect(hwnd
, &rt
);
3907 if (x
>=0 && x
<rt
.right
) {
3908 child
->split_pos
= x
;
3909 resize_tree(child
, rt
.right
, rt
.bottom
);
3910 rt
.left
= x
-SPLIT_WIDTH
/2;
3911 rt
.right
= x
+SPLIT_WIDTH
/2+1;
3912 InvalidateRect(hwnd
, &rt
, FALSE
);
3913 UpdateWindow(child
->left
.hwnd
);
3915 UpdateWindow(child
->right
.hwnd
);
3920 case WM_GETMINMAXINFO
:
3921 DefMDIChildProcW(hwnd
, nmsg
, wparam
, lparam
);
3923 {LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
3925 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
3926 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
3930 if (SetCurrentDirectoryW(child
->path
))
3932 SetFocus(child
->focus_pane
? child
->right
.hwnd
: child
->left
.hwnd
);
3935 case WM_DISPATCH_COMMAND
: {
3936 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
3938 switch(LOWORD(wparam
)) {
3939 case ID_WINDOW_NEW
: {
3940 ChildWnd
* new_child
= alloc_child_window(child
->path
, NULL
, hwnd
);
3942 if (!create_child_window(new_child
))
3943 HeapFree(GetProcessHeap(), 0, new_child
);
3949 refresh_child(child
);
3953 activate_entry(child
, pane
, hwnd
);
3956 case ID_FILE_MOVE
: {
3957 WCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
3959 if (prompt_target(pane
, source
, target
)) {
3960 SHFILEOPSTRUCTW shfo
= {hwnd
, FO_MOVE
, source
, target
};
3962 source
[lstrlenW(source
)+1] = '\0';
3963 target
[lstrlenW(target
)+1] = '\0';
3965 if (!SHFileOperationW(&shfo
))
3966 refresh_child(child
);
3970 case ID_FILE_COPY
: {
3971 WCHAR source
[BUFFER_LEN
], target
[BUFFER_LEN
];
3973 if (prompt_target(pane
, source
, target
)) {
3974 SHFILEOPSTRUCTW shfo
= {hwnd
, FO_COPY
, source
, target
};
3976 source
[lstrlenW(source
)+1] = '\0';
3977 target
[lstrlenW(target
)+1] = '\0';
3979 if (!SHFileOperationW(&shfo
))
3980 refresh_child(child
);
3984 case ID_FILE_DELETE
: {
3985 WCHAR path
[BUFFER_LEN
];
3986 SHFILEOPSTRUCTW shfo
= {hwnd
, FO_DELETE
, path
, NULL
, FOF_ALLOWUNDO
};
3988 get_path(pane
->cur
, path
);
3990 path
[lstrlenW(path
)+1] = '\0';
3992 if (!SHFileOperationW(&shfo
))
3993 refresh_child(child
);
3996 case ID_VIEW_SORT_NAME
:
3997 set_sort_order(child
, SORT_NAME
);
4000 case ID_VIEW_SORT_TYPE
:
4001 set_sort_order(child
, SORT_EXT
);
4004 case ID_VIEW_SORT_SIZE
:
4005 set_sort_order(child
, SORT_SIZE
);
4008 case ID_VIEW_SORT_DATE
:
4009 set_sort_order(child
, SORT_DATE
);
4012 case ID_VIEW_FILTER
: {
4013 struct FilterDialog dlg
;
4015 memset(&dlg
, 0, sizeof(struct FilterDialog
));
4016 lstrcpyW(dlg
.pattern
, child
->filter_pattern
);
4017 dlg
.flags
= child
->filter_flags
;
4019 if (DialogBoxParamW(Globals
.hInstance
, MAKEINTRESOURCEW(IDD_DIALOG_VIEW_TYPE
), hwnd
, FilterDialogDlgProc
, (LPARAM
)&dlg
) == IDOK
) {
4020 lstrcpyW(child
->filter_pattern
, dlg
.pattern
);
4021 child
->filter_flags
= dlg
.flags
;
4022 refresh_right_pane(child
);
4026 case ID_VIEW_SPLIT
: {
4027 last_split
= child
->split_pos
;
4031 case ID_EDIT_PROPERTIES
:
4032 show_properties_dlg(pane
->cur
, child
->hwnd
);
4036 return pane_command(pane
, LOWORD(wparam
));
4042 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4044 switch(HIWORD(wparam
)) {
4045 case LBN_SELCHANGE
: {
4046 int idx
= SendMessageW(pane
->hwnd
, LB_GETCURSEL
, 0, 0);
4047 Entry
* entry
= (Entry
*)SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, idx
, 0);
4049 if (pane
== &child
->left
)
4050 set_curdir(child
, entry
, idx
, hwnd
);
4056 activate_entry(child
, pane
, hwnd
);
4062 NMHDR
* pnmh
= (NMHDR
*) lparam
;
4063 return pane_notify(pnmh
->idFrom
==IDW_HEADER_LEFT
? &child
->left
: &child
->right
, pnmh
);}
4065 case WM_CONTEXTMENU
: {
4070 /* first select the current item in the listbox */
4071 HWND hpanel
= (HWND
) wparam
;
4072 pt_clnt
.x
= pt
.x
= (short)LOWORD(lparam
);
4073 pt_clnt
.y
= pt
.y
= (short)HIWORD(lparam
);
4074 ScreenToClient(hpanel
, &pt_clnt
);
4075 SendMessageW(hpanel
, WM_LBUTTONDOWN
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4076 SendMessageW(hpanel
, WM_LBUTTONUP
, 0, MAKELONG(pt_clnt
.x
, pt_clnt
.y
));
4078 /* now create the popup menu using shell namespace and IContextMenu */
4079 pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
4080 idx
= SendMessageW(pane
->hwnd
, LB_GETCURSEL
, 0, 0);
4083 Entry
* entry
= (Entry
*)SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, idx
, 0);
4085 LPITEMIDLIST pidl_abs
= get_to_absolute_pidl(entry
, hwnd
);
4088 IShellFolder
* parentFolder
;
4089 LPCITEMIDLIST pidlLast
;
4091 /* get and use the parent folder to display correct context menu in all cases */
4092 if (SUCCEEDED(SHBindToParent(pidl_abs
, &IID_IShellFolder
, (LPVOID
*)&parentFolder
, &pidlLast
))) {
4093 if (ShellFolderContextMenu(parentFolder
, hwnd
, 1, &pidlLast
, pt
.x
, pt
.y
) == S_OK
)
4094 refresh_child(child
);
4096 IShellFolder_Release(parentFolder
);
4099 IMalloc_Free(Globals
.iMalloc
, pidl_abs
);
4104 case WM_MEASUREITEM
:
4106 if (!wparam
) /* Is the message menu-related? */
4107 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4112 case WM_INITMENUPOPUP
:
4113 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
4116 update_view_menu(child
);
4119 case WM_MENUCHAR
: /* only supported by IContextMenu3 */
4121 LRESULT lResult
= 0;
4123 IContextMenu3_HandleMenuMsg2(s_pctxmenu3
, nmsg
, wparam
, lparam
, &lResult
);
4131 if (wparam
!= SIZE_MINIMIZED
)
4132 resize_tree(child
, LOWORD(lparam
), HIWORD(lparam
));
4136 return DefMDIChildProcW(hwnd
, nmsg
, wparam
, lparam
);
4143 static LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
4145 ChildWnd
* child
= (ChildWnd
*)GetWindowLongPtrW(GetParent(hwnd
), GWLP_USERDATA
);
4146 Pane
* pane
= (Pane
*)GetWindowLongPtrW(hwnd
, GWLP_USERDATA
);
4155 child
->focus_pane
= pane
==&child
->right
? 1: 0;
4156 SendMessageW(hwnd
, LB_SETSEL
, TRUE
, 1);
4157 /*TODO: check menu items */
4161 if (wparam
== VK_TAB
) {
4162 /*TODO: SetFocus(Globals.hdrivebar) */
4163 SetFocus(child
->focus_pane
? child
->left
.hwnd
: child
->right
.hwnd
);
4167 return CallWindowProcW(g_orgTreeWndProc
, hwnd
, nmsg
, wparam
, lparam
);
4171 static void InitInstance(HINSTANCE hinstance
)
4173 static const WCHAR sFont
[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4175 WNDCLASSEXW wcFrame
;
4179 INITCOMMONCONTROLSEX icc
= {
4180 sizeof(INITCOMMONCONTROLSEX
),
4186 setlocale(LC_COLLATE
, ""); /* set collating rules to local settings for compareName */
4188 InitCommonControlsEx(&icc
);
4191 /* register frame window class */
4193 wcFrame
.cbSize
= sizeof(WNDCLASSEXW
);
4195 wcFrame
.lpfnWndProc
= FrameWndProc
;
4196 wcFrame
.cbClsExtra
= 0;
4197 wcFrame
.cbWndExtra
= 0;
4198 wcFrame
.hInstance
= hinstance
;
4199 wcFrame
.hIcon
= LoadIconW(hinstance
, MAKEINTRESOURCEW(IDI_WINEFILE
));
4200 wcFrame
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
4201 wcFrame
.hbrBackground
= 0;
4202 wcFrame
.lpszMenuName
= 0;
4203 wcFrame
.lpszClassName
= sWINEFILEFRAME
;
4204 wcFrame
.hIconSm
= LoadImageW(hinstance
, MAKEINTRESOURCEW(IDI_WINEFILE
), IMAGE_ICON
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
4206 Globals
.hframeClass
= RegisterClassExW(&wcFrame
);
4209 /* register tree windows class */
4211 wcChild
.style
= CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
;
4212 wcChild
.lpfnWndProc
= ChildWndProc
;
4213 wcChild
.cbClsExtra
= 0;
4214 wcChild
.cbWndExtra
= 0;
4215 wcChild
.hInstance
= hinstance
;
4217 wcChild
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
4218 wcChild
.hbrBackground
= 0;
4219 wcChild
.lpszMenuName
= 0;
4220 wcChild
.lpszClassName
= sWINEFILETREE
;
4222 RegisterClassW(&wcChild
);
4225 Globals
.haccel
= LoadAcceleratorsW(hinstance
, MAKEINTRESOURCEW(IDA_WINEFILE
));
4227 Globals
.hfont
= CreateFontW(-MulDiv(8,GetDeviceCaps(hdc
,LOGPIXELSY
),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont
);
4231 Globals
.hInstance
= hinstance
;
4234 CoGetMalloc(MEMCTX_TASK
, &Globals
.iMalloc
);
4235 SHGetDesktopFolder(&Globals
.iDesktop
);
4236 Globals
.cfStrFName
= RegisterClipboardFormatW(CFSTR_FILENAMEW
);
4238 /* load column strings */
4241 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_NAME
);
4242 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_SIZE
);
4243 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_CDATE
);
4244 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_ADATE
);
4245 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_MDATE
);
4246 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_IDX
);
4247 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_LINKS
);
4248 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_ATTR
);
4249 load_string(g_pos_names
[col
++], sizeof(g_pos_names
[col
])/sizeof(g_pos_names
[col
][0]), IDS_COL_SEC
);
4253 static BOOL
show_frame(HWND hwndParent
, int cmdshow
, LPCWSTR path
)
4255 static const WCHAR sMDICLIENT
[] = {'M','D','I','C','L','I','E','N','T','\0'};
4257 WCHAR buffer
[MAX_PATH
], b1
[BUFFER_LEN
];
4259 HMENU hMenuFrame
, hMenuWindow
;
4262 CLIENTCREATESTRUCT ccs
;
4264 if (Globals
.hMainWnd
)
4267 opts
= load_registry_settings();
4268 hMenuFrame
= LoadMenuW(Globals
.hInstance
, MAKEINTRESOURCEW(IDM_WINEFILE
));
4269 hMenuWindow
= GetSubMenu(hMenuFrame
, GetMenuItemCount(hMenuFrame
)-2);
4271 Globals
.hMenuFrame
= hMenuFrame
;
4272 Globals
.hMenuView
= GetSubMenu(hMenuFrame
, 2);
4273 Globals
.hMenuOptions
= GetSubMenu(hMenuFrame
, 3);
4275 ccs
.hWindowMenu
= hMenuWindow
;
4276 ccs
.idFirstChild
= IDW_FIRST_CHILD
;
4279 /* create main window */
4280 Globals
.hMainWnd
= CreateWindowExW(0, MAKEINTRESOURCEW(Globals
.hframeClass
), RS(b1
,IDS_WINEFILE
), WS_OVERLAPPEDWINDOW
,
4281 opts
.start_x
, opts
.start_y
, opts
.width
, opts
.height
,
4282 hwndParent
, Globals
.hMenuFrame
, Globals
.hInstance
, 0/*lpParam*/);
4285 Globals
.hmdiclient
= CreateWindowExW(0, sMDICLIENT
, NULL
,
4286 WS_CHILD
|WS_CLIPCHILDREN
|WS_VSCROLL
|WS_HSCROLL
|WS_VISIBLE
|WS_BORDER
,
4288 Globals
.hMainWnd
, 0, Globals
.hInstance
, &ccs
);
4290 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_DRIVE_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4291 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_SAVESETTINGS
, MF_BYCOMMAND
);
4296 TBBUTTON toolbarBtns
[] = {
4297 {0, 0, 0, BTNS_SEP
, {0, 0}, 0, 0},
4298 {0, ID_WINDOW_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4299 {1, ID_WINDOW_CASCADE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4300 {2, ID_WINDOW_TILE_HORZ
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4301 {3, ID_WINDOW_TILE_VERT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
4304 Globals
.htoolbar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
,
4305 IDW_TOOLBAR
, 2, Globals
.hInstance
, IDB_TOOLBAR
, toolbarBtns
,
4306 sizeof(toolbarBtns
)/sizeof(TBBUTTON
), 16, 15, 16, 15, sizeof(TBBUTTON
));
4307 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_TOOL_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
4310 Globals
.hstatusbar
= CreateStatusWindowW(WS_CHILD
|WS_VISIBLE
, 0, Globals
.hMainWnd
, IDW_STATUSBAR
);
4311 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
4313 /*TODO: read paths from registry */
4315 if (!path
|| !*path
) {
4316 GetCurrentDirectoryW(MAX_PATH
, buffer
);
4320 ShowWindow(Globals
.hMainWnd
, cmdshow
);
4323 /* Shell Namespace as default: */
4324 child
= alloc_child_window(path
, get_path_pidl(path
,Globals
.hMainWnd
), Globals
.hMainWnd
);
4326 child
= alloc_child_window(path
, NULL
, Globals
.hMainWnd
);
4329 child
->pos
.showCmd
= SW_SHOWMAXIMIZED
;
4330 child
->pos
.rcNormalPosition
.left
= 0;
4331 child
->pos
.rcNormalPosition
.top
= 0;
4332 child
->pos
.rcNormalPosition
.right
= 320;
4333 child
->pos
.rcNormalPosition
.bottom
= 280;
4335 if (!create_child_window(child
)) {
4336 HeapFree(GetProcessHeap(), 0, child
);
4340 SetWindowPlacement(child
->hwnd
, &child
->pos
);
4342 Globals
.himl
= ImageList_LoadImageW(Globals
.hInstance
, MAKEINTRESOURCEW(IDB_IMAGES
), 16, 0, RGB(0,255,0), IMAGE_BITMAP
, 0);
4344 Globals
.prescan_node
= FALSE
;
4346 UpdateWindow(Globals
.hMainWnd
);
4348 if (child
->hwnd
&& path
&& path
[0])
4351 WCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
4352 WCHAR fullname
[_MAX_FNAME
+_MAX_EXT
+1];
4354 memset(name
,0,sizeof(name
));
4355 memset(name
,0,sizeof(ext
));
4356 _wsplitpath(path
, drv
, dir
, name
, ext
);
4359 count
= SendMessageW(child
->right
.hwnd
, LB_GETCOUNT
, 0, 0);
4360 lstrcpyW(fullname
,name
);
4361 lstrcatW(fullname
,ext
);
4363 for (index
= 0; index
< count
; index
++)
4365 Entry
* entry
= (Entry
*)SendMessageW(child
->right
.hwnd
, LB_GETITEMDATA
, index
, 0);
4366 if (lstrcmpW(entry
->data
.cFileName
,fullname
)==0 ||
4367 lstrcmpW(entry
->data
.cAlternateFileName
,fullname
)==0)
4369 SendMessageW(child
->right
.hwnd
, LB_SETCURSEL
, index
, 0);
4370 SetFocus(child
->right
.hwnd
);
4379 static void ExitInstance(void)
4381 IShellFolder_Release(Globals
.iDesktop
);
4382 IMalloc_Release(Globals
.iMalloc
);
4385 DeleteObject(Globals
.hfont
);
4386 ImageList_Destroy(Globals
.himl
);
4389 int APIENTRY
wWinMain(HINSTANCE hinstance
, HINSTANCE previnstance
, LPWSTR cmdline
, int cmdshow
)
4393 InitInstance(hinstance
);
4395 if( !show_frame(0, cmdshow
, cmdline
) )
4401 while(GetMessageW(&msg
, 0, 0, 0)) {
4402 if (Globals
.hmdiclient
&& TranslateMDISysAccel(Globals
.hmdiclient
, &msg
))
4405 if (Globals
.hMainWnd
&& TranslateAcceleratorW(Globals
.hMainWnd
, Globals
.haccel
, &msg
))
4408 TranslateMessage(&msg
);
4409 DispatchMessageW(&msg
);