4 * Copyright 2000, 2003, 2004 Martin Fuchs
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
28 #define NONAMELESSUNION
32 /* for read_directory_unix() */
33 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
48 #define _MAX_FNAME 256
49 #define _MAX_DIR _MAX_FNAME
50 #define _MAX_EXT _MAX_FNAME
54 #ifdef NONAMELESSUNION
55 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
57 #define UNION_MEMBER(x) x
62 #define DEFAULT_SPLIT_POS 300
64 #define DEFAULT_SPLIT_POS 200
68 WINEFILE_GLOBALS Globals
;
70 extern void WineLicense(HWND hwnd
);
71 extern void WineWarranty(HWND hwnd
);
81 typedef struct _Entry
{
92 #ifndef _NO_EXTENSIONS
93 BY_HANDLE_FILE_INFORMATION bhfi
;
95 enum ENTRY_TYPE etype
;
106 TCHAR path
[MAX_PATH
];
107 TCHAR volname
[_MAX_FNAME
];
117 COL_ATTRIBUTES
= 0x08,
119 #ifdef _NO_EXTENSIONS
120 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
124 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
|COL_INDEX
|COL_LINKS
137 #ifndef _NO_EXTENSIONS
141 #ifndef _NO_EXTENSIONS
147 int positions
[COLUMNS
+1];
159 int focus_pane
; /* 0: left 1: right */
162 BOOL header_wdths_ok
;
164 TCHAR path
[MAX_PATH
];
167 SORT_ORDER sortOrder
;
171 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
);
172 static void set_curdir(ChildWnd
* child
, Entry
* entry
, HWND hwnd
);
173 static void get_path(Entry
* dir
, PTSTR path
);
175 LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
176 LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
177 LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
180 /* load resource string */
181 static LPTSTR
load_string(LPTSTR buffer
, UINT id
)
183 LoadString(Globals
.hInstance
, id
, buffer
, BUFFER_LEN
);
188 #define RS(b, i) load_string(b, i)
191 /* display error message for the specified WIN32 error code */
192 static void display_error(HWND hwnd
, DWORD error
)
194 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
197 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_FROM_SYSTEM
,
198 0, error
, MAKELANGID(LANG_NEUTRAL
,SUBLANG_DEFAULT
), (PTSTR
)&msg
, 0, NULL
))
199 MessageBox(hwnd
, msg
, RS(b2
,IDS_WINEFILE
), MB_OK
);
201 MessageBox(hwnd
, RS(b1
,IDS_ERROR
), RS(b2
,IDS_WINEFILE
), MB_OK
);
206 /* allocate and initialise a directory entry */
207 static Entry
* alloc_entry()
209 Entry
* entry
= (Entry
*) malloc(sizeof(Entry
));
211 #ifdef _SHELL_FOLDERS
213 entry
->folder
= NULL
;
220 /* free a directory entry */
221 static void free_entry(Entry
* entry
)
223 #ifdef _SHELL_FOLDERS
224 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
225 DestroyIcon(entry
->hicon
);
227 if (entry
->folder
&& entry
->folder
!=Globals
.iDesktop
)
228 (*entry
->folder
->lpVtbl
->Release
)(entry
->folder
);
231 (*Globals
.iMalloc
->lpVtbl
->Free
)(Globals
.iMalloc
, entry
->pidl
);
237 /* recursively free all child entries */
238 static void free_entries(Entry
* dir
)
240 Entry
*entry
, *next
=dir
->down
;
256 static void read_directory_win(Entry
* dir
, LPCTSTR path
)
258 Entry
* first_entry
= NULL
;
262 int level
= dir
->level
+ 1;
263 WIN32_FIND_DATA w32fd
;
265 #ifndef _NO_EXTENSIONS
269 TCHAR buffer
[MAX_PATH
], *p
;
270 for(p
=buffer
; *path
; )
273 lstrcpy(p
, TEXT("\\*"));
275 hFind
= FindFirstFile(buffer
, &w32fd
);
277 if (hFind
!= INVALID_HANDLE_VALUE
) {
279 entry
= alloc_entry();
287 memcpy(&entry
->data
, &w32fd
, sizeof(WIN32_FIND_DATA
));
290 entry
->expanded
= FALSE
;
291 entry
->scanned
= FALSE
;
292 entry
->level
= level
;
294 #ifdef _NO_EXTENSIONS
295 /* hide directory entry "." */
296 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
297 LPCTSTR name
= entry
->data
.cFileName
;
299 if (name
[0]=='.' && name
[1]=='\0')
303 entry
->etype
= ET_WINDOWS
;
304 entry
->bhfi_valid
= FALSE
;
306 lstrcpy(p
+1, entry
->data
.cFileName
);
308 hFile
= CreateFile(buffer
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
309 0, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0);
311 if (hFile
!= INVALID_HANDLE_VALUE
) {
312 if (GetFileInformationByHandle(hFile
, &entry
->bhfi
))
313 entry
->bhfi_valid
= TRUE
;
320 } while(FindNextFile(hFind
, &entry
->data
));
327 dir
->down
= first_entry
;
332 static Entry
* find_entry_win(Entry
* dir
, LPCTSTR name
)
336 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
338 LPCTSTR q
= entry
->data
.cFileName
;
341 if (!*p
|| *p
==TEXT('\\') || *p
==TEXT('/'))
343 } while(tolower(*p
++) == tolower(*q
++));
346 q
= entry
->data
.cAlternateFileName
;
349 if (!*p
|| *p
==TEXT('\\') || *p
==TEXT('/'))
351 } while(tolower(*p
++) == tolower(*q
++));
358 static Entry
* read_tree_win(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
360 TCHAR buffer
[MAX_PATH
];
361 Entry
* entry
= &root
->entry
;
365 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
367 #ifndef _NO_EXTENSIONS
368 entry
->etype
= ET_WINDOWS
;
372 while(*s
&& *s
!=TEXT('\\') && *s
!=TEXT('/'))
375 while(*s
==TEXT('\\') || *s
==TEXT('/'))
381 read_directory(entry
, buffer
, sortOrder
, hwnd
);
384 entry
->expanded
= TRUE
;
389 entry
= find_entry_win(entry
, s
);
392 SetCursor(old_cursor
);
398 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
400 static BOOL
time_to_filetime(const time_t* t
, FILETIME
* ftime
)
402 struct tm
* tm
= gmtime(t
);
408 stime
.wYear
= tm
->tm_year
+1900;
409 stime
.wMonth
= tm
->tm_mon
+1;
410 /* stime.wDayOfWeek */
411 stime
.wDay
= tm
->tm_mday
;
412 stime
.wHour
= tm
->tm_hour
;
413 stime
.wMinute
= tm
->tm_min
;
414 stime
.wSecond
= tm
->tm_sec
;
416 return SystemTimeToFileTime(&stime
, ftime
);
419 static void read_directory_unix(Entry
* dir
, LPCTSTR path
)
421 Entry
* first_entry
= NULL
;
425 int level
= dir
->level
+ 1;
427 DIR* pdir
= opendir(path
);
432 TCHAR buffer
[MAX_PATH
], *p
;
434 for(p
=buffer
; *path
; )
437 if (p
==buffer
|| p
[-1]!='/')
440 while((ent
=readdir(pdir
))) {
441 entry
= alloc_entry();
449 entry
->etype
= ET_UNIX
;
451 lstrcpy(entry
->data
.cFileName
, ent
->d_name
);
452 entry
->data
.dwFileAttributes
= ent
->d_name
[0]=='.'? FILE_ATTRIBUTE_HIDDEN
: 0;
454 strcpy(p
, ent
->d_name
);
456 if (!stat(buffer
, &st
)) {
457 if (S_ISDIR(st
.st_mode
))
458 entry
->data
.dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
460 entry
->data
.nFileSizeLow
= st
.st_size
& 0xFFFFFFFF;
461 entry
->data
.nFileSizeHigh
= st
.st_size
>> 32;
463 memset(&entry
->data
.ftCreationTime
, 0, sizeof(FILETIME
));
464 time_to_filetime(&st
.st_atime
, &entry
->data
.ftLastAccessTime
);
465 time_to_filetime(&st
.st_mtime
, &entry
->data
.ftLastWriteTime
);
467 entry
->bhfi
.nFileIndexLow
= ent
->d_ino
;
468 entry
->bhfi
.nFileIndexHigh
= 0;
470 entry
->bhfi
.nNumberOfLinks
= st
.st_nlink
;
472 entry
->bhfi_valid
= TRUE
;
474 entry
->data
.nFileSizeLow
= 0;
475 entry
->data
.nFileSizeHigh
= 0;
476 entry
->bhfi_valid
= FALSE
;
481 entry
->expanded
= FALSE
;
482 entry
->scanned
= FALSE
;
483 entry
->level
= level
;
493 dir
->down
= first_entry
;
497 static Entry
* find_entry_unix(Entry
* dir
, LPCTSTR name
)
501 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
503 LPCTSTR q
= entry
->data
.cFileName
;
506 if (!*p
|| *p
==TEXT('/'))
508 } while(*p
++ == *q
++);
514 static Entry
* read_tree_unix(Root
* root
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
516 TCHAR buffer
[MAX_PATH
];
517 Entry
* entry
= &root
->entry
;
521 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
523 entry
->etype
= ET_UNIX
;
526 while(*s
&& *s
!=TEXT('/'))
529 while(*s
== TEXT('/'))
535 read_directory(entry
, buffer
, sortOrder
, hwnd
);
538 entry
->expanded
= TRUE
;
543 entry
= find_entry_unix(entry
, s
);
546 SetCursor(old_cursor
);
551 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
554 #ifdef _SHELL_FOLDERS
557 #define tcscpyn strcpyn
558 #define get_strret get_strretW
559 #define path_from_pidl path_from_pidlW
561 #define tcscpyn wcscpyn
562 #define get_strret get_strretA
563 #define path_from_pidl path_from_pidlA
567 static LPSTR
strcpyn(LPSTR dest
, LPCSTR source
, size_t count
)
572 for(s
=source
; count
&&(*d
++=*s
++); )
578 static LPWSTR
wcscpyn(LPWSTR dest
, LPCWSTR source
, size_t count
)
583 for(s
=source
; count
&&(*d
++=*s
++); )
590 static void get_strretA(STRRET
* str
, const SHITEMID
* shiid
, LPSTR buffer
, int len
)
594 WideCharToMultiByte(CP_ACP
, 0, str
->UNION_MEMBER(pOleStr
), -1, buffer
, len
, NULL
, NULL
);
598 strcpyn(buffer
, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), len
);
602 strcpyn(buffer
, str
->UNION_MEMBER(cStr
), len
);
606 static void get_strretW(STRRET
* str
, const SHITEMID
* shiid
, LPWSTR buffer
, int len
)
610 wcscpyn(buffer
, str
->UNION_MEMBER(pOleStr
), len
);
614 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), -1, buffer
, len
);
618 MultiByteToWideChar(CP_ACP
, 0, str
->UNION_MEMBER(cStr
), -1, buffer
, len
);
623 static void free_strret(STRRET
* str
)
625 if (str
->uType
== STRRET_WSTR
)
626 (*Globals
.iMalloc
->lpVtbl
->Free
)(Globals
.iMalloc
, str
->UNION_MEMBER(pOleStr
));
630 HRESULT
name_from_pidl(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPTSTR buffer
, int len
, SHGDNF flags
)
634 HRESULT hr
= (*folder
->lpVtbl
->GetDisplayNameOf
)(folder
, pidl
, flags
, &str
);
637 get_strret(&str
, &pidl
->mkid
, buffer
, len
);
646 HRESULT
path_from_pidlA(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPSTR buffer
, int len
)
650 /* SHGDN_FORPARSING: get full path of id list */
651 HRESULT hr
= (*folder
->lpVtbl
->GetDisplayNameOf
)(folder
, pidl
, SHGDN_FORPARSING
, &str
);
654 get_strretA(&str
, &pidl
->mkid
, buffer
, len
);
662 HRESULT
path_from_pidlW(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPWSTR buffer
, int len
)
666 /* SHGDN_FORPARSING: get full path of id list */
667 HRESULT hr
= (*folder
->lpVtbl
->GetDisplayNameOf
)(folder
, pidl
, SHGDN_FORPARSING
, &str
);
670 get_strretW(&str
, &pidl
->mkid
, buffer
, len
);
679 /* create an item id list from a file system path */
681 static LPITEMIDLIST
get_path_pidl(LPTSTR path
, HWND hwnd
)
688 LPWSTR buffer
= path
;
690 WCHAR buffer
[MAX_PATH
];
691 MultiByteToWideChar(CP_ACP
, 0, path
, -1, buffer
, MAX_PATH
);
694 hr
= (*Globals
.iDesktop
->lpVtbl
->ParseDisplayName
)(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
702 /* convert an item id list from relative to absolute (=relative to the desktop) format */
704 static LPITEMIDLIST
get_to_absolute_pidl(Entry
* entry
, HWND hwnd
)
706 if (entry
->up
&& entry
->up
->etype
==ET_SHELL
) {
707 IShellFolder
* folder
= entry
->up
->folder
;
708 WCHAR buffer
[MAX_PATH
];
710 HRESULT hr
= path_from_pidlW(folder
, entry
->pidl
, buffer
, MAX_PATH
);
716 hr
= (*Globals
.iDesktop
->lpVtbl
->ParseDisplayName
)(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
721 } else if (entry
->etype
== ET_WINDOWS
) {
722 TCHAR path
[MAX_PATH
];
724 get_path(entry
, path
);
726 return get_path_pidl(path
, hwnd
);
727 } else if (entry
->pidl
)
728 return ILClone(entry
->pidl
);
734 HICON
extract_icon(IShellFolder
* folder
, LPCITEMIDLIST pidl
)
736 IExtractIcon
* pExtract
;
738 if (SUCCEEDED((*folder
->lpVtbl
->GetUIObjectOf
)(folder
, 0, 1, (LPCITEMIDLIST
*)&pidl
, &IID_IExtractIcon
, 0, (LPVOID
*)&pExtract
))) {
739 TCHAR path
[_MAX_PATH
];
744 if (SUCCEEDED((*pExtract
->lpVtbl
->GetIconLocation
)(pExtract
, GIL_FORSHELL
, path
, _MAX_PATH
, &idx
, &flags
))) {
745 if (!(flags
& GIL_NOTFILENAME
)) {
747 idx
= 0; /* special case for some control panel applications */
749 if ((int)ExtractIconEx(path
, idx
, 0, &hicon
, 1) > 0)
750 flags
&= ~GIL_DONTCACHE
;
752 HICON hIconLarge
= 0;
754 HRESULT hr
= (*pExtract
->lpVtbl
->Extract
)(pExtract
, path
, idx
, &hIconLarge
, &hicon
, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON
)));
757 DestroyIcon(hIconLarge
);
768 static Entry
* find_entry_shell(Entry
* dir
, LPITEMIDLIST pidl
)
772 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
773 if (entry
->pidl
->mkid
.cb
== pidl
->mkid
.cb
&&
774 !memcmp(entry
->pidl
, pidl
, entry
->pidl
->mkid
.cb
))
781 static Entry
* read_tree_shell(Root
* root
, LPITEMIDLIST pidl
, SORT_ORDER sortOrder
, HWND hwnd
)
783 Entry
* entry
= &root
->entry
;
785 LPITEMIDLIST next_pidl
= pidl
;
786 IShellFolder
* folder
;
787 IShellFolder
* child
= NULL
;
790 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
792 #ifndef _NO_EXTENSIONS
793 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
= (*Globals
.iMalloc
->lpVtbl
->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
= (*folder
->lpVtbl
->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_DATA
* w32fdata
)
838 if (!(attribs
& SFGAO_FILESYSTEM
) ||
839 FAILED(SHGetDataFromIDList(folder
, pidl
, SHGDFIL_FINDDATA
, w32fdata
, sizeof(WIN32_FIND_DATA
)))) {
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
= (*folder
->lpVtbl
->GetUIObjectOf
)(folder
, 0, 1, &pidl
, &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
849 hr
= (*pDataObj
->lpVtbl
->GetData
)(pDataObj
, &fmt
, &medium
);
851 (*pDataObj
->lpVtbl
->Release
)(pDataObj
);
854 LPCTSTR path
= (LPCTSTR
)GlobalLock(medium
.UNION_MEMBER(hGlobal
));
855 UINT sem_org
= SetErrorMode(SEM_FAILCRITICALERRORS
);
857 if (GetFileAttributesEx(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
= (*folder
->lpVtbl
->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
= (*idlist
->lpVtbl
->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_DATA
));
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
= (*folder
->lpVtbl
->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
= (*folder
->lpVtbl
->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 #ifndef _NO_EXTENSIONS
981 entry
->etype
= ET_SHELL
;
982 entry
->bhfi_valid
= FALSE
;
989 (*idlist
->lpVtbl
->Release
)(idlist
);
995 dir
->down
= first_entry
;
999 #endif /* _SHELL_FOLDERS */
1002 /* sort order for different directory/file types */
1011 /* distinguish between ".", ".." and any other directory names */
1012 static int TypeOrderFromDirname(LPCTSTR name
)
1014 if (name
[0] == '.') {
1015 if (name
[1] == '\0')
1016 return TO_DOT
; /* "." */
1018 if (name
[1]=='.' && name
[2]=='\0')
1019 return TO_DOTDOT
; /* ".." */
1022 return TO_OTHER_DIR
; /* anything else */
1025 /* directories first... */
1026 static int compareType(const WIN32_FIND_DATA
* fd1
, const WIN32_FIND_DATA
* fd2
)
1028 int order1
= fd1
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1029 int order2
= fd2
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
? TO_DIR
: TO_FILE
;
1031 /* Handle "." and ".." as special case and move them at the very first beginning. */
1032 if (order1
==TO_DIR
&& order2
==TO_DIR
) {
1033 order1
= TypeOrderFromDirname(fd1
->cFileName
);
1034 order2
= TypeOrderFromDirname(fd2
->cFileName
);
1037 return order2
==order1
? 0: order1
<order2
? -1: 1;
1041 static int compareName(const void* arg1
, const void* arg2
)
1043 const WIN32_FIND_DATA
* fd1
= &(*(Entry
**)arg1
)->data
;
1044 const WIN32_FIND_DATA
* fd2
= &(*(Entry
**)arg2
)->data
;
1046 int cmp
= compareType(fd1
, fd2
);
1050 return lstrcmpi(fd1
->cFileName
, fd2
->cFileName
);
1053 static int compareExt(const void* arg1
, const void* arg2
)
1055 const WIN32_FIND_DATA
* fd1
= &(*(Entry
**)arg1
)->data
;
1056 const WIN32_FIND_DATA
* fd2
= &(*(Entry
**)arg2
)->data
;
1057 const TCHAR
*name1
, *name2
, *ext1
, *ext2
;
1059 int cmp
= compareType(fd1
, fd2
);
1063 name1
= fd1
->cFileName
;
1064 name2
= fd2
->cFileName
;
1066 ext1
= _tcsrchr(name1
, TEXT('.'));
1067 ext2
= _tcsrchr(name2
, TEXT('.'));
1079 cmp
= lstrcmpi(ext1
, ext2
);
1083 return lstrcmpi(name1
, name2
);
1086 static int compareSize(const void* arg1
, const void* arg2
)
1088 WIN32_FIND_DATA
* fd1
= &(*(Entry
**)arg1
)->data
;
1089 WIN32_FIND_DATA
* fd2
= &(*(Entry
**)arg2
)->data
;
1091 int cmp
= compareType(fd1
, fd2
);
1095 cmp
= fd2
->nFileSizeHigh
- fd1
->nFileSizeHigh
;
1102 cmp
= fd2
->nFileSizeLow
- fd1
->nFileSizeLow
;
1104 return cmp
<0? -1: cmp
>0? 1: 0;
1107 static int compareDate(const void* arg1
, const void* arg2
)
1109 WIN32_FIND_DATA
* fd1
= &(*(Entry
**)arg1
)->data
;
1110 WIN32_FIND_DATA
* fd2
= &(*(Entry
**)arg2
)->data
;
1112 int cmp
= compareType(fd1
, fd2
);
1116 return CompareFileTime(&fd2
->ftLastWriteTime
, &fd1
->ftLastWriteTime
);
1120 static int (*sortFunctions
[])(const void* arg1
, const void* arg2
) = {
1121 compareName
, /* SORT_NAME */
1122 compareExt
, /* SORT_EXT */
1123 compareSize
, /* SORT_SIZE */
1124 compareDate
/* SORT_DATE */
1128 static void SortDirectory(Entry
* dir
, SORT_ORDER sortOrder
)
1130 Entry
* entry
= dir
->down
;
1135 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1139 array
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(Entry
*));
1142 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1145 /* call qsort with the appropriate compare function */
1146 qsort(array
, len
, sizeof(array
[0]), sortFunctions
[sortOrder
]);
1148 dir
->down
= array
[0];
1150 for(p
=array
; --len
; p
++)
1154 HeapFree( GetProcessHeap(), 0, array
);
1159 static void read_directory(Entry
* dir
, LPCTSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
1161 TCHAR buffer
[MAX_PATH
];
1166 #ifdef _SHELL_FOLDERS
1167 if (dir
->etype
== ET_SHELL
)
1169 read_directory_shell(dir
, hwnd
);
1171 if (Globals
.prescan_node
) {
1180 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1181 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1182 read_directory_shell(entry
, hwnd
);
1183 SortDirectory(entry
, sortOrder
);
1189 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1190 if (dir
->etype
== ET_UNIX
)
1192 read_directory_unix(dir
, path
);
1194 if (Globals
.prescan_node
) {
1203 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1204 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1205 lstrcpy(d
, entry
->data
.cFileName
);
1206 read_directory_unix(entry
, buffer
);
1207 SortDirectory(entry
, sortOrder
);
1214 read_directory_win(dir
, path
);
1216 if (Globals
.prescan_node
) {
1225 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
1226 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
1227 lstrcpy(d
, entry
->data
.cFileName
);
1228 read_directory_win(entry
, buffer
);
1229 SortDirectory(entry
, sortOrder
);
1234 SortDirectory(dir
, sortOrder
);
1238 static ChildWnd
* alloc_child_window(LPCTSTR path
, LPITEMIDLIST pidl
, HWND hwnd
)
1240 TCHAR drv
[_MAX_DRIVE
+1], dir
[_MAX_DIR
], name
[_MAX_FNAME
], ext
[_MAX_EXT
];
1241 TCHAR b1
[BUFFER_LEN
];
1243 ChildWnd
* child
= (ChildWnd
*) malloc(sizeof(ChildWnd
));
1244 Root
* root
= &child
->root
;
1247 memset(child
, 0, sizeof(ChildWnd
));
1249 child
->left
.treePane
= TRUE
;
1250 child
->left
.visible_cols
= 0;
1252 child
->right
.treePane
= FALSE
;
1253 #ifndef _NO_EXTENSIONS
1254 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_INDEX
|COL_LINKS
;
1256 child
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
;
1259 child
->pos
.length
= sizeof(WINDOWPLACEMENT
);
1260 child
->pos
.flags
= 0;
1261 child
->pos
.showCmd
= SW_SHOWNORMAL
;
1262 child
->pos
.rcNormalPosition
.left
= CW_USEDEFAULT
;
1263 child
->pos
.rcNormalPosition
.top
= CW_USEDEFAULT
;
1264 child
->pos
.rcNormalPosition
.right
= CW_USEDEFAULT
;
1265 child
->pos
.rcNormalPosition
.bottom
= CW_USEDEFAULT
;
1267 child
->focus_pane
= 0;
1268 child
->split_pos
= DEFAULT_SPLIT_POS
;
1269 child
->sortOrder
= SORT_NAME
;
1270 child
->header_wdths_ok
= FALSE
;
1274 lstrcpy(child
->path
, path
);
1276 _tsplitpath(path
, drv
, dir
, name
, ext
);
1279 root
->entry
.level
= 0;
1281 #ifdef _SHELL_FOLDERS
1284 root
->drive_type
= DRIVE_UNKNOWN
;
1285 lstrcpy(drv
, TEXT("\\"));
1286 lstrcpy(root
->volname
, TEXT("Desktop"));
1288 lstrcpy(root
->fs
, TEXT("Shell"));
1290 entry
= read_tree_shell(root
, pidl
, child
->sortOrder
, hwnd
);
1294 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1297 root
->drive_type
= GetDriveType(path
);
1299 lstrcat(drv
, TEXT("/"));
1300 lstrcpy(root
->volname
, TEXT("root fs"));
1302 lstrcpy(root
->fs
, TEXT("unixfs"));
1304 lstrcpy(root
->path
, TEXT("/"));
1305 entry
= read_tree_unix(root
, path
, child
->sortOrder
, hwnd
);
1310 root
->drive_type
= GetDriveType(path
);
1312 lstrcat(drv
, TEXT("\\"));
1313 GetVolumeInformation(drv
, root
->volname
, _MAX_FNAME
, 0, 0, &root
->fs_flags
, root
->fs
, _MAX_DIR
);
1315 lstrcpy(root
->path
, drv
);
1316 entry
= read_tree_win(root
, path
, child
->sortOrder
, hwnd
);
1319 #ifdef _SHELL_FOLDERS
1320 if (root
->entry
.etype
== ET_SHELL
)
1321 load_string(root
->entry
.data
.cFileName
, IDS_DESKTOP
);
1324 wsprintf(root
->entry
.data
.cFileName
, RS(b1
,IDS_TITLEFMT
), drv
, root
->fs
);
1326 root
->entry
.data
.dwFileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1328 child
->left
.root
= &root
->entry
;
1329 child
->right
.root
= NULL
;
1331 set_curdir(child
, entry
, hwnd
);
1337 /* free all memory associated with a child window */
1338 static void free_child_window(ChildWnd
* child
)
1340 free_entries(&child
->root
.entry
);
1345 /* get full path of specified directory entry */
1346 static void get_path(Entry
* dir
, PTSTR path
)
1352 #ifdef _SHELL_FOLDERS
1353 if (dir
->etype
== ET_SHELL
)
1358 path
[0] = TEXT('\0');
1363 hr
= (*dir
->folder
->lpVtbl
->GetAttributesOf
)(dir
->folder
, 1, (LPCITEMIDLIST
*)&dir
->pidl
, &attribs
);
1365 if (SUCCEEDED(hr
) && (attribs
&SFGAO_FILESYSTEM
)) {
1366 IShellFolder
* parent
= dir
->up
? dir
->up
->folder
: Globals
.iDesktop
;
1368 hr
= path_from_pidl(parent
, dir
->pidl
, path
, MAX_PATH
);
1374 for(entry
=dir
; entry
; level
++) {
1380 name
= entry
->data
.cFileName
;
1383 for(l
=0; *s
&& *s
!=TEXT('/') && *s
!=TEXT('\\'); s
++)
1389 memmove(path
+l
+1, path
, len
*sizeof(TCHAR
));
1390 memcpy(path
+1, name
, l
*sizeof(TCHAR
));
1393 #ifndef _NO_EXTENSIONS
1394 if (entry
->etype
== ET_UNIX
)
1395 path
[0] = TEXT('/');
1398 path
[0] = TEXT('\\');
1403 memmove(path
+l
, path
, len
*sizeof(TCHAR
));
1404 memcpy(path
, name
, l
*sizeof(TCHAR
));
1411 #ifndef _NO_EXTENSIONS
1412 if (entry
->etype
== ET_UNIX
)
1413 path
[len
++] = TEXT('/');
1416 path
[len
++] = TEXT('\\');
1419 path
[len
] = TEXT('\0');
1424 static void resize_frame_rect(HWND hwnd
, PRECT prect
)
1429 if (IsWindowVisible(Globals
.htoolbar
)) {
1430 SendMessage(Globals
.htoolbar
, WM_SIZE
, 0, 0);
1431 GetClientRect(Globals
.htoolbar
, &rt
);
1432 prect
->top
= rt
.bottom
+3;
1433 prect
->bottom
-= rt
.bottom
+3;
1436 if (IsWindowVisible(Globals
.hdrivebar
)) {
1437 SendMessage(Globals
.hdrivebar
, WM_SIZE
, 0, 0);
1438 GetClientRect(Globals
.hdrivebar
, &rt
);
1439 new_top
= --prect
->top
+ rt
.bottom
+3;
1440 MoveWindow(Globals
.hdrivebar
, 0, prect
->top
, rt
.right
, new_top
, TRUE
);
1441 prect
->top
= new_top
;
1442 prect
->bottom
-= rt
.bottom
+2;
1445 if (IsWindowVisible(Globals
.hstatusbar
)) {
1446 int parts
[] = {300, 500};
1448 SendMessage(Globals
.hstatusbar
, WM_SIZE
, 0, 0);
1449 SendMessage(Globals
.hstatusbar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
1450 GetClientRect(Globals
.hstatusbar
, &rt
);
1451 prect
->bottom
-= rt
.bottom
;
1454 MoveWindow(Globals
.hmdiclient
, prect
->left
-1,prect
->top
-1,prect
->right
+2,prect
->bottom
+1, TRUE
);
1457 static void resize_frame(HWND hwnd
, int cx
, int cy
)
1466 resize_frame_rect(hwnd
, &rect
);
1469 static void resize_frame_client(HWND hwnd
)
1473 GetClientRect(hwnd
, &rect
);
1475 resize_frame_rect(hwnd
, &rect
);
1479 static HHOOK hcbthook
;
1480 static ChildWnd
* newchild
= NULL
;
1482 LRESULT CALLBACK
CBTProc(int code
, WPARAM wparam
, LPARAM lparam
)
1484 if (code
==HCBT_CREATEWND
&& newchild
) {
1485 ChildWnd
* child
= newchild
;
1488 child
->hwnd
= (HWND
) wparam
;
1489 SetWindowLong(child
->hwnd
, GWL_USERDATA
, (LPARAM
)child
);
1492 return CallNextHookEx(hcbthook
, code
, wparam
, lparam
);
1495 static HWND
create_child_window(ChildWnd
* child
)
1497 MDICREATESTRUCT mcs
;
1500 mcs
.szClass
= WINEFILETREE
;
1501 mcs
.szTitle
= (LPTSTR
)child
->path
;
1502 mcs
.hOwner
= Globals
.hInstance
;
1503 mcs
.x
= child
->pos
.rcNormalPosition
.left
;
1504 mcs
.y
= child
->pos
.rcNormalPosition
.top
;
1505 mcs
.cx
= child
->pos
.rcNormalPosition
.right
-child
->pos
.rcNormalPosition
.left
;
1506 mcs
.cy
= child
->pos
.rcNormalPosition
.bottom
-child
->pos
.rcNormalPosition
.top
;
1510 hcbthook
= SetWindowsHookEx(WH_CBT
, CBTProc
, 0, GetCurrentThreadId());
1513 child
->hwnd
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDICREATE
, 0, (LPARAM
)&mcs
);
1515 UnhookWindowsHookEx(hcbthook
);
1519 UnhookWindowsHookEx(hcbthook
);
1521 ListBox_SetItemHeight(child
->left
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1522 ListBox_SetItemHeight(child
->right
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1523 idx
= ListBox_FindItemData(child
->left
.hwnd
, ListBox_GetCurSel(child
->left
.hwnd
), child
->left
.cur
);
1524 ListBox_SetCurSel(child
->left
.hwnd
, idx
);
1530 struct ExecuteDialog
{
1531 TCHAR cmd
[MAX_PATH
];
1536 static BOOL CALLBACK
ExecuteDialogWndProg(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1538 static struct ExecuteDialog
* dlg
;
1542 dlg
= (struct ExecuteDialog
*) lparam
;
1546 int id
= (int)wparam
;
1549 GetWindowText(GetDlgItem(hwnd
, 201), dlg
->cmd
, MAX_PATH
);
1550 dlg
->cmdshow
= Button_GetState(GetDlgItem(hwnd
,214))&BST_CHECKED
?
1551 SW_SHOWMINIMIZED
: SW_SHOWNORMAL
;
1552 EndDialog(hwnd
, id
);
1553 } else if (id
== IDCANCEL
)
1554 EndDialog(hwnd
, id
);
1562 static BOOL CALLBACK
DestinationDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1564 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1568 SetWindowLong(hwnd
, GWL_USERDATA
, lparam
);
1572 int id
= (int)wparam
;
1576 LPTSTR dest
= (LPTSTR
) GetWindowLong(hwnd
, GWL_USERDATA
);
1577 GetWindowText(GetDlgItem(hwnd
, 201), dest
, MAX_PATH
);
1578 EndDialog(hwnd
, id
);
1582 EndDialog(hwnd
, id
);
1586 MessageBox(hwnd
, RS(b1
,IDS_NO_IMPL
), RS(b2
,IDS_WINEFILE
), MB_OK
);
1598 #ifndef _NO_EXTENSIONS
1600 static struct FullScreenParameters
{
1610 void frame_get_clientspace(HWND hwnd
, PRECT prect
)
1614 if (!IsIconic(hwnd
))
1615 GetClientRect(hwnd
, prect
);
1619 GetWindowPlacement(hwnd
, &wp
);
1621 prect
->left
= prect
->top
= 0;
1622 prect
->right
= wp
.rcNormalPosition
.right
-wp
.rcNormalPosition
.left
-
1623 2*(GetSystemMetrics(SM_CXSIZEFRAME
)+GetSystemMetrics(SM_CXEDGE
));
1624 prect
->bottom
= wp
.rcNormalPosition
.bottom
-wp
.rcNormalPosition
.top
-
1625 2*(GetSystemMetrics(SM_CYSIZEFRAME
)+GetSystemMetrics(SM_CYEDGE
))-
1626 GetSystemMetrics(SM_CYCAPTION
)-GetSystemMetrics(SM_CYMENUSIZE
);
1629 if (IsWindowVisible(Globals
.htoolbar
)) {
1630 GetClientRect(Globals
.htoolbar
, &rt
);
1631 prect
->top
+= rt
.bottom
+2;
1634 if (IsWindowVisible(Globals
.hdrivebar
)) {
1635 GetClientRect(Globals
.hdrivebar
, &rt
);
1636 prect
->top
+= rt
.bottom
+2;
1639 if (IsWindowVisible(Globals
.hstatusbar
)) {
1640 GetClientRect(Globals
.hstatusbar
, &rt
);
1641 prect
->bottom
-= rt
.bottom
;
1645 static BOOL
toggle_fullscreen(HWND hwnd
)
1649 if ((g_fullscreen
.mode
=!g_fullscreen
.mode
)) {
1650 GetWindowRect(hwnd
, &g_fullscreen
.orgPos
);
1651 g_fullscreen
.wasZoomed
= IsZoomed(hwnd
);
1653 Frame_CalcFrameClient(hwnd
, &rt
);
1654 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
1655 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
1657 rt
.left
= g_fullscreen
.orgPos
.left
-rt
.left
;
1658 rt
.top
= g_fullscreen
.orgPos
.top
-rt
.top
;
1659 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+g_fullscreen
.orgPos
.right
-rt
.right
;
1660 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+g_fullscreen
.orgPos
.bottom
-rt
.bottom
;
1662 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
1664 MoveWindow(hwnd
, g_fullscreen
.orgPos
.left
, g_fullscreen
.orgPos
.top
,
1665 g_fullscreen
.orgPos
.right
-g_fullscreen
.orgPos
.left
,
1666 g_fullscreen
.orgPos
.bottom
-g_fullscreen
.orgPos
.top
, TRUE
);
1668 if (g_fullscreen
.wasZoomed
)
1669 ShowWindow(hwnd
, WS_MAXIMIZE
);
1672 return g_fullscreen
.mode
;
1675 static void fullscreen_move(HWND hwnd
)
1678 GetWindowRect(hwnd
, &pos
);
1680 Frame_CalcFrameClient(hwnd
, &rt
);
1681 ClientToScreen(hwnd
, (LPPOINT
)&rt
.left
);
1682 ClientToScreen(hwnd
, (LPPOINT
)&rt
.right
);
1684 rt
.left
= pos
.left
-rt
.left
;
1685 rt
.top
= pos
.top
-rt
.top
;
1686 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+pos
.right
-rt
.right
;
1687 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+pos
.bottom
-rt
.bottom
;
1689 MoveWindow(hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
1695 static void toggle_child(HWND hwnd
, UINT cmd
, HWND hchild
)
1697 BOOL vis
= IsWindowVisible(hchild
);
1699 CheckMenuItem(Globals
.hMenuOptions
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
1701 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
1703 #ifndef _NO_EXTENSIONS
1704 if (g_fullscreen
.mode
)
1705 fullscreen_move(hwnd
);
1708 resize_frame_client(hwnd
);
1711 BOOL
activate_drive_window(LPCTSTR path
)
1713 TCHAR drv1
[_MAX_DRIVE
], drv2
[_MAX_DRIVE
];
1716 _tsplitpath(path
, drv1
, 0, 0, 0);
1718 /* search for a already open window for the same drive */
1719 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
1720 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(child_wnd
, GWL_USERDATA
);
1723 _tsplitpath(child
->root
.path
, drv2
, 0, 0, 0);
1725 if (!lstrcmpi(drv2
, drv1
)) {
1726 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
1728 if (IsMinimized(child_wnd
))
1729 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
1739 BOOL
activate_fs_window(LPCTSTR filesys
)
1743 /* search for a already open window of the given file system name */
1744 for(child_wnd
=GetNextWindow(Globals
.hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
1745 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(child_wnd
, GWL_USERDATA
);
1748 if (!lstrcmpi(child
->root
.fs
, filesys
)) {
1749 SendMessage(Globals
.hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
1751 if (IsMinimized(child_wnd
))
1752 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
1762 LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1764 TCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
1768 DestroyWindow(hwnd
);
1770 /* clear handle variables */
1771 Globals
.hMenuFrame
= 0;
1772 Globals
.hMenuView
= 0;
1773 Globals
.hMenuOptions
= 0;
1774 Globals
.hMainWnd
= 0;
1775 Globals
.hmdiclient
= 0;
1776 Globals
.hdrivebar
= 0;
1780 /* don't exit desktop when closing file manager window */
1781 if (!Globals
.hwndParent
)
1786 UINT cmd
= LOWORD(wparam
);
1787 HWND hwndClient
= (HWND
) SendMessage(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
1789 if (SendMessage(hwndClient
, WM_DISPATCH_COMMAND
, wparam
, lparam
))
1792 if (cmd
>=ID_DRIVE_FIRST
&& cmd
<=ID_DRIVE_FIRST
+0xFF) {
1793 TCHAR drv
[_MAX_DRIVE
], path
[MAX_PATH
];
1795 LPCTSTR root
= Globals
.drives
;
1798 for(i
=cmd
-ID_DRIVE_FIRST
; i
--; root
++)
1802 if (activate_drive_window(root
))
1805 _tsplitpath(root
, drv
, 0, 0, 0);
1807 if (!SetCurrentDirectory(drv
)) {
1808 display_error(hwnd
, GetLastError());
1812 GetCurrentDirectory(MAX_PATH
, path
); /*TODO: store last directory per drive */
1813 child
= alloc_child_window(path
, NULL
, hwnd
);
1815 if (!create_child_window(child
))
1817 } else switch(cmd
) {
1819 SendMessage(hwnd
, WM_CLOSE
, 0, 0);
1822 case ID_WINDOW_NEW
: {
1823 TCHAR path
[MAX_PATH
];
1826 GetCurrentDirectory(MAX_PATH
, path
);
1827 child
= alloc_child_window(path
, NULL
, hwnd
);
1829 if (!create_child_window(child
))
1833 case ID_WINDOW_CASCADE
:
1834 SendMessage(Globals
.hmdiclient
, WM_MDICASCADE
, 0, 0);
1837 case ID_WINDOW_TILE_HORZ
:
1838 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
1841 case ID_WINDOW_TILE_VERT
:
1842 SendMessage(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
1845 case ID_WINDOW_ARRANGE
:
1846 SendMessage(Globals
.hmdiclient
, WM_MDIICONARRANGE
, 0, 0);
1849 case ID_SELECT_FONT
: {
1850 TCHAR dlg_name
[BUFFER_LEN
], dlg_info
[BUFFER_LEN
];
1854 HDC hdc
= GetDC(hwnd
);
1855 chFont
.lStructSize
= sizeof(CHOOSEFONT
);
1856 chFont
.hwndOwner
= hwnd
;
1858 chFont
.lpLogFont
= &lFont
;
1859 chFont
.Flags
= CF_SCREENFONTS
| CF_FORCEFONTEXIST
| CF_LIMITSIZE
| CF_NOSCRIPTSEL
;
1860 chFont
.rgbColors
= RGB(0,0,0);
1861 chFont
.lCustData
= 0;
1862 chFont
.lpfnHook
= NULL
;
1863 chFont
.lpTemplateName
= NULL
;
1864 chFont
.hInstance
= Globals
.hInstance
;
1865 chFont
.lpszStyle
= NULL
;
1866 chFont
.nFontType
= SIMULATED_FONTTYPE
;
1867 chFont
.nSizeMin
= 0;
1868 chFont
.nSizeMax
= 24;
1870 if (ChooseFont(&chFont
)) {
1873 Globals
.hfont
= CreateFontIndirect(&lFont
);
1874 SelectFont(hdc
, Globals
.hfont
);
1875 GetTextExtentPoint32(hdc
, TEXT(" "), 1, &Globals
.spaceSize
);
1877 /* change font in all open child windows */
1878 for(childWnd
=GetWindow(Globals
.hmdiclient
,GW_CHILD
); childWnd
; childWnd
=GetNextWindow(childWnd
,GW_HWNDNEXT
)) {
1879 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(childWnd
, GWL_USERDATA
);
1880 SetWindowFont(child
->left
.hwnd
, Globals
.hfont
, TRUE
);
1881 SetWindowFont(child
->right
.hwnd
, Globals
.hfont
, TRUE
);
1882 ListBox_SetItemHeight(child
->left
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1883 ListBox_SetItemHeight(child
->right
.hwnd
, 1, max(Globals
.spaceSize
.cy
,IMAGE_HEIGHT
+3));
1884 InvalidateRect(child
->left
.hwnd
, NULL
, TRUE
);
1885 InvalidateRect(child
->right
.hwnd
, NULL
, TRUE
);
1888 else if (CommDlgExtendedError()) {
1889 LoadString(Globals
.hInstance
, IDS_FONT_SEL_DLG_NAME
, dlg_name
, BUFFER_LEN
);
1890 LoadString(Globals
.hInstance
, IDS_FONT_SEL_ERROR
, dlg_info
, BUFFER_LEN
);
1891 MessageBox(hwnd
, dlg_info
, dlg_name
, MB_OK
);
1894 ReleaseDC(hwnd
, hdc
);
1898 case ID_VIEW_TOOL_BAR
:
1899 toggle_child(hwnd
, cmd
, Globals
.htoolbar
);
1902 case ID_VIEW_DRIVE_BAR
:
1903 toggle_child(hwnd
, cmd
, Globals
.hdrivebar
);
1906 case ID_VIEW_STATUSBAR
:
1907 toggle_child(hwnd
, cmd
, Globals
.hstatusbar
);
1911 struct ExecuteDialog dlg
;
1913 memset(&dlg
, 0, sizeof(struct ExecuteDialog
));
1915 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_EXECUTE
), hwnd
, ExecuteDialogWndProg
, (LPARAM
)&dlg
) == IDOK
) {
1916 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, dlg
.cmd
/*file*/, NULL
/*parameters*/, NULL
/*dir*/, dlg
.cmdshow
);
1918 if ((int)hinst
<= 32)
1919 display_error(hwnd
, GetLastError());
1924 WinHelp(hwnd
, RS(b1
,IDS_WINEFILE
), HELP_INDEX
, 0);
1927 #ifndef _NO_EXTENSIONS
1928 case ID_VIEW_FULLSCREEN
:
1929 CheckMenuItem(Globals
.hMenuOptions
, cmd
, toggle_fullscreen(hwnd
)?MF_CHECKED
:0);
1933 case ID_DRIVE_UNIX_FS
: {
1934 TCHAR path
[MAX_PATH
];
1937 if (activate_fs_window(RS(b1
,IDS_UNIXFS
)))
1940 getcwd(path
, MAX_PATH
);
1941 child
= alloc_child_window(path
, NULL
, hwnd
);
1943 if (!create_child_window(child
))
1947 #ifdef _SHELL_FOLDERS
1948 case ID_DRIVE_SHELL_NS
: {
1949 TCHAR path
[MAX_PATH
];
1952 if (activate_fs_window(RS(b1
,IDS_SHELL
)))
1955 GetCurrentDirectory(MAX_PATH
, path
);
1956 child
= alloc_child_window(path
, get_path_pidl(path
,hwnd
), hwnd
);
1958 if (!create_child_window(child
))
1964 /*TODO: There are even more menu items! */
1966 #ifndef _NO_EXTENSIONS
1969 WineLicense(Globals
.hMainWnd
);
1972 case ID_NO_WARRANTY
:
1973 WineWarranty(Globals
.hMainWnd
);
1978 ShellAbout(hwnd
, RS(b2
,IDS_WINE
), RS(b1
,IDS_WINEFILE
), 0);
1981 case ID_ABOUT
: /*ID_ABOUT_WINE: */
1982 ShellAbout(hwnd
, RS(b1
,IDS_WINEFILE
), NULL
, 0);
1984 #endif /* _NO_EXTENSIONS */
1987 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
1988 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
1989 else */if ((cmd
<IDW_FIRST_CHILD
|| cmd
>=IDW_FIRST_CHILD
+0x100) &&
1990 (cmd
<SC_SIZE
|| cmd
>SC_RESTORE
))
1991 MessageBox(hwnd
, RS(b2
,IDS_NO_IMPL
), RS(b1
,IDS_WINEFILE
), MB_OK
);
1993 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
1998 resize_frame(hwnd
, LOWORD(lparam
), HIWORD(lparam
));
1999 break; /* do not pass message to DefFrameProc */
2001 #ifndef _NO_EXTENSIONS
2002 case WM_GETMINMAXINFO
: {
2003 LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
2005 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2006 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2009 case FRM_CALC_CLIENT
:
2010 frame_get_clientspace(hwnd
, (PRECT
)lparam
);
2012 #endif /* _NO_EXTENSIONS */
2015 return DefFrameProc(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2022 static const LPTSTR g_pos_names
[COLUMNS
] = {
2023 TEXT(""), /* symbol */
2027 #ifndef _NO_EXTENSIONS
2030 TEXT("Index/Inode"),
2032 #endif /* _NO_EXTENSIONS */
2034 #ifndef _NO_EXTENSIONS
2039 static const int g_pos_align
[] = {
2041 HDF_LEFT
, /* Name */
2042 HDF_RIGHT
, /* Size */
2043 HDF_LEFT
, /* CDate */
2044 #ifndef _NO_EXTENSIONS
2045 HDF_LEFT
, /* ADate */
2046 HDF_LEFT
, /* MDate */
2047 HDF_LEFT
, /* Index */
2048 HDF_CENTER
, /* Links */
2050 HDF_CENTER
, /* Attributes */
2051 #ifndef _NO_EXTENSIONS
2052 HDF_LEFT
/* Security */
2056 static void resize_tree(ChildWnd
* child
, int cx
, int cy
)
2058 HDWP hdwp
= BeginDeferWindowPos(4);
2066 cx
= child
->split_pos
+ SPLIT_WIDTH
/2;
2068 #ifndef _NO_EXTENSIONS
2076 Header_Layout(child
->left
.hwndHeader
, &hdl
);
2078 DeferWindowPos(hdwp
, child
->left
.hwndHeader
, wp
.hwndInsertAfter
,
2079 wp
.x
-1, wp
.y
, child
->split_pos
-SPLIT_WIDTH
/2+1, wp
.cy
, wp
.flags
);
2080 DeferWindowPos(hdwp
, child
->right
.hwndHeader
, wp
.hwndInsertAfter
,
2081 rt
.left
+cx
+1, wp
.y
, wp
.cx
-cx
+2, wp
.cy
, wp
.flags
);
2083 #endif /* _NO_EXTENSIONS */
2085 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
);
2086 DeferWindowPos(hdwp
, child
->right
.hwnd
, 0, rt
.left
+cx
+1, rt
.top
, rt
.right
-cx
, rt
.bottom
-rt
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
2088 EndDeferWindowPos(hdwp
);
2092 #ifndef _NO_EXTENSIONS
2094 static HWND
create_header(HWND parent
, Pane
* pane
, int id
)
2099 HWND hwnd
= CreateWindow(WC_HEADER
, 0, WS_CHILD
|WS_VISIBLE
|HDS_HORZ
/*TODO: |HDS_BUTTONS + sort orders*/,
2100 0, 0, 0, 0, parent
, (HMENU
)id
, Globals
.hInstance
, 0);
2104 SetWindowFont(hwnd
, GetStockObject(DEFAULT_GUI_FONT
), FALSE
);
2106 hdi
.mask
= HDI_TEXT
|HDI_WIDTH
|HDI_FORMAT
;
2108 for(idx
=0; idx
<COLUMNS
; idx
++) {
2109 hdi
.pszText
= g_pos_names
[idx
];
2110 hdi
.fmt
= HDF_STRING
| g_pos_align
[idx
];
2111 hdi
.cxy
= pane
->widths
[idx
];
2112 Header_InsertItem(hwnd
, idx
, &hdi
);
2118 #endif /* _NO_EXTENSIONS */
2121 static void init_output(HWND hwnd
)
2125 HDC hdc
= GetDC(hwnd
);
2127 if (GetNumberFormat(LOCALE_USER_DEFAULT
, 0, TEXT("1000"), 0, b
, 16) > 4)
2128 Globals
.num_sep
= b
[1];
2130 Globals
.num_sep
= TEXT('.');
2132 old_font
= SelectFont(hdc
, Globals
.hfont
);
2133 GetTextExtentPoint32(hdc
, TEXT(" "), 1, &Globals
.spaceSize
);
2134 SelectFont(hdc
, old_font
);
2135 ReleaseDC(hwnd
, hdc
);
2138 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
);
2141 /* calculate prefered width for all visible columns */
2143 static BOOL
calc_widths(Pane
* pane
, BOOL anyway
)
2145 int col
, x
, cx
, spc
=3*Globals
.spaceSize
.cx
;
2146 int entries
= ListBox_GetCount(pane
->hwnd
);
2147 int orgWidths
[COLUMNS
];
2148 int orgPositions
[COLUMNS
+1];
2154 memcpy(orgWidths
, pane
->widths
, sizeof(orgWidths
));
2155 memcpy(orgPositions
, pane
->positions
, sizeof(orgPositions
));
2158 for(col
=0; col
<COLUMNS
; col
++)
2159 pane
->widths
[col
] = 0;
2161 hdc
= GetDC(pane
->hwnd
);
2162 hfontOld
= SelectFont(hdc
, Globals
.hfont
);
2164 for(cnt
=0; cnt
<entries
; cnt
++) {
2165 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, cnt
);
2174 dis
.hwndItem
= pane
->hwnd
;
2176 dis
.rcItem
.left
= 0;
2178 dis
.rcItem
.right
= 0;
2179 dis
.rcItem
.bottom
= 0;
2180 /*dis.itemData = 0; */
2182 draw_item(pane
, &dis
, entry
, COLUMNS
);
2185 SelectObject(hdc
, hfontOld
);
2186 ReleaseDC(pane
->hwnd
, hdc
);
2189 for(col
=0; col
<COLUMNS
; col
++) {
2190 pane
->positions
[col
] = x
;
2191 cx
= pane
->widths
[col
];
2196 if (cx
< IMAGE_WIDTH
)
2199 pane
->widths
[col
] = cx
;
2205 pane
->positions
[COLUMNS
] = x
;
2207 ListBox_SetHorizontalExtent(pane
->hwnd
, x
);
2210 if (!memcmp(orgWidths
, pane
->widths
, sizeof(orgWidths
)))
2213 /* don't move, if only collapsing an entry */
2214 if (!anyway
&& pane
->widths
[0]<orgWidths
[0] &&
2215 !memcmp(orgWidths
+1, pane
->widths
+1, sizeof(orgWidths
)-sizeof(int))) {
2216 pane
->widths
[0] = orgWidths
[0];
2217 memcpy(pane
->positions
, orgPositions
, sizeof(orgPositions
));
2222 InvalidateRect(pane
->hwnd
, 0, TRUE
);
2228 /* calculate one prefered column width */
2230 static void calc_single_width(Pane
* pane
, int col
)
2234 int entries
= ListBox_GetCount(pane
->hwnd
);
2238 pane
->widths
[col
] = 0;
2240 hdc
= GetDC(pane
->hwnd
);
2241 hfontOld
= SelectFont(hdc
, Globals
.hfont
);
2243 for(cnt
=0; cnt
<entries
; cnt
++) {
2244 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, cnt
);
2252 dis
.hwndItem
= pane
->hwnd
;
2254 dis
.rcItem
.left
= 0;
2256 dis
.rcItem
.right
= 0;
2257 dis
.rcItem
.bottom
= 0;
2258 /*dis.itemData = 0; */
2260 draw_item(pane
, &dis
, entry
, col
);
2263 SelectObject(hdc
, hfontOld
);
2264 ReleaseDC(pane
->hwnd
, hdc
);
2266 cx
= pane
->widths
[col
];
2269 cx
+= 3*Globals
.spaceSize
.cx
;
2271 if (cx
< IMAGE_WIDTH
)
2275 pane
->widths
[col
] = cx
;
2277 x
= pane
->positions
[col
] + cx
;
2279 for(; col
<COLUMNS
; ) {
2280 pane
->positions
[++col
] = x
;
2281 x
+= pane
->widths
[col
];
2284 ListBox_SetHorizontalExtent(pane
->hwnd
, x
);
2288 /* insert listbox entries after index idx */
2290 static void insert_entries(Pane
* pane
, Entry
* dir
, int idx
)
2297 ShowWindow(pane
->hwnd
, SW_HIDE
);
2299 for(; entry
; entry
=entry
->next
) {
2301 if (pane
->treePane
&& !(entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
2305 /* don't display entries "." and ".." in the left pane */
2306 if (pane
->treePane
&& (entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
)
2307 && entry
->data
.cFileName
[0]==TEXT('.'))
2309 #ifndef _NO_EXTENSIONS
2310 entry
->data
.cFileName
[1]==TEXT('\0') ||
2312 (entry
->data
.cFileName
[1]==TEXT('.') && entry
->data
.cFileName
[2]==TEXT('\0')))
2318 ListBox_InsertItemData(pane
->hwnd
, idx
, entry
);
2320 if (pane
->treePane
&& entry
->expanded
)
2321 insert_entries(pane
, entry
->down
, idx
);
2324 ShowWindow(pane
->hwnd
, SW_SHOW
);
2328 static WNDPROC g_orgTreeWndProc
;
2330 static void create_tree_window(HWND parent
, Pane
* pane
, int id
, int id_header
)
2332 static int s_init
= 0;
2333 Entry
* entry
= pane
->root
;
2335 pane
->hwnd
= CreateWindow(TEXT("ListBox"), TEXT(""), WS_CHILD
|WS_VISIBLE
|WS_HSCROLL
|WS_VSCROLL
|
2336 LBS_DISABLENOSCROLL
|LBS_NOINTEGRALHEIGHT
|LBS_OWNERDRAWFIXED
|LBS_NOTIFY
,
2337 0, 0, 0, 0, parent
, (HMENU
)id
, Globals
.hInstance
, 0);
2339 SetWindowLong(pane
->hwnd
, GWL_USERDATA
, (LPARAM
)pane
);
2340 g_orgTreeWndProc
= SubclassWindow(pane
->hwnd
, TreeWndProc
);
2342 SetWindowFont(pane
->hwnd
, Globals
.hfont
, FALSE
);
2344 /* insert entries into listbox */
2346 insert_entries(pane
, entry
, -1);
2348 /* calculate column widths */
2351 init_output(pane
->hwnd
);
2354 calc_widths(pane
, TRUE
);
2356 #ifndef _NO_EXTENSIONS
2357 pane
->hwndHeader
= create_header(parent
, pane
, id_header
);
2362 static void InitChildWindow(ChildWnd
* child
)
2364 create_tree_window(child
->hwnd
, &child
->left
, IDW_TREE_LEFT
, IDW_HEADER_LEFT
);
2365 create_tree_window(child
->hwnd
, &child
->right
, IDW_TREE_RIGHT
, IDW_HEADER_RIGHT
);
2369 static void format_date(const FILETIME
* ft
, TCHAR
* buffer
, int visible_cols
)
2375 *buffer
= TEXT('\0');
2377 if (!ft
->dwLowDateTime
&& !ft
->dwHighDateTime
)
2380 if (!FileTimeToLocalFileTime(ft
, &lft
))
2381 {err
: _tcscpy(buffer
,TEXT("???")); return;}
2383 if (!FileTimeToSystemTime(&lft
, &systime
))
2386 if (visible_cols
& COL_DATE
) {
2387 len
= GetDateFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
, BUFFER_LEN
);
2392 if (visible_cols
& COL_TIME
) {
2394 buffer
[len
-1] = ' ';
2396 buffer
[len
++] = ' ';
2398 if (!GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
+len
, BUFFER_LEN
-len
))
2399 buffer
[len
] = TEXT('\0');
2404 static void calc_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2406 RECT rt
= {0, 0, 0, 0};
2408 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
2410 if (rt
.right
> pane
->widths
[col
])
2411 pane
->widths
[col
] = rt
.right
;
2414 static void calc_tabbed_width(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2416 RECT rt
= {0, 0, 0, 0};
2418 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2419 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2421 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2422 /*FIXME rt (0,0) ??? */
2424 if (rt
.right
> pane
->widths
[col
])
2425 pane
->widths
[col
] = rt
.right
;
2429 static void output_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
, DWORD flags
)
2431 int x
= dis
->rcItem
.left
;
2434 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2435 rt
.top
= dis
->rcItem
.top
;
2436 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2437 rt
.bottom
= dis
->rcItem
.bottom
;
2439 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_SINGLELINE
|DT_NOPREFIX
|flags
);
2442 static void output_tabbed_text(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2444 int x
= dis
->rcItem
.left
;
2447 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2448 rt
.top
= dis
->rcItem
.top
;
2449 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2450 rt
.bottom
= dis
->rcItem
.bottom
;
2452 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2453 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2455 DrawText(dis
->hDC
, (LPTSTR
)str
, -1, &rt
, DT_SINGLELINE
|DT_EXPANDTABS
|DT_TABSTOP
|(2<<8));
2458 static void output_number(Pane
* pane
, LPDRAWITEMSTRUCT dis
, int col
, LPCTSTR str
)
2460 int x
= dis
->rcItem
.left
;
2467 rt
.left
= x
+pane
->positions
[col
]+Globals
.spaceSize
.cx
;
2468 rt
.top
= dis
->rcItem
.top
;
2469 rt
.right
= x
+pane
->positions
[col
+1]-Globals
.spaceSize
.cx
;
2470 rt
.bottom
= dis
->rcItem
.bottom
;
2475 /* insert number separator characters */
2476 pos
= lstrlen(s
) % 3;
2482 *d
++ = Globals
.num_sep
;
2486 DrawText(dis
->hDC
, b
, d
-b
, &rt
, DT_RIGHT
|DT_SINGLELINE
|DT_NOPREFIX
|DT_END_ELLIPSIS
);
2490 static int is_exe_file(LPCTSTR ext
)
2492 static const LPCTSTR executable_extensions
[] = {
2497 #ifndef _NO_EXTENSIONS
2501 #endif /* _NO_EXTENSIONS */
2505 TCHAR ext_buffer
[_MAX_EXT
];
2510 for(s
=ext
+1,d
=ext_buffer
; (*d
=tolower(*s
)); s
++)
2513 for(p
=executable_extensions
; *p
; p
++)
2514 if (!_tcscmp(ext_buffer
, *p
))
2520 static int is_registered_type(LPCTSTR ext
)
2528 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
)
2530 TCHAR buffer
[BUFFER_LEN
];
2532 int visible_cols
= pane
->visible_cols
;
2533 COLORREF bkcolor
, textcolor
;
2534 RECT focusRect
= dis
->rcItem
;
2541 attrs
= entry
->data
.dwFileAttributes
;
2543 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) {
2544 if (entry
->data
.cFileName
[0]==TEXT('.') && entry
->data
.cFileName
[1]==TEXT('.')
2545 && entry
->data
.cFileName
[2]==TEXT('\0'))
2546 img
= IMG_FOLDER_UP
;
2547 #ifndef _NO_EXTENSIONS
2548 else if (entry
->data
.cFileName
[0]==TEXT('.') && entry
->data
.cFileName
[1]==TEXT('\0'))
2549 img
= IMG_FOLDER_CUR
;
2552 #ifdef _NO_EXTENSIONS
2555 (pane
->treePane
&& (dis
->itemState
&ODS_FOCUS
)))
2556 img
= IMG_OPEN_FOLDER
;
2560 LPCTSTR ext
= _tcsrchr(entry
->data
.cFileName
, '.');
2564 if (is_exe_file(ext
))
2565 img
= IMG_EXECUTABLE
;
2566 else if (is_registered_type(ext
))
2576 if (pane
->treePane
) {
2578 img_pos
= dis
->rcItem
.left
+ entry
->level
*(IMAGE_WIDTH
+TREE_LINE_DX
);
2580 if (calcWidthCol
== -1) {
2582 int y
= dis
->rcItem
.top
+ IMAGE_HEIGHT
/2;
2585 HRGN hrgn_org
= CreateRectRgn(0, 0, 0, 0);
2588 rt_clip
.left
= dis
->rcItem
.left
;
2589 rt_clip
.top
= dis
->rcItem
.top
;
2590 rt_clip
.right
= dis
->rcItem
.left
+pane
->widths
[col
];
2591 rt_clip
.bottom
= dis
->rcItem
.bottom
;
2593 hrgn
= CreateRectRgnIndirect(&rt_clip
);
2595 if (!GetClipRgn(dis
->hDC
, hrgn_org
)) {
2596 DeleteObject(hrgn_org
);
2600 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
2601 ExtSelectClipRgn(dis
->hDC
, hrgn
, RGN_AND
);
2604 if ((up
=entry
->up
) != NULL
) {
2605 MoveToEx(dis
->hDC
, img_pos
-IMAGE_WIDTH
/2, y
, 0);
2606 LineTo(dis
->hDC
, img_pos
-2, y
);
2608 x
= img_pos
- IMAGE_WIDTH
/2;
2611 x
-= IMAGE_WIDTH
+TREE_LINE_DX
;
2615 && (up
->next
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
2618 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
2619 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
2621 } while((up
=up
->up
) != NULL
);
2624 x
= img_pos
- IMAGE_WIDTH
/2;
2626 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
, 0);
2627 LineTo(dis
->hDC
, x
, y
);
2631 && (entry
->next
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
)
2634 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
2636 if (entry
->down
&& entry
->expanded
) {
2637 x
+= IMAGE_WIDTH
+TREE_LINE_DX
;
2638 MoveToEx(dis
->hDC
, x
, dis
->rcItem
.top
+IMAGE_HEIGHT
+2, 0);
2639 LineTo(dis
->hDC
, x
, dis
->rcItem
.bottom
);
2642 SelectClipRgn(dis
->hDC
, hrgn_org
);
2643 if (hrgn_org
) DeleteObject(hrgn_org
);
2644 /* SelectObject(dis->hDC, holdPen); */
2645 } else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
) {
2646 int right
= img_pos
+ IMAGE_WIDTH
- TREE_LINE_DX
;
2648 if (right
> pane
->widths
[col
])
2649 pane
->widths
[col
] = right
;
2652 img_pos
= dis
->rcItem
.left
;
2655 img_pos
= dis
->rcItem
.left
;
2657 if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2658 pane
->widths
[col
] = IMAGE_WIDTH
;
2661 if (calcWidthCol
== -1) {
2662 focusRect
.left
= img_pos
-2;
2664 #ifdef _NO_EXTENSIONS
2665 if (pane
->treePane
&& entry
) {
2668 DrawText(dis
->hDC
, entry
->data
.cFileName
, -1, &rt
, DT_CALCRECT
|DT_SINGLELINE
|DT_NOPREFIX
);
2670 focusRect
.right
= dis
->rcItem
.left
+pane
->positions
[col
+1]+TREE_LINE_DX
+ rt
.right
+2;
2674 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
)
2675 textcolor
= COLOR_COMPRESSED
;
2677 #endif /* _NO_EXTENSIONS */
2678 textcolor
= RGB(0,0,0);
2680 if (dis
->itemState
& ODS_FOCUS
) {
2681 textcolor
= RGB(255,255,255);
2682 bkcolor
= COLOR_SELECTION
;
2684 bkcolor
= RGB(255,255,255);
2687 hbrush
= CreateSolidBrush(bkcolor
);
2688 FillRect(dis
->hDC
, &focusRect
, hbrush
);
2689 DeleteObject(hbrush
);
2691 SetBkMode(dis
->hDC
, TRANSPARENT
);
2692 SetTextColor(dis
->hDC
, textcolor
);
2694 cx
= pane
->widths
[col
];
2696 if (cx
&& img
!=IMG_NONE
) {
2698 if (cx
> IMAGE_WIDTH
)
2701 #ifdef _SHELL_FOLDERS
2702 if (entry
->hicon
&& entry
->hicon
!=(HICON
)-1)
2703 DrawIconEx(dis
->hDC
, img_pos
, dis
->rcItem
.top
, entry
->hicon
, cx
, GetSystemMetrics(SM_CYSMICON
), 0, 0, DI_NORMAL
);
2706 ImageList_DrawEx(Globals
.himl
, img
, dis
->hDC
,
2707 img_pos
, dis
->rcItem
.top
, cx
,
2708 IMAGE_HEIGHT
, bkcolor
, CLR_DEFAULT
, ILD_NORMAL
);
2715 #ifdef _NO_EXTENSIONS
2716 if (img
>= IMG_FOLDER_UP
)
2722 /* ouput file name */
2723 if (calcWidthCol
== -1)
2724 output_text(pane
, dis
, col
, entry
->data
.cFileName
, 0);
2725 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2726 calc_width(pane
, dis
, col
, entry
->data
.cFileName
);
2730 #ifdef _NO_EXTENSIONS
2731 if (!pane
->treePane
) {
2734 /* display file size */
2735 if (visible_cols
& COL_SIZE
) {
2736 #ifdef _NO_EXTENSIONS
2737 if (!(attrs
&FILE_ATTRIBUTE_DIRECTORY
))
2742 size
= ((ULONGLONG
)entry
->data
.nFileSizeHigh
<< 32) | entry
->data
.nFileSizeLow
;
2744 _stprintf(buffer
, TEXT("%") LONGLONGARG
TEXT("d"), size
);
2746 if (calcWidthCol
== -1)
2747 output_number(pane
, dis
, col
, buffer
);
2748 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2749 calc_width(pane
, dis
, col
, buffer
);/*TODO: not ever time enough */
2755 /* display file date */
2756 if (visible_cols
& (COL_DATE
|COL_TIME
)) {
2757 #ifndef _NO_EXTENSIONS
2758 format_date(&entry
->data
.ftCreationTime
, buffer
, visible_cols
);
2759 if (calcWidthCol
== -1)
2760 output_text(pane
, dis
, col
, buffer
, 0);
2761 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2762 calc_width(pane
, dis
, col
, buffer
);
2765 format_date(&entry
->data
.ftLastAccessTime
, buffer
, visible_cols
);
2766 if (calcWidthCol
== -1)
2767 output_text(pane
, dis
, col
, buffer
, 0);
2768 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2769 calc_width(pane
, dis
, col
, buffer
);
2771 #endif /* _NO_EXTENSIONS */
2773 format_date(&entry
->data
.ftLastWriteTime
, buffer
, visible_cols
);
2774 if (calcWidthCol
== -1)
2775 output_text(pane
, dis
, col
, buffer
, 0);
2776 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2777 calc_width(pane
, dis
, col
, buffer
);
2781 #ifndef _NO_EXTENSIONS
2782 if (entry
->bhfi_valid
) {
2783 ULONGLONG index
= ((ULONGLONG
)entry
->bhfi
.nFileIndexHigh
<< 32) | entry
->bhfi
.nFileIndexLow
;
2785 if (visible_cols
& COL_INDEX
) {
2786 _stprintf(buffer
, TEXT("%") LONGLONGARG
TEXT("X"), index
);
2787 if (calcWidthCol
== -1)
2788 output_text(pane
, dis
, col
, buffer
, DT_RIGHT
);
2789 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2790 calc_width(pane
, dis
, col
, buffer
);
2794 if (visible_cols
& COL_LINKS
) {
2795 wsprintf(buffer
, TEXT("%d"), entry
->bhfi
.nNumberOfLinks
);
2796 if (calcWidthCol
== -1)
2797 output_text(pane
, dis
, col
, buffer
, DT_CENTER
);
2798 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2799 calc_width(pane
, dis
, col
, buffer
);
2804 #endif /* _NO_EXTENSIONS */
2806 /* show file attributes */
2807 if (visible_cols
& COL_ATTRIBUTES
) {
2808 #ifdef _NO_EXTENSIONS
2809 _tcscpy(buffer
, TEXT(" \t \t \t \t "));
2811 _tcscpy(buffer
, TEXT(" \t \t \t \t \t \t \t \t \t \t \t "));
2814 if (attrs
& FILE_ATTRIBUTE_NORMAL
) buffer
[ 0] = 'N';
2816 if (attrs
& FILE_ATTRIBUTE_READONLY
) buffer
[ 2] = 'R';
2817 if (attrs
& FILE_ATTRIBUTE_HIDDEN
) buffer
[ 4] = 'H';
2818 if (attrs
& FILE_ATTRIBUTE_SYSTEM
) buffer
[ 6] = 'S';
2819 if (attrs
& FILE_ATTRIBUTE_ARCHIVE
) buffer
[ 8] = 'A';
2820 if (attrs
& FILE_ATTRIBUTE_COMPRESSED
) buffer
[10] = 'C';
2821 #ifndef _NO_EXTENSIONS
2822 if (attrs
& FILE_ATTRIBUTE_DIRECTORY
) buffer
[12] = 'D';
2823 if (attrs
& FILE_ATTRIBUTE_ENCRYPTED
) buffer
[14] = 'E';
2824 if (attrs
& FILE_ATTRIBUTE_TEMPORARY
) buffer
[16] = 'T';
2825 if (attrs
& FILE_ATTRIBUTE_SPARSE_FILE
) buffer
[18] = 'P';
2826 if (attrs
& FILE_ATTRIBUTE_REPARSE_POINT
) buffer
[20] = 'Q';
2827 if (attrs
& FILE_ATTRIBUTE_OFFLINE
) buffer
[22] = 'O';
2828 if (attrs
& FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
) buffer
[24] = 'X';
2829 #endif /* _NO_EXTENSIONS */
2832 if (calcWidthCol
== -1)
2833 output_tabbed_text(pane
, dis
, col
, buffer
);
2834 else if (calcWidthCol
==col
|| calcWidthCol
==COLUMNS
)
2835 calc_tabbed_width(pane
, dis
, col
, buffer
);
2841 if (flags.security) {
2842 DWORD rights = get_access_mask();
2844 tcscpy(buffer, TEXT(" \t \t \t \t \t \t \t \t \t \t \t "));
2846 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
2847 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
2848 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
2849 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
2850 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
2851 if (rights & FILE_EXECUTE) buffer[12] = 'X';
2852 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
2853 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
2854 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
2855 if (rights & WRITE_DAC) buffer[22] = 'C';
2856 if (rights & WRITE_OWNER) buffer[24] = 'O';
2857 if (rights & SYNCHRONIZE) buffer[26] = 'S';
2859 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
2862 if (flags.description) {
2863 get_description(buffer);
2864 output_text(dis, col++, buffer, 0, psize);
2868 #ifdef _NO_EXTENSIONS
2871 /* draw focus frame */
2872 if ((dis
->itemState
&ODS_FOCUS
) && calcWidthCol
==-1) {
2873 /* Currently [04/2000] Wine neither behaves exactly the same */
2874 /* way as WIN 95 nor like Windows NT... */
2879 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
2880 LOGBRUSH lb
= {PS_SOLID
, RGB(255,255,255)};
2881 hpen
= ExtCreatePen(PS_COSMETIC
|PS_ALTERNATE
, 1, &lb
, 0, 0);
2883 hpen
= CreatePen(PS_DOT
, 0, RGB(255,255,255));
2885 lastPen
= SelectPen(dis
->hDC
, hpen
);
2886 lastBrush
= SelectObject(dis
->hDC
, GetStockObject(HOLLOW_BRUSH
));
2887 SetROP2(dis
->hDC
, R2_XORPEN
);
2888 Rectangle(dis
->hDC
, focusRect
.left
, focusRect
.top
, focusRect
.right
, focusRect
.bottom
);
2889 SelectObject(dis
->hDC
, lastBrush
);
2890 SelectObject(dis
->hDC
, lastPen
);
2893 #endif /* _NO_EXTENSIONS */
2897 #ifdef _NO_EXTENSIONS
2899 static void draw_splitbar(HWND hwnd
, int x
)
2902 HDC hdc
= GetDC(hwnd
);
2904 GetClientRect(hwnd
, &rt
);
2906 rt
.left
= x
- SPLIT_WIDTH
/2;
2907 rt
.right
= x
+ SPLIT_WIDTH
/2+1;
2909 InvertRect(hdc
, &rt
);
2911 ReleaseDC(hwnd
, hdc
);
2914 #endif /* _NO_EXTENSIONS */
2917 #ifndef _NO_EXTENSIONS
2919 static void set_header(Pane
* pane
)
2922 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
2925 item
.mask
= HDI_WIDTH
;
2928 for(; x
+pane
->widths
[i
]<scroll_pos
&& i
<COLUMNS
; i
++) {
2929 x
+= pane
->widths
[i
];
2930 Header_SetItem(pane
->hwndHeader
, i
, &item
);
2934 x
+= pane
->widths
[i
];
2935 item
.cxy
= x
- scroll_pos
;
2936 Header_SetItem(pane
->hwndHeader
, i
++, &item
);
2938 for(; i
<COLUMNS
; i
++) {
2939 item
.cxy
= pane
->widths
[i
];
2940 x
+= pane
->widths
[i
];
2941 Header_SetItem(pane
->hwndHeader
, i
, &item
);
2946 static LRESULT
pane_notify(Pane
* pane
, NMHDR
* pnmh
)
2948 switch(pnmh
->code
) {
2950 case HDN_ENDTRACK
: {
2951 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
2952 int idx
= phdn
->iItem
;
2953 int dx
= phdn
->pitem
->cxy
- pane
->widths
[idx
];
2957 GetClientRect(pane
->hwnd
, &clnt
);
2959 /* move immediate to simulate HDS_FULLDRAG (for now [04/2000] not really needed with WINELIB) */
2960 Header_SetItem(pane
->hwndHeader
, idx
, phdn
->pitem
);
2962 pane
->widths
[idx
] += dx
;
2964 for(i
=idx
; ++i
<=COLUMNS
; )
2965 pane
->positions
[i
] += dx
;
2968 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
2972 rt_scr
.left
= pane
->positions
[idx
+1]-scroll_pos
;
2974 rt_scr
.right
= clnt
.right
;
2975 rt_scr
.bottom
= clnt
.bottom
;
2977 rt_clip
.left
= pane
->positions
[idx
]-scroll_pos
;
2979 rt_clip
.right
= clnt
.right
;
2980 rt_clip
.bottom
= clnt
.bottom
;
2982 if (rt_scr
.left
< 0) rt_scr
.left
= 0;
2983 if (rt_clip
.left
< 0) rt_clip
.left
= 0;
2985 ScrollWindowEx(pane
->hwnd
, dx
, 0, &rt_scr
, &rt_clip
, 0, 0, SW_INVALIDATE
);
2987 rt_clip
.right
= pane
->positions
[idx
+1];
2988 RedrawWindow(pane
->hwnd
, &rt_clip
, 0, RDW_INVALIDATE
|RDW_UPDATENOW
);
2990 if (pnmh
->code
== HDN_ENDTRACK
) {
2991 ListBox_SetHorizontalExtent(pane
->hwnd
, pane
->positions
[COLUMNS
]);
2993 if (GetScrollPos(pane
->hwnd
, SB_HORZ
) != scroll_pos
)
3001 case HDN_DIVIDERDBLCLICK
: {
3002 HD_NOTIFY
* phdn
= (HD_NOTIFY
*) pnmh
;
3005 calc_single_width(pane
, phdn
->iItem
);
3006 item
.mask
= HDI_WIDTH
;
3007 item
.cxy
= pane
->widths
[phdn
->iItem
];
3009 Header_SetItem(pane
->hwndHeader
, phdn
->iItem
, &item
);
3010 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3017 #endif /* _NO_EXTENSIONS */
3020 static void scan_entry(ChildWnd
* child
, Entry
* entry
, HWND hwnd
)
3022 TCHAR path
[MAX_PATH
];
3023 int idx
= ListBox_GetCurSel(child
->left
.hwnd
);
3024 HCURSOR old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
3026 /* delete sub entries in left pane */
3028 LRESULT res
= ListBox_GetItemData(child
->left
.hwnd
, idx
+1);
3029 Entry
* sub
= (Entry
*) res
;
3031 if (res
==LB_ERR
|| !sub
|| sub
->level
<=entry
->level
)
3034 ListBox_DeleteString(child
->left
.hwnd
, idx
+1);
3037 /* empty right pane */
3038 ListBox_ResetContent(child
->right
.hwnd
);
3040 /* release memory */
3041 free_entries(entry
);
3043 /* read contents from disk */
3044 #ifdef _SHELL_FOLDERS
3045 if (entry
->etype
== ET_SHELL
)
3047 read_directory(entry
, NULL
, child
->sortOrder
, hwnd
);
3052 get_path(entry
, path
);
3053 read_directory(entry
, path
, child
->sortOrder
, hwnd
);
3056 /* insert found entries in right pane */
3057 insert_entries(&child
->right
, entry
->down
, -1);
3058 calc_widths(&child
->right
, FALSE
);
3059 #ifndef _NO_EXTENSIONS
3060 set_header(&child
->right
);
3063 child
->header_wdths_ok
= FALSE
;
3065 SetCursor(old_cursor
);
3069 /* expand a directory entry */
3071 static BOOL
expand_entry(ChildWnd
* child
, Entry
* dir
)
3076 if (!dir
|| dir
->expanded
|| !dir
->down
)
3081 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='\0' && p
->next
) {
3084 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='.' &&
3085 p
->data
.cFileName
[2]=='\0' && p
->next
)
3089 /* no subdirectories ? */
3090 if (!(p
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
3093 idx
= ListBox_FindItemData(child
->left
.hwnd
, 0, dir
);
3095 dir
->expanded
= TRUE
;
3097 /* insert entries in left pane */
3098 insert_entries(&child
->left
, p
, idx
);
3100 if (!child
->header_wdths_ok
) {
3101 if (calc_widths(&child
->left
, FALSE
)) {
3102 #ifndef _NO_EXTENSIONS
3103 set_header(&child
->left
);
3106 child
->header_wdths_ok
= TRUE
;
3114 static void collapse_entry(Pane
* pane
, Entry
* dir
)
3116 int idx
= ListBox_FindItemData(pane
->hwnd
, 0, dir
);
3118 ShowWindow(pane
->hwnd
, SW_HIDE
);
3120 /* hide sub entries */
3122 LRESULT res
= ListBox_GetItemData(pane
->hwnd
, idx
+1);
3123 Entry
* sub
= (Entry
*) res
;
3125 if (res
==LB_ERR
|| !sub
|| sub
->level
<=dir
->level
)
3128 ListBox_DeleteString(pane
->hwnd
, idx
+1);
3131 dir
->expanded
= FALSE
;
3133 ShowWindow(pane
->hwnd
, SW_SHOW
);
3137 static void set_curdir(ChildWnd
* child
, Entry
* entry
, HWND hwnd
)
3139 TCHAR path
[MAX_PATH
];
3143 child
->left
.cur
= entry
;
3144 child
->right
.root
= entry
->down
? entry
->down
: entry
;
3145 child
->right
.cur
= entry
;
3147 if (!entry
->scanned
)
3148 scan_entry(child
, entry
, hwnd
);
3150 ListBox_ResetContent(child
->right
.hwnd
);
3151 insert_entries(&child
->right
, entry
->down
, -1);
3152 calc_widths(&child
->right
, FALSE
);
3153 #ifndef _NO_EXTENSIONS
3154 set_header(&child
->right
);
3158 get_path(entry
, path
);
3159 lstrcpy(child
->path
, path
);
3161 if (child
->hwnd
) /* only change window title, if the window already exists */
3162 SetWindowText(child
->hwnd
, path
);
3165 SetCurrentDirectory(path
);
3169 BOOL
launch_file(HWND hwnd
, LPCTSTR cmd
, UINT nCmdShow
)
3171 HINSTANCE hinst
= ShellExecute(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3173 if ((int)hinst
<= 32) {
3174 display_error(hwnd
, GetLastError());
3182 BOOL
launch_fileA(HWND hwnd
, LPSTR cmd
, UINT nCmdShow
)
3184 HINSTANCE hinst
= ShellExecuteA(hwnd
, NULL
/*operation*/, cmd
, NULL
/*parameters*/, NULL
/*dir*/, nCmdShow
);
3186 if ((int)hinst
<= 32) {
3187 display_error(hwnd
, GetLastError());
3196 BOOL
launch_entry(Entry
* entry
, HWND hwnd
, UINT nCmdShow
)
3198 TCHAR cmd
[MAX_PATH
];
3200 #ifdef _SHELL_FOLDERS
3201 if (entry
->etype
== ET_SHELL
) {
3204 SHELLEXECUTEINFO shexinfo
;
3206 shexinfo
.cbSize
= sizeof(SHELLEXECUTEINFO
);
3207 shexinfo
.fMask
= SEE_MASK_IDLIST
;
3208 shexinfo
.hwnd
= hwnd
;
3209 shexinfo
.lpVerb
= NULL
;
3210 shexinfo
.lpFile
= NULL
;
3211 shexinfo
.lpParameters
= NULL
;
3212 shexinfo
.lpDirectory
= NULL
;
3213 shexinfo
.nShow
= nCmdShow
;
3214 shexinfo
.lpIDList
= get_to_absolute_pidl(entry
, hwnd
);
3216 if (!ShellExecuteEx(&shexinfo
)) {
3217 display_error(hwnd
, GetLastError());
3221 if (shexinfo
.lpIDList
!= entry
->pidl
)
3222 (*Globals
.iMalloc
->lpVtbl
->Free
)(Globals
.iMalloc
, shexinfo
.lpIDList
);
3228 get_path(entry
, cmd
);
3230 /* start program, open document... */
3231 return launch_file(hwnd
, cmd
, nCmdShow
);
3235 static void activate_entry(ChildWnd
* child
, Pane
* pane
, HWND hwnd
)
3237 Entry
* entry
= pane
->cur
;
3242 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
3243 int scanned_old
= entry
->scanned
;
3246 scan_entry(child
, entry
, hwnd
);
3248 #ifndef _NO_EXTENSIONS
3249 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='\0')
3253 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='.' && entry
->data
.cFileName
[2]=='\0') {
3254 entry
= child
->left
.cur
->up
;
3255 collapse_entry(&child
->left
, entry
);
3257 } else if (entry
->expanded
)
3258 collapse_entry(pane
, child
->left
.cur
);
3260 expand_entry(child
, child
->left
.cur
);
3262 if (!pane
->treePane
) focus_entry
: {
3263 int idx
= ListBox_FindItemData(child
->left
.hwnd
, ListBox_GetCurSel(child
->left
.hwnd
), entry
);
3264 ListBox_SetCurSel(child
->left
.hwnd
, idx
);
3265 set_curdir(child
, entry
, hwnd
);
3270 calc_widths(pane
, FALSE
);
3272 #ifndef _NO_EXTENSIONS
3277 launch_entry(entry
, child
->hwnd
, SW_SHOWNORMAL
);
3282 static BOOL
pane_command(Pane
* pane
, UINT cmd
)
3286 if (pane
->visible_cols
) {
3287 pane
->visible_cols
= 0;
3288 calc_widths(pane
, TRUE
);
3289 #ifndef _NO_EXTENSIONS
3292 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3293 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
|MF_CHECKED
);
3294 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
);
3295 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
3299 case ID_VIEW_ALL_ATTRIBUTES
:
3300 if (pane
->visible_cols
!= COL_ALL
) {
3301 pane
->visible_cols
= COL_ALL
;
3302 calc_widths(pane
, TRUE
);
3303 #ifndef _NO_EXTENSIONS
3306 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3307 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_NAME
, MF_BYCOMMAND
);
3308 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_ALL_ATTRIBUTES
, MF_BYCOMMAND
|MF_CHECKED
);
3309 CheckMenuItem(Globals
.hMenuView
, ID_VIEW_SELECTED_ATTRIBUTES
, MF_BYCOMMAND
);
3313 #ifndef _NO_EXTENSIONS
3314 case ID_PREFERED_SIZES
: {
3315 calc_widths(pane
, TRUE
);
3317 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3321 /* TODO: more command ids... */
3331 static HRESULT
ShellFolderContextMenu(IShellFolder
* shell_folder
, HWND hwndParent
, int cidl
, LPCITEMIDLIST
* apidl
, int x
, int y
)
3335 HRESULT hr
= (*shell_folder
->lpVtbl
->GetUIObjectOf
)(shell_folder
, hwndParent
, cidl
, apidl
, &IID_IContextMenu
, NULL
, (LPVOID
*)&pcm
);
3336 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
3338 if (SUCCEEDED(hr
)) {
3339 HMENU hmenu
= CreatePopupMenu();
3342 hr
= (*pcm
->lpVtbl
->QueryContextMenu
)(pcm
, hmenu
, 0, FCIDM_SHVIEWFIRST
, FCIDM_SHVIEWLAST
, CMF_NORMAL
);
3344 if (SUCCEEDED(hr
)) {
3345 UINT idCmd
= TrackPopupMenu(hmenu
, TPM_LEFTALIGN
|TPM_RETURNCMD
|TPM_RIGHTBUTTON
, x
, y
, 0, hwndParent
, NULL
);
3348 CMINVOKECOMMANDINFO cmi
;
3350 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFO
);
3352 cmi
.hwnd
= hwndParent
;
3353 cmi
.lpVerb
= (LPCSTR
)(INT_PTR
)(idCmd
- FCIDM_SHVIEWFIRST
);
3354 cmi
.lpParameters
= NULL
;
3355 cmi
.lpDirectory
= NULL
;
3356 cmi
.nShow
= SW_SHOWNORMAL
;
3360 hr
= (*pcm
->lpVtbl
->InvokeCommand
)(pcm
, &cmi
);
3365 (*pcm
->lpVtbl
->Release
)(pcm
);
3372 LRESULT CALLBACK
ChildWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3374 static int last_split
;
3376 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(hwnd
, GWL_USERDATA
);
3381 LPDRAWITEMSTRUCT dis
= (LPDRAWITEMSTRUCT
)lparam
;
3382 Entry
* entry
= (Entry
*) dis
->itemData
;
3384 if (dis
->CtlID
== IDW_TREE_LEFT
)
3385 draw_item(&child
->left
, dis
, entry
, -1);
3387 draw_item(&child
->right
, dis
, entry
, -1);
3392 InitChildWindow(child
);
3396 free_child_window(child
);
3397 SetWindowLong(hwnd
, GWL_USERDATA
, 0);
3404 GetClientRect(hwnd
, &rt
);
3405 BeginPaint(hwnd
, &ps
);
3406 rt
.left
= child
->split_pos
-SPLIT_WIDTH
/2;
3407 rt
.right
= child
->split_pos
+SPLIT_WIDTH
/2+1;
3408 lastBrush
= SelectBrush(ps
.hdc
, (HBRUSH
)GetStockObject(COLOR_SPLITBAR
));
3409 Rectangle(ps
.hdc
, rt
.left
, rt
.top
-1, rt
.right
, rt
.bottom
+1);
3410 SelectObject(ps
.hdc
, lastBrush
);
3411 #ifdef _NO_EXTENSIONS
3412 rt
.top
= rt
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
3413 FillRect(ps
.hdc
, &rt
, GetStockObject(BLACK_BRUSH
));
3415 EndPaint(hwnd
, &ps
);
3419 if (LOWORD(lparam
) == HTCLIENT
) {
3422 ScreenToClient(hwnd
, &pt
);
3424 if (pt
.x
>=child
->split_pos
-SPLIT_WIDTH
/2 && pt
.x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
3425 SetCursor(LoadCursor(0, IDC_SIZEWE
));
3431 case WM_LBUTTONDOWN
: {
3433 int x
= GET_X_LPARAM(lparam
);
3435 GetClientRect(hwnd
, &rt
);
3437 if (x
>=child
->split_pos
-SPLIT_WIDTH
/2 && x
<child
->split_pos
+SPLIT_WIDTH
/2+1) {
3438 last_split
= child
->split_pos
;
3439 #ifdef _NO_EXTENSIONS
3440 draw_splitbar(hwnd
, last_split
);
3448 if (GetCapture() == hwnd
) {
3449 #ifdef _NO_EXTENSIONS
3451 int x
= LOWORD(lparam
);
3452 draw_splitbar(hwnd
, last_split
);
3454 GetClientRect(hwnd
, &rt
);
3455 child
->split_pos
= x
;
3456 resize_tree(child
, rt
.right
, rt
.bottom
);
3462 #ifdef _NO_EXTENSIONS
3463 case WM_CAPTURECHANGED
:
3464 if (GetCapture()==hwnd
&& last_split
>=0)
3465 draw_splitbar(hwnd
, last_split
);
3470 if (wparam
== VK_ESCAPE
)
3471 if (GetCapture() == hwnd
) {
3473 #ifdef _NO_EXTENSIONS
3474 draw_splitbar(hwnd
, last_split
);
3476 child
->split_pos
= last_split
;
3478 GetClientRect(hwnd
, &rt
);
3479 resize_tree(child
, rt
.right
, rt
.bottom
);
3482 SetCursor(LoadCursor(0, IDC_ARROW
));
3487 if (GetCapture() == hwnd
) {
3489 int x
= LOWORD(lparam
);
3491 #ifdef _NO_EXTENSIONS
3492 HDC hdc
= GetDC(hwnd
);
3493 GetClientRect(hwnd
, &rt
);
3495 rt
.left
= last_split
-SPLIT_WIDTH
/2;
3496 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
3497 InvertRect(hdc
, &rt
);
3500 rt
.left
= x
-SPLIT_WIDTH
/2;
3501 rt
.right
= x
+SPLIT_WIDTH
/2+1;
3502 InvertRect(hdc
, &rt
);
3504 ReleaseDC(hwnd
, hdc
);
3506 GetClientRect(hwnd
, &rt
);
3508 if (x
>=0 && x
<rt
.right
) {
3509 child
->split_pos
= x
;
3510 resize_tree(child
, rt
.right
, rt
.bottom
);
3511 rt
.left
= x
-SPLIT_WIDTH
/2;
3512 rt
.right
= x
+SPLIT_WIDTH
/2+1;
3513 InvalidateRect(hwnd
, &rt
, FALSE
);
3514 UpdateWindow(child
->left
.hwnd
);
3516 UpdateWindow(child
->right
.hwnd
);
3522 #ifndef _NO_EXTENSIONS
3523 case WM_GETMINMAXINFO
:
3524 DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
3526 {LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
3528 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
3529 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
3531 #endif /* _NO_EXTENSIONS */
3534 SetCurrentDirectory(child
->path
);
3535 SetFocus(child
->focus_pane
? child
->right
.hwnd
: child
->left
.hwnd
);
3538 case WM_DISPATCH_COMMAND
: {
3539 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
3541 switch(LOWORD(wparam
)) {
3542 case ID_WINDOW_NEW
: {
3543 ChildWnd
* new_child
= alloc_child_window(child
->path
, NULL
, hwnd
);
3545 if (!create_child_window(new_child
))
3551 scan_entry(child
, pane
->cur
, hwnd
);
3555 activate_entry(child
, pane
, hwnd
);
3558 case ID_FILE_MOVE
: {
3559 TCHAR new_name
[BUFFER_LEN
], old_name
[BUFFER_LEN
];
3562 int ret
= DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_SELECT_DESTINATION
), hwnd
, DestinationDlgProc
, (LPARAM
)new_name
);
3566 if (new_name
[0]!='/' && new_name
[1]!=':') {
3567 get_path(pane
->cur
->up
, old_name
);
3568 len
= lstrlen(old_name
);
3570 if (old_name
[len
-1]!='\\' && old_name
[len
-1]!='/') {
3571 old_name
[len
++] = '/';
3572 old_name
[len
] = '\n';
3575 lstrcpy(&old_name
[len
], new_name
);
3576 lstrcpy(new_name
, old_name
);
3579 get_path(pane
->cur
, old_name
);
3581 if (MoveFileEx(old_name
, new_name
, MOVEFILE_COPY_ALLOWED
)) {
3582 if (pane
->treePane
) {
3583 pane
->root
->scanned
= FALSE
;
3584 pane
->cur
= pane
->root
;
3585 activate_entry(child
, pane
, hwnd
);
3588 scan_entry(child
, pane
->root
, hwnd
);
3591 display_error(hwnd
, GetLastError());
3595 return pane_command(pane
, LOWORD(wparam
));
3601 Pane
* pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
3603 switch(HIWORD(wparam
)) {
3604 case LBN_SELCHANGE
: {
3605 int idx
= ListBox_GetCurSel(pane
->hwnd
);
3606 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, idx
);
3608 if (pane
== &child
->left
)
3609 set_curdir(child
, entry
, hwnd
);
3615 activate_entry(child
, pane
, hwnd
);
3620 #ifndef _NO_EXTENSIONS
3622 NMHDR
* pnmh
= (NMHDR
*) lparam
;
3623 return pane_notify(pnmh
->idFrom
==IDW_HEADER_LEFT
? &child
->left
: &child
->right
, pnmh
);}
3626 #ifdef _SHELL_FOLDERS
3627 case WM_CONTEXTMENU
: {
3631 /* first select the current item in the listbox */
3632 HWND hpanel
= (HWND
) wparam
;
3633 POINTS
* ppos
= &MAKEPOINTS(lparam
);
3634 POINT pt
; POINTSTOPOINT(pt
, *ppos
);
3635 ScreenToClient(hpanel
, &pt
);
3636 SendMessage(hpanel
, WM_LBUTTONDOWN
, 0, MAKELONG(pt
.x
, pt
.y
));
3637 SendMessage(hpanel
, WM_LBUTTONUP
, 0, MAKELONG(pt
.x
, pt
.y
));
3639 /* now create the popup menu using shell namespace and IContextMenu */
3640 pane
= GetFocus()==child
->left
.hwnd
? &child
->left
: &child
->right
;
3641 idx
= ListBox_GetCurSel(pane
->hwnd
);
3645 Entry
* entry
= (Entry
*) ListBox_GetItemData(pane
->hwnd
, idx
);
3647 LPITEMIDLIST pidl_abs
= get_to_absolute_pidl(entry
, hwnd
);
3650 IShellFolder
* parentFolder
;
3651 LPCITEMIDLIST pidlLast
;
3653 /* get and use the parent folder to display correct context menu in all cases */
3654 if (SUCCEEDED(SHBindToParent(pidl_abs
, &IID_IShellFolder
, (LPVOID
*)&parentFolder
, &pidlLast
))) {
3655 hr
= ShellFolderContextMenu(parentFolder
, hwnd
, 1, &pidlLast
, ppos
->x
, ppos
->y
);
3657 (*parentFolder
->lpVtbl
->Release
)(parentFolder
);
3660 (*Globals
.iMalloc
->lpVtbl
->Free
)(Globals
.iMalloc
, pidl_abs
);
3667 if (wparam
!= SIZE_MINIMIZED
)
3668 resize_tree(child
, LOWORD(lparam
), HIWORD(lparam
));
3672 return DefMDIChildProc(hwnd
, nmsg
, wparam
, lparam
);
3679 LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3681 ChildWnd
* child
= (ChildWnd
*) GetWindowLong(GetParent(hwnd
), GWL_USERDATA
);
3682 Pane
* pane
= (Pane
*) GetWindowLong(hwnd
, GWL_USERDATA
);
3686 #ifndef _NO_EXTENSIONS
3693 child
->focus_pane
= pane
==&child
->right
? 1: 0;
3694 ListBox_SetSel(hwnd
, TRUE
, 1);
3695 /*TODO: check menu items */
3699 if (wparam
== VK_TAB
) {
3700 /*TODO: SetFocus(Globals.hdrivebar) */
3701 SetFocus(child
->focus_pane
? child
->left
.hwnd
: child
->right
.hwnd
);
3705 return CallWindowProc(g_orgTreeWndProc
, hwnd
, nmsg
, wparam
, lparam
);
3709 static void InitInstance(HINSTANCE hinstance
)
3715 INITCOMMONCONTROLSEX icc
= {
3716 sizeof(INITCOMMONCONTROLSEX
),
3722 setlocale(LC_COLLATE
, ""); /* set collating rules to local settings for compareName */
3724 InitCommonControlsEx(&icc
);
3727 /* register frame window class */
3729 wcFrame
.cbSize
= sizeof(WNDCLASSEX
);
3731 wcFrame
.lpfnWndProc
= FrameWndProc
;
3732 wcFrame
.cbClsExtra
= 0;
3733 wcFrame
.cbWndExtra
= 0;
3734 wcFrame
.hInstance
= hinstance
;
3735 wcFrame
.hIcon
= LoadIcon(hinstance
, MAKEINTRESOURCE(IDI_WINEFILE
));
3736 wcFrame
.hCursor
= LoadCursor(0, IDC_ARROW
);
3737 wcFrame
.hbrBackground
= 0;
3738 wcFrame
.lpszMenuName
= 0;
3739 wcFrame
.lpszClassName
= WINEFILEFRAME
;
3740 wcFrame
.hIconSm
= (HICON
)LoadImage(hinstance
,
3741 MAKEINTRESOURCE(IDI_WINEFILE
),
3743 GetSystemMetrics(SM_CXSMICON
),
3744 GetSystemMetrics(SM_CYSMICON
),
3747 Globals
.hframeClass
= RegisterClassEx(&wcFrame
);
3750 /* register tree windows class */
3752 wcChild
.style
= CS_CLASSDC
|CS_DBLCLKS
|CS_VREDRAW
;
3753 wcChild
.lpfnWndProc
= ChildWndProc
;
3754 wcChild
.cbClsExtra
= 0;
3755 wcChild
.cbWndExtra
= 0;
3756 wcChild
.hInstance
= hinstance
;
3758 wcChild
.hCursor
= LoadCursor(0, IDC_ARROW
);
3759 wcChild
.hbrBackground
= 0;
3760 wcChild
.lpszMenuName
= 0;
3761 wcChild
.lpszClassName
= WINEFILETREE
;
3763 hChildClass
= RegisterClass(&wcChild
);
3766 Globals
.haccel
= LoadAccelerators(hinstance
, MAKEINTRESOURCE(IDA_WINEFILE
));
3768 Globals
.hfont
= CreateFont(-MulDiv(8,GetDeviceCaps(hdc
,LOGPIXELSY
),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("MS Shell Dlg"));
3772 Globals
.hInstance
= hinstance
;
3774 #ifdef _SHELL_FOLDERS
3776 CoGetMalloc(MEMCTX_TASK
, &Globals
.iMalloc
);
3777 SHGetDesktopFolder(&Globals
.iDesktop
);
3778 Globals
.cfStrFName
= RegisterClipboardFormat(CFSTR_FILENAME
);
3783 void show_frame(HWND hwndParent
, int cmdshow
)
3785 TCHAR path
[MAX_PATH
], b1
[BUFFER_LEN
];
3787 HMENU hMenuFrame
, hMenuWindow
;
3789 CLIENTCREATESTRUCT ccs
;
3791 if (Globals
.hMainWnd
)
3794 Globals
.hwndParent
= hwndParent
;
3796 hMenuFrame
= LoadMenu(Globals
.hInstance
, MAKEINTRESOURCE(IDM_WINEFILE
));
3797 hMenuWindow
= GetSubMenu(hMenuFrame
, GetMenuItemCount(hMenuFrame
)-2);
3799 Globals
.hMenuFrame
= hMenuFrame
;
3800 Globals
.hMenuView
= GetSubMenu(hMenuFrame
, 3);
3801 Globals
.hMenuOptions
= GetSubMenu(hMenuFrame
, 4);
3803 ccs
.hWindowMenu
= hMenuWindow
;
3804 ccs
.idFirstChild
= IDW_FIRST_CHILD
;
3807 /* create main window */
3808 Globals
.hMainWnd
= CreateWindowEx(0, (LPCTSTR
)(int)Globals
.hframeClass
, RS(b1
,IDS_WINE_FILE
), WS_OVERLAPPEDWINDOW
,
3809 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
3810 hwndParent
, Globals
.hMenuFrame
, Globals
.hInstance
, 0/*lpParam*/);
3813 Globals
.hmdiclient
= CreateWindowEx(0, TEXT("MDICLIENT"), NULL
,
3814 WS_CHILD
|WS_CLIPCHILDREN
|WS_VSCROLL
|WS_HSCROLL
|WS_VISIBLE
|WS_BORDER
,
3816 Globals
.hMainWnd
, 0, Globals
.hInstance
, &ccs
);
3820 TBBUTTON drivebarBtn
= {0, 0, TBSTATE_ENABLED
, BTNS_SEP
, {0, 0}, 0, 0};
3824 Globals
.hdrivebar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
,
3825 IDW_DRIVEBAR
, 2, Globals
.hInstance
, IDB_DRIVEBAR
, &drivebarBtn
,
3826 1, 16, 13, 16, 13, sizeof(TBBUTTON
));
3827 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_DRIVE_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
3829 GetLogicalDriveStrings(BUFFER_LEN
, Globals
.drives
);
3831 drivebarBtn
.fsStyle
= BTNS_BUTTON
;
3833 #ifndef _NO_EXTENSIONS
3835 /* insert unix file system button */
3836 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)TEXT("/\0"));
3838 drivebarBtn
.idCommand
= ID_DRIVE_UNIX_FS
;
3839 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3840 drivebarBtn
.iString
++;
3842 #ifdef _SHELL_FOLDERS
3843 /* insert shell namespace button */
3844 load_string(b1
, IDS_SHELL
);
3845 b1
[lstrlen(b1
)+1] = '\0';
3846 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b1
);
3848 drivebarBtn
.idCommand
= ID_DRIVE_SHELL_NS
;
3849 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3850 drivebarBtn
.iString
++;
3853 /* register windows drive root strings */
3854 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)Globals
.drives
);
3857 drivebarBtn
.idCommand
= ID_DRIVE_FIRST
;
3859 for(p
=Globals
.drives
; *p
; ) {
3860 #ifdef _NO_EXTENSIONS
3861 /* insert drive letter */
3862 TCHAR b
[3] = {tolower(*p
)};
3863 SendMessage(Globals
.hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)b
);
3865 switch(GetDriveType(p
)) {
3866 case DRIVE_REMOVABLE
: drivebarBtn
.iBitmap
= 1; break;
3867 case DRIVE_CDROM
: drivebarBtn
.iBitmap
= 3; break;
3868 case DRIVE_REMOTE
: drivebarBtn
.iBitmap
= 4; break;
3869 case DRIVE_RAMDISK
: drivebarBtn
.iBitmap
= 5; break;
3870 default:/*DRIVE_FIXED*/ drivebarBtn
.iBitmap
= 2;
3873 SendMessage(Globals
.hdrivebar
, TB_INSERTBUTTON
, btn
++, (LPARAM
)&drivebarBtn
);
3874 drivebarBtn
.idCommand
++;
3875 drivebarBtn
.iString
++;
3882 TBBUTTON toolbarBtns
[] = {
3883 {0, 0, 0, BTNS_SEP
, {0, 0}, 0, 0},
3884 {0, ID_WINDOW_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
3885 {1, ID_WINDOW_CASCADE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
3886 {2, ID_WINDOW_TILE_HORZ
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
3887 {3, ID_WINDOW_TILE_VERT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
3889 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON},
3890 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON},
3893 Globals
.htoolbar
= CreateToolbarEx(Globals
.hMainWnd
, WS_CHILD
|WS_VISIBLE
,
3894 IDW_TOOLBAR
, 2, Globals
.hInstance
, IDB_TOOLBAR
, toolbarBtns
,
3895 sizeof(toolbarBtns
)/sizeof(TBBUTTON
), 16, 15, 16, 15, sizeof(TBBUTTON
));
3896 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_TOOL_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
3899 Globals
.hstatusbar
= CreateStatusWindow(WS_CHILD
|WS_VISIBLE
, 0, Globals
.hMainWnd
, IDW_STATUSBAR
);
3900 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
3902 /* CreateStatusWindow does not accept WS_BORDER
3903 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
3904 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
3905 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
3907 /*TODO: read paths and window placements from registry */
3908 GetCurrentDirectory(MAX_PATH
, path
);
3910 ShowWindow(Globals
.hMainWnd
, cmdshow
);
3912 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
3913 /* Shell Namespace as default: */
3914 child
= alloc_child_window(path
, get_path_pidl(path
,Globals
.hMainWnd
), Globals
.hMainWnd
);
3916 child
= alloc_child_window(path
, NULL
, Globals
.hMainWnd
);
3919 child
->pos
.showCmd
= SW_SHOWMAXIMIZED
;
3920 child
->pos
.rcNormalPosition
.left
= 0;
3921 child
->pos
.rcNormalPosition
.top
= 0;
3922 child
->pos
.rcNormalPosition
.right
= 320;
3923 child
->pos
.rcNormalPosition
.bottom
= 280;
3925 if (!create_child_window(child
))
3928 SetWindowPlacement(child
->hwnd
, &child
->pos
);
3930 Globals
.himl
= ImageList_LoadBitmap(Globals
.hInstance
, MAKEINTRESOURCE(IDB_IMAGES
), 16, 0, RGB(0,255,0));
3932 Globals
.prescan_node
= FALSE
;
3934 UpdateWindow(Globals
.hMainWnd
);
3939 #ifdef _SHELL_FOLDERS
3940 (*Globals
.iDesktop
->lpVtbl
->Release
)(Globals
.iDesktop
);
3941 (*Globals
.iMalloc
->lpVtbl
->Release
)(Globals
.iMalloc
);
3945 ImageList_Destroy(Globals
.himl
);
3949 /* search for already running win[e]files */
3951 static int g_foundPrevInstance
= 0;
3953 static BOOL CALLBACK
EnumWndProc(HWND hwnd
, LPARAM lparam
)
3957 GetClassName(hwnd
, cls
, 128);
3959 if (!lstrcmp(cls
, (LPCTSTR
)lparam
)) {
3960 g_foundPrevInstance
++;
3967 /* search for window of given class name to allow only one running instance */
3968 int find_window_class(LPCTSTR classname
)
3970 EnumWindows(EnumWndProc
, (LPARAM
)classname
);
3972 if (g_foundPrevInstance
)
3979 int winefile_main(HINSTANCE hinstance
, HWND hwndParent
, int cmdshow
)
3983 InitInstance(hinstance
);
3985 if (cmdshow
== SW_SHOWNORMAL
)
3986 /*TODO: read window placement from registry */
3987 cmdshow
= SW_MAXIMIZE
;
3989 show_frame(hwndParent
, cmdshow
);
3991 while(GetMessage(&msg
, 0, 0, 0)) {
3992 if (Globals
.hmdiclient
&& TranslateMDISysAccel(Globals
.hmdiclient
, &msg
))
3995 if (Globals
.hMainWnd
&& TranslateAccelerator(Globals
.hMainWnd
, Globals
.haccel
, &msg
))
3998 TranslateMessage(&msg
);
3999 DispatchMessage(&msg
);
4008 int APIENTRY
WinMain(HINSTANCE hinstance
,
4009 HINSTANCE previnstance
,
4013 #ifdef _NO_EXTENSIONS
4014 if (find_window_class(WINEFILEFRAME
))
4018 winefile_main(hinstance
, 0, cmdshow
);