Remove no longer necessary includes <signal.h>, <wait.h>.
[wine] / programs / winefile / winefile.c
1 /*
2  * Winefile
3  *
4  * Copyright 2000 Martin Fuchs
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #ifndef _WIN32
22 #include "config.h"
23 #include "wine/port.h"
24 #endif
25
26 #include <locale.h>
27
28 #define NONAMELESSUNION
29 #include "winefile.h"
30 #include "resource.h"
31
32 /* for read_directory_unix() */
33 #if !defined(_NO_EXTENSIONS) && !defined(_WIN32)
34 #include <dirent.h>
35 #include <sys/stat.h>
36 #include <unistd.h>
37 #include <time.h>
38 #endif
39
40 #ifdef _NO_EXTENSIONS
41 #undef _LEFT_FILES
42 #endif
43
44 #ifndef _MAX_PATH
45 #define _MAX_DRIVE          3
46 #define _MAX_FNAME          256
47 #define _MAX_DIR            _MAX_FNAME
48 #define _MAX_EXT            _MAX_FNAME
49 #define _MAX_PATH           260
50 #endif
51
52 #ifdef NONAMELESSUNION
53 #define UNION_MEMBER(x) DUMMYUNIONNAME.##x
54 #else
55 #define UNION_MEMBER(x) x
56 #endif
57
58
59 #ifdef _SHELL_FOLDERS
60 #define DEFAULT_SPLIT_POS       300;
61 #else
62 #define DEFAULT_SPLIT_POS       200;
63 #endif
64
65
66 WINEFILE_GLOBALS Globals;
67
68 extern void WineLicense(HWND hwnd);
69 extern void WineWarranty(HWND hwnd);
70
71 enum ENTRY_TYPE {
72         ET_WINDOWS,
73         ET_UNIX,
74 #ifdef _SHELL_FOLDERS
75         ET_SHELL
76 #endif
77 };
78
79 typedef struct _Entry {
80         struct _Entry*  next;
81         struct _Entry*  down;
82         struct _Entry*  up;
83
84         BOOL                    expanded;
85         BOOL                    scanned;
86         int                             level;
87
88         WIN32_FIND_DATA data;
89
90 #ifndef _NO_EXTENSIONS
91         BY_HANDLE_FILE_INFORMATION bhfi;
92         BOOL                    bhfi_valid;
93         enum ENTRY_TYPE etype;
94 #endif
95 #ifdef _SHELL_FOLDERS
96         LPITEMIDLIST    pidl;
97         IShellFolder*   folder;
98         HICON                   hicon;
99 #endif
100 } Entry;
101
102 typedef struct {
103         Entry   entry;
104         TCHAR   path[MAX_PATH];
105         TCHAR   volname[_MAX_FNAME];
106         TCHAR   fs[_MAX_DIR];
107         DWORD   drive_type;
108         DWORD   fs_flags;
109 } Root;
110
111 enum COLUMN_FLAGS {
112         COL_SIZE                = 0x01,
113         COL_DATE                = 0x02,
114         COL_TIME                = 0x04,
115         COL_ATTRIBUTES  = 0x08,
116         COL_DOSNAMES    = 0x10,
117 #ifdef _NO_EXTENSIONS
118         COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES
119 #else
120         COL_INDEX               = 0x20,
121         COL_LINKS               = 0x40,
122         COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES|COL_INDEX|COL_LINKS
123 #endif
124 };
125
126 typedef enum {
127         SORT_NAME,
128         SORT_EXT,
129         SORT_SIZE,
130         SORT_DATE
131 } SORT_ORDER;
132
133 typedef struct {
134         HWND    hwnd;
135 #ifndef _NO_EXTENSIONS
136         HWND    hwndHeader;
137 #endif
138
139 #ifndef _NO_EXTENSIONS
140 #define COLUMNS 10
141 #else
142 #define COLUMNS 5
143 #endif
144         int             widths[COLUMNS];
145         int             positions[COLUMNS+1];
146
147         BOOL    treePane;
148         int             visible_cols;
149         Entry*  root;
150         Entry*  cur;
151 } Pane;
152
153 typedef struct {
154         HWND    hwnd;
155         Pane    left;
156         Pane    right;
157         int             focus_pane;             /* 0: left  1: right */
158         WINDOWPLACEMENT pos;
159         int             split_pos;
160         BOOL    header_wdths_ok;
161
162         TCHAR   path[MAX_PATH];
163         Root    root;
164
165         SORT_ORDER sortOrder;
166 } ChildWnd;
167
168
169 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd);
170 static void set_curdir(ChildWnd* child, Entry* entry, HWND hwnd);
171
172 LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
173 LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
174 LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
175
176
177 static void display_error(HWND hwnd, DWORD error)
178 {
179         PTSTR msg;
180
181         if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
182                 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL))
183                 MessageBox(hwnd, msg, TEXT("Winefile"), MB_OK);
184         else
185                 MessageBox(hwnd, TEXT("Error"), TEXT("Winefile"), MB_OK);
186
187         LocalFree(msg);
188 }
189
190
191 /* allocate and initialise a directory entry */
192 static Entry* alloc_entry()
193 {
194         Entry* entry = (Entry*) malloc(sizeof(Entry));
195
196 #ifdef _SHELL_FOLDERS
197         entry->pidl = NULL;
198         entry->folder = NULL;
199         entry->hicon = 0;
200 #endif
201
202         return entry;
203 }
204
205 /* free a directory entry */
206 static void free_entry(Entry* entry)
207 {
208 #ifdef _SHELL_FOLDERS
209         if (entry->hicon && entry->hicon!=(HICON)-1)
210                 DestroyIcon(entry->hicon);
211
212         if (entry->folder && entry->folder!=Globals.iDesktop)
213                 (*entry->folder->lpVtbl->Release)(entry->folder);
214
215         if (entry->pidl)
216                 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, entry->pidl);
217 #endif
218
219         free(entry);
220 }
221
222 /* recursively free all child entries */
223 static void free_entries(Entry* dir)
224 {
225         Entry *entry, *next=dir->down;
226
227         if (next) {
228                 dir->down = 0;
229
230                 do {
231                         entry = next;
232                         next = entry->next;
233
234                         free_entries(entry);
235                         free_entry(entry);
236                 } while(next);
237         }
238 }
239
240
241 static void read_directory_win(Entry* dir, LPCTSTR path)
242 {
243         Entry* first_entry = NULL;
244         Entry* last = NULL;
245         Entry* entry;
246
247         int level = dir->level + 1;
248         WIN32_FIND_DATA w32fd;
249         HANDLE hFind;
250 #ifndef _NO_EXTENSIONS
251         HANDLE hFile;
252 #endif
253
254         TCHAR buffer[MAX_PATH], *p;
255         for(p=buffer; *path; )
256                 *p++ = *path++;
257
258         lstrcpy(p, TEXT("\\*"));
259
260         hFind = FindFirstFile(buffer, &w32fd);
261
262         if (hFind != INVALID_HANDLE_VALUE) {
263                 do {
264                         entry = alloc_entry();
265
266                         if (!first_entry)
267                                 first_entry = entry;
268
269                         if (last)
270                                 last->next = entry;
271
272                         memcpy(&entry->data, &w32fd, sizeof(WIN32_FIND_DATA));
273                         entry->down = NULL;
274                         entry->up = dir;
275                         entry->expanded = FALSE;
276                         entry->scanned = FALSE;
277                         entry->level = level;
278
279 #ifdef _NO_EXTENSIONS
280                         /* hide directory entry "." */
281                         if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
282                                 LPCTSTR name = entry->data.cFileName;
283
284                                 if (name[0]=='.' && name[1]=='\0')
285                                         continue;
286                         }
287 #else
288                         entry->etype = ET_WINDOWS;
289                         entry->bhfi_valid = FALSE;
290
291                         lstrcpy(p+1, entry->data.cFileName);
292
293                         hFile = CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
294                                                                 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
295
296                         if (hFile != INVALID_HANDLE_VALUE) {
297                                 if (GetFileInformationByHandle(hFile, &entry->bhfi))
298                                         entry->bhfi_valid = TRUE;
299
300                                 CloseHandle(hFile);
301                         }
302 #endif
303
304                         last = entry;
305                 } while(FindNextFile(hFind, &entry->data));
306
307                 last->next = NULL;
308
309                 FindClose(hFind);
310         }
311
312         dir->down = first_entry;
313         dir->scanned = TRUE;
314 }
315
316
317 static Entry* find_entry_win(Entry* dir, LPCTSTR name)
318 {
319         Entry* entry;
320
321         for(entry=dir->down; entry; entry=entry->next) {
322                 LPCTSTR p = name;
323                 LPCTSTR q = entry->data.cFileName;
324
325                 do {
326                         if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
327                                 return entry;
328                 } while(tolower(*p++) == tolower(*q++));
329
330                 p = name;
331                 q = entry->data.cAlternateFileName;
332
333                 do {
334                         if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
335                                 return entry;
336                 } while(tolower(*p++) == tolower(*q++));
337         }
338
339         return 0;
340 }
341
342
343 static Entry* read_tree_win(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
344 {
345         TCHAR buffer[MAX_PATH];
346         Entry* entry = &root->entry;
347         LPCTSTR s = path;
348         PTSTR d = buffer;
349
350         HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
351
352 #ifndef _NO_EXTENSIONS
353         entry->etype = ET_WINDOWS;
354 #endif
355
356         while(entry) {
357                 while(*s && *s!=TEXT('\\') && *s!=TEXT('/'))
358                         *d++ = *s++;
359
360                 while(*s==TEXT('\\') || *s==TEXT('/'))
361                         s++;
362
363                 *d++ = TEXT('\\');
364                 *d = TEXT('\0');
365
366                 read_directory(entry, buffer, sortOrder, hwnd);
367
368                 if (entry->down)
369                         entry->expanded = TRUE;
370
371                 if (!*s)
372                         break;
373
374                 entry = find_entry_win(entry, s);
375         }
376
377         SetCursor(old_cursor);
378
379         return entry;
380 }
381
382
383 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
384
385 BOOL time_to_filetime(const time_t* t, FILETIME* ftime)
386 {
387         struct tm* tm = gmtime(t);
388         SYSTEMTIME stime;
389
390         if (!tm)
391                 return FALSE;
392
393         stime.wYear = tm->tm_year+1900;
394         stime.wMonth = tm->tm_mon+1;
395         /*      stime.wDayOfWeek */
396         stime.wDay = tm->tm_mday;
397         stime.wHour = tm->tm_hour;
398         stime.wMinute = tm->tm_min;
399         stime.wSecond = tm->tm_sec;
400
401         return SystemTimeToFileTime(&stime, ftime);
402 }
403
404 static void read_directory_unix(Entry* dir, LPCTSTR path)
405 {
406         Entry* first_entry = NULL;
407         Entry* last = NULL;
408         Entry* entry;
409
410         int level = dir->level + 1;
411
412         DIR* pdir = opendir(path);
413
414         if (pdir) {
415                 struct stat st;
416                 struct dirent* ent;
417                 TCHAR buffer[MAX_PATH], *p;
418
419                 for(p=buffer; *path; )
420                         *p++ = *path++;
421
422                 if (p==buffer || p[-1]!='/')
423                         *p++ = '/';
424
425                 while((ent=readdir(pdir))) {
426                         entry = alloc_entry();
427
428                         if (!first_entry)
429                                 first_entry = entry;
430
431                         if (last)
432                                 last->next = entry;
433
434                         entry->etype = ET_UNIX;
435
436                         lstrcpy(entry->data.cFileName, ent->d_name);
437                         entry->data.dwFileAttributes = ent->d_name[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0;
438
439                         strcpy(p, ent->d_name);
440
441                         if (!stat(buffer, &st)) {
442                                 if (S_ISDIR(st.st_mode))
443                                         entry->data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
444
445                                 entry->data.nFileSizeLow = st.st_size & 0xFFFFFFFF;
446                                 entry->data.nFileSizeHigh = st.st_size >> 32;
447
448                                 memset(&entry->data.ftCreationTime, 0, sizeof(FILETIME));
449                                 time_to_filetime(&st.st_atime, &entry->data.ftLastAccessTime);
450                                 time_to_filetime(&st.st_mtime, &entry->data.ftLastWriteTime);
451
452                                 entry->bhfi.nFileIndexLow = ent->d_ino;
453                                 entry->bhfi.nFileIndexHigh = 0;
454
455                                 entry->bhfi.nNumberOfLinks = st.st_nlink;
456
457                                 entry->bhfi_valid = TRUE;
458                         } else {
459                                 entry->data.nFileSizeLow = 0;
460                                 entry->data.nFileSizeHigh = 0;
461                                 entry->bhfi_valid = FALSE;
462                         }
463
464                         entry->down = NULL;
465                         entry->up = dir;
466                         entry->expanded = FALSE;
467                         entry->scanned = FALSE;
468                         entry->level = level;
469
470                         last = entry;
471                 }
472
473                 last->next = NULL;
474
475                 closedir(pdir);
476         }
477
478         dir->down = first_entry;
479         dir->scanned = TRUE;
480 }
481
482 static Entry* find_entry_unix(Entry* dir, LPCTSTR name)
483 {
484         Entry* entry;
485
486         for(entry=dir->down; entry; entry=entry->next) {
487                 LPCTSTR p = name;
488                 LPCTSTR q = entry->data.cFileName;
489
490                 do {
491                         if (!*p || *p==TEXT('/'))
492                                 return entry;
493                 } while(*p++ == *q++);
494         }
495
496         return 0;
497 }
498
499 static Entry* read_tree_unix(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
500 {
501         TCHAR buffer[MAX_PATH];
502         Entry* entry = &root->entry;
503         LPCTSTR s = path;
504         PTSTR d = buffer;
505
506         HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
507
508         entry->etype = ET_UNIX;
509
510         while(entry) {
511                 while(*s && *s!=TEXT('/'))
512                         *d++ = *s++;
513
514                 while(*s == TEXT('/'))
515                         s++;
516
517                 *d++ = TEXT('/');
518                 *d = TEXT('\0');
519
520                 read_directory(entry, buffer, sortOrder, hwnd);
521
522                 if (entry->down)
523                         entry->expanded = TRUE;
524
525                 if (!*s)
526                         break;
527
528                 entry = find_entry_unix(entry, s);
529         }
530
531         SetCursor(old_cursor);
532
533         return entry;
534 }
535
536 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
537
538
539 #ifdef _SHELL_FOLDERS
540
541 #ifdef UNICODE
542 #define tcscpyn strcpyn
543 #define get_strret get_strretW
544 #define path_from_pidl path_from_pidlW
545 #else
546 #define tcscpyn wcscpyn
547 #define get_strret get_strretA
548 #define path_from_pidl path_from_pidlA
549 #endif
550
551
552 static LPSTR strcpyn(LPSTR dest, LPCSTR source, size_t count)
553 {
554  LPCSTR s;
555  LPSTR d = dest;
556
557  for(s=source; count&&(*d++=*s++); )
558   count--;
559
560  return dest;
561 }
562
563 static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
564 {
565  LPCWSTR s;
566  LPWSTR d = dest;
567
568  for(s=source; count&&(*d++=*s++); )
569   count--;
570
571  return dest;
572 }
573
574
575 static void get_strretA(STRRET* str, const SHITEMID* shiid, LPSTR buffer, int len)
576 {
577  switch(str->uType) {
578   case STRRET_WSTR:
579         WideCharToMultiByte(CP_ACP, 0, str->UNION_MEMBER(pOleStr), -1, buffer, len, NULL, NULL);
580         break;
581
582   case STRRET_OFFSET:
583         strcpyn(buffer, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), len);
584         break;
585
586   case STRRET_CSTR:
587         strcpyn(buffer, str->UNION_MEMBER(cStr), len);
588  }
589 }
590
591 static void get_strretW(STRRET* str, const SHITEMID* shiid, LPWSTR buffer, int len)
592 {
593  switch(str->uType) {
594   case STRRET_WSTR:
595         wcscpyn(buffer, str->UNION_MEMBER(pOleStr), len);
596         break;
597
598   case STRRET_OFFSET:
599         MultiByteToWideChar(CP_ACP, 0, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), -1, buffer, len);
600         break;
601
602   case STRRET_CSTR:
603         MultiByteToWideChar(CP_ACP, 0, str->UNION_MEMBER(cStr), -1, buffer, len);
604  }
605 }
606
607
608 static void free_strret(STRRET* str)
609 {
610         if (str->uType == STRRET_WSTR)
611                 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, str->UNION_MEMBER(pOleStr));
612 }
613
614
615 HRESULT name_from_pidl(IShellFolder* folder, LPITEMIDLIST pidl, LPTSTR buffer, int len, SHGDNF flags)
616 {
617         STRRET str;
618
619         HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, flags, &str);
620
621         if (SUCCEEDED(hr)) {
622                 get_strret(&str, &pidl->mkid, buffer, len);
623                 free_strret(&str);
624         } else
625                 buffer[0] = '\0';
626
627         return hr;
628 }
629
630
631 HRESULT path_from_pidlA(IShellFolder* folder, LPITEMIDLIST pidl, LPSTR buffer, int len)
632 {
633         STRRET str;
634
635          /* SHGDN_FORPARSING: get full path of id list */
636         HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, SHGDN_FORPARSING, &str);
637
638         if (SUCCEEDED(hr)) {
639                 get_strretA(&str, &pidl->mkid, buffer, len);
640                 free_strret(&str);
641         } else
642                 buffer[0] = '\0';
643
644         return hr;
645 }
646
647 HRESULT path_from_pidlW(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len)
648 {
649         STRRET str;
650
651          /* SHGDN_FORPARSING: get full path of id list */
652         HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, SHGDN_FORPARSING, &str);
653
654         if (SUCCEEDED(hr)) {
655                 get_strretW(&str, &pidl->mkid, buffer, len);
656                 free_strret(&str);
657         } else
658                 buffer[0] = '\0';
659
660         return hr;
661 }
662
663
664  /* create an item id list from a file system path */
665
666 static LPITEMIDLIST get_path_pidl(LPTSTR path, HWND hwnd)
667 {
668         LPITEMIDLIST pidl;
669         HRESULT hr;
670         ULONG len;
671
672 #ifdef UNICODE
673         LPWSTR buffer = path;
674 #else
675         WCHAR buffer[MAX_PATH];
676         MultiByteToWideChar(CP_ACP, 0, path, -1, buffer, MAX_PATH);
677 #endif
678
679         hr = (*Globals.iDesktop->lpVtbl->ParseDisplayName)(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
680         if (FAILED(hr))
681                 return NULL;
682
683         return pidl;
684 }
685
686
687  /* convert an item id list from relative to absolute (=relative to the desktop) format */
688
689 static LPITEMIDLIST get_to_absolute_pidl(Entry* entry, HWND hwnd)
690 {
691         if (entry->up && entry->up->etype==ET_SHELL) {
692                 IShellFolder* folder = entry->up->folder;
693                 WCHAR buffer[MAX_PATH];
694
695                 HRESULT hr = path_from_pidlW(folder, entry->pidl, buffer, MAX_PATH);
696
697                 if (SUCCEEDED(hr)) {
698                         LPITEMIDLIST pidl;
699                         ULONG len;
700
701                         hr = (*Globals.iDesktop->lpVtbl->ParseDisplayName)(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
702
703                         if (SUCCEEDED(hr))
704                                 return pidl;
705                 }
706         }
707
708         return entry->pidl;
709 }
710
711
712 HICON extract_icon(IShellFolder* folder, LPCITEMIDLIST pidl)
713 {
714         IExtractIcon* pExtract;
715
716         if (SUCCEEDED((*folder->lpVtbl->GetUIObjectOf)(folder, 0, 1, (LPCITEMIDLIST*)&pidl, &IID_IExtractIcon, 0, (LPVOID*)&pExtract))) {
717                 TCHAR path[_MAX_PATH];
718                 unsigned flags;
719                 HICON hicon;
720                 int idx;
721
722                 if (SUCCEEDED((*pExtract->lpVtbl->GetIconLocation)(pExtract, GIL_FORSHELL, path, _MAX_PATH, &idx, &flags))) {
723                         if (!(flags & GIL_NOTFILENAME)) {
724                                 if (idx == -1)
725                                         idx = 0;        /* special case for some control panel applications */
726
727                                 if ((int)ExtractIconEx(path, idx, 0, &hicon, 1) > 0)
728                                         flags &= ~GIL_DONTCACHE;
729                         } else {
730                                 HICON hIconLarge = 0;
731
732                                 HRESULT hr = (*pExtract->lpVtbl->Extract)(pExtract, path, idx, &hIconLarge, &hicon, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON)));
733
734                                 if (SUCCEEDED(hr))
735                                         DestroyIcon(hIconLarge);
736                         }
737
738                         return hicon;
739                 }
740         }
741
742         return 0;
743 }
744
745
746 static Entry* find_entry_shell(Entry* dir, LPITEMIDLIST pidl)
747 {
748         Entry* entry;
749
750         for(entry=dir->down; entry; entry=entry->next) {
751                 if (entry->pidl->mkid.cb == pidl->mkid.cb &&
752                         !memcmp(entry->pidl, pidl, entry->pidl->mkid.cb))
753                         return entry;
754         }
755
756         return 0;
757 }
758
759 static Entry* read_tree_shell(Root* root, LPITEMIDLIST pidl, SORT_ORDER sortOrder, HWND hwnd)
760 {
761         Entry* entry = &root->entry;
762         Entry* next;
763         LPITEMIDLIST next_pidl = pidl;
764         IShellFolder* folder;
765         IShellFolder* child = NULL;
766         HRESULT hr;
767
768         HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
769
770 #ifndef _NO_EXTENSIONS
771         entry->etype = ET_SHELL;
772 #endif
773
774         folder = Globals.iDesktop;
775
776         while(entry) {
777                 entry->pidl = next_pidl;
778                 entry->folder = folder;
779
780                 if (!pidl->mkid.cb)
781                         break;
782
783                  /* copy first element of item idlist */
784                 next_pidl = (*Globals.iMalloc->lpVtbl->Alloc)(Globals.iMalloc, pidl->mkid.cb+sizeof(USHORT));
785                 memcpy(next_pidl, pidl, pidl->mkid.cb);
786                 ((LPITEMIDLIST)((LPBYTE)next_pidl+pidl->mkid.cb))->mkid.cb = 0;
787
788                 hr = (*folder->lpVtbl->BindToObject)(folder, next_pidl, 0, &IID_IShellFolder, (void**)&child);
789                 if (!SUCCEEDED(hr))
790                         break;
791
792                 read_directory(entry, NULL, sortOrder, hwnd);
793
794                 if (entry->down)
795                         entry->expanded = TRUE;
796
797                 next = find_entry_shell(entry, next_pidl);
798                 if (!next)
799                         break;
800
801                 folder = child;
802                 entry = next;
803
804                  /* go to next element */
805                 pidl = (LPITEMIDLIST) ((LPBYTE)pidl+pidl->mkid.cb);
806         }
807
808         SetCursor(old_cursor);
809
810         return entry;
811 }
812
813
814 static void fill_w32fdata_shell(IShellFolder* folder, LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATA* w32fdata)
815 {
816         if (!(attribs & SFGAO_FILESYSTEM) ||
817                   FAILED(SHGetDataFromIDList(folder, pidl, SHGDFIL_FINDDATA, w32fdata, sizeof(WIN32_FIND_DATA)))) {
818                 WIN32_FILE_ATTRIBUTE_DATA fad;
819                 IDataObject* pDataObj;
820
821                 STGMEDIUM medium = {0, {0}, 0};
822                 FORMATETC fmt = {Globals.cfStrFName, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
823
824                 HRESULT hr = (*folder->lpVtbl->GetUIObjectOf)(folder, 0, 1, &pidl, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
825
826                 if (SUCCEEDED(hr)) {
827                         hr = (*pDataObj->lpVtbl->GetData)(pDataObj, &fmt, &medium);
828
829                         (*pDataObj->lpVtbl->Release)(pDataObj);
830
831                         if (SUCCEEDED(hr)) {
832                                 LPCTSTR path = (LPCTSTR)GlobalLock(medium.UNION_MEMBER(hGlobal));
833                                 UINT sem_org = SetErrorMode(SEM_FAILCRITICALERRORS);
834
835                                 if (GetFileAttributesEx(path, GetFileExInfoStandard, &fad)) {
836                                         w32fdata->dwFileAttributes = fad.dwFileAttributes;
837                                         w32fdata->ftCreationTime = fad.ftCreationTime;
838                                         w32fdata->ftLastAccessTime = fad.ftLastAccessTime;
839                                         w32fdata->ftLastWriteTime = fad.ftLastWriteTime;
840
841                                         if (!(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
842                                                 w32fdata->nFileSizeLow = fad.nFileSizeLow;
843                                                 w32fdata->nFileSizeHigh = fad.nFileSizeHigh;
844                                         }
845                                 }
846
847                                 SetErrorMode(sem_org);
848
849                                 GlobalUnlock(medium.UNION_MEMBER(hGlobal));
850                                 GlobalFree(medium.UNION_MEMBER(hGlobal));
851                         }
852                 }
853         }
854
855         if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER))
856                 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
857
858         if (attribs & SFGAO_READONLY)
859                 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
860
861         if (attribs & SFGAO_COMPRESSED)
862                 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_COMPRESSED;
863 }
864
865
866 static void read_directory_shell(Entry* dir, HWND hwnd)
867 {
868         IShellFolder* folder = dir->folder;
869         int level = dir->level + 1;
870         HRESULT hr;
871
872         IShellFolder* child;
873         IEnumIDList* idlist;
874
875         Entry* first_entry = NULL;
876         Entry* last = NULL;
877         Entry* entry;
878
879         if (!folder)
880                 return;
881
882         hr = (*folder->lpVtbl->EnumObjects)(folder, hwnd, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE, &idlist);
883
884         if (SUCCEEDED(hr)) {
885                 for(;;) {
886 #define FETCH_ITEM_COUNT        32
887                         LPITEMIDLIST pidls[FETCH_ITEM_COUNT];
888                         SFGAOF attribs;
889                         ULONG cnt = 0;
890                         ULONG n;
891
892                         memset(pidls, 0, sizeof(pidls));
893
894                         hr = (*idlist->lpVtbl->Next)(idlist, FETCH_ITEM_COUNT, pidls, &cnt);
895                         if (!SUCCEEDED(hr))
896                                 break;
897
898                         if (hr == S_FALSE)
899                                 break;
900
901                         for(n=0; n<cnt; ++n) {
902                                 entry = alloc_entry();
903
904                                 if (!first_entry)
905                                         first_entry = entry;
906
907                                 if (last)
908                                         last->next = entry;
909
910                                 memset(&entry->data, 0, sizeof(WIN32_FIND_DATA));
911                                 entry->bhfi_valid = FALSE;
912
913                                 attribs = ~SFGAO_FILESYSTEM;    /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
914
915                                 hr = (*folder->lpVtbl->GetAttributesOf)(folder, 1, (LPCITEMIDLIST*)&pidls[n], &attribs);
916
917                                 if (SUCCEEDED(hr)) {
918                                         if (attribs != (SFGAOF)~SFGAO_FILESYSTEM) {
919                                                 fill_w32fdata_shell(folder, pidls[n], attribs, &entry->data);
920
921                                                 entry->bhfi_valid = TRUE;
922                                         } else
923                                                 attribs = 0;
924                                 } else
925                                         attribs = 0;
926
927                                 entry->pidl = pidls[n];
928
929                                 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
930                                         hr = (*folder->lpVtbl->BindToObject)(folder, pidls[n], 0, &IID_IShellFolder, (void**)&child);
931
932                                         if (SUCCEEDED(hr))
933                                                 entry->folder = child;
934                                         else
935                                                 entry->folder = NULL;
936                                 }
937                                 else
938                                         entry->folder = NULL;
939
940                                 if (!entry->data.cFileName[0])
941                                         /*hr = */name_from_pidl(folder, pidls[n], entry->data.cFileName, MAX_PATH, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
942
943                                  /* get display icons for files and virtual objects */
944                                 if (!(entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
945                                         !(attribs & SFGAO_FILESYSTEM)) {
946                                         entry->hicon = extract_icon(folder, pidls[n]);
947
948                                         if (!entry->hicon)
949                                                 entry->hicon = (HICON)-1;       /* don't try again later */
950                                 }
951
952                                 entry->down = NULL;
953                                 entry->up = dir;
954                                 entry->expanded = FALSE;
955                                 entry->scanned = FALSE;
956                                 entry->level = level;
957
958 #ifndef _NO_EXTENSIONS
959                                 entry->etype = ET_SHELL;
960                                 entry->bhfi_valid = FALSE;
961 #endif
962
963                                 last = entry;
964                         }
965                 }
966
967                 (*idlist->lpVtbl->Release)(idlist);
968         }
969
970         if (last)
971                 last->next = NULL;
972
973         dir->down = first_entry;
974         dir->scanned = TRUE;
975 }
976
977 #endif /* _SHELL_FOLDERS */
978
979
980 /* directories first... */
981 static int compareType(const WIN32_FIND_DATA* fd1, const WIN32_FIND_DATA* fd2)
982 {
983         int dir1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
984         int dir2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
985
986         return dir2==dir1? 0: dir2<dir1? -1: 1;
987 }
988
989
990 static int compareName(const void* arg1, const void* arg2)
991 {
992         const WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
993         const WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
994
995         int cmp = compareType(fd1, fd2);
996         if (cmp)
997                 return cmp;
998
999         return lstrcmpi(fd1->cFileName, fd2->cFileName);
1000 }
1001
1002 static int compareExt(const void* arg1, const void* arg2)
1003 {
1004         const WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1005         const WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1006         const TCHAR *name1, *name2, *ext1, *ext2;
1007
1008         int cmp = compareType(fd1, fd2);
1009         if (cmp)
1010                 return cmp;
1011
1012         name1 = fd1->cFileName;
1013         name2 = fd2->cFileName;
1014
1015         ext1 = _tcsrchr(name1, TEXT('.'));
1016         ext2 = _tcsrchr(name2, TEXT('.'));
1017
1018         if (ext1)
1019                 ext1++;
1020         else
1021                 ext1 = TEXT("");
1022
1023         if (ext2)
1024                 ext2++;
1025         else
1026                 ext2 = TEXT("");
1027
1028         cmp = lstrcmpi(ext1, ext2);
1029         if (cmp)
1030                 return cmp;
1031
1032         return lstrcmpi(name1, name2);
1033 }
1034
1035 static int compareSize(const void* arg1, const void* arg2)
1036 {
1037         WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1038         WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1039
1040         int cmp = compareType(fd1, fd2);
1041         if (cmp)
1042                 return cmp;
1043
1044         cmp = fd2->nFileSizeHigh - fd1->nFileSizeHigh;
1045
1046         if (cmp < 0)
1047                 return -1;
1048         else if (cmp > 0)
1049                 return 1;
1050
1051         cmp = fd2->nFileSizeLow - fd1->nFileSizeLow;
1052
1053         return cmp<0? -1: cmp>0? 1: 0;
1054 }
1055
1056 static int compareDate(const void* arg1, const void* arg2)
1057 {
1058         WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1059         WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1060
1061         int cmp = compareType(fd1, fd2);
1062         if (cmp)
1063                 return cmp;
1064
1065         return CompareFileTime(&fd2->ftLastWriteTime, &fd1->ftLastWriteTime);
1066 }
1067
1068
1069 static int (*sortFunctions[])(const void* arg1, const void* arg2) = {
1070         compareName,    /* SORT_NAME */
1071         compareExt,             /* SORT_EXT */
1072         compareSize,    /* SORT_SIZE */
1073         compareDate             /* SORT_DATE */
1074 };
1075
1076
1077 static void SortDirectory(Entry* dir, SORT_ORDER sortOrder)
1078 {
1079         Entry* entry = dir->down;
1080         Entry** array, **p;
1081         int len;
1082
1083         len = 0;
1084         for(entry=dir->down; entry; entry=entry->next)
1085                 len++;
1086
1087         if (len) {
1088                 array = (Entry**) alloca(len*sizeof(Entry*));
1089
1090                 p = array;
1091                 for(entry=dir->down; entry; entry=entry->next)
1092                         *p++ = entry;
1093
1094                 /* call qsort with the appropriate compare function */
1095                 qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]);
1096
1097                 dir->down = array[0];
1098
1099                 for(p=array; --len; p++)
1100                         p[0]->next = p[1];
1101
1102                 (*p)->next = 0;
1103         }
1104 }
1105
1106
1107 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
1108 {
1109         TCHAR buffer[MAX_PATH];
1110         Entry* entry;
1111         LPCTSTR s;
1112         PTSTR d;
1113
1114 #ifdef _SHELL_FOLDERS
1115         if (dir->etype == ET_SHELL)
1116         {
1117                 read_directory_shell(dir, hwnd);
1118
1119                 if (Globals.prescan_node) {
1120                         s = path;
1121                         d = buffer;
1122
1123                         while(*s)
1124                                 *d++ = *s++;
1125
1126                         *d++ = TEXT('\\');
1127
1128                         for(entry=dir->down; entry; entry=entry->next)
1129                                 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1130                                         read_directory_shell(entry, hwnd);
1131                                         SortDirectory(entry, sortOrder);
1132                                 }
1133                 }
1134         }
1135         else
1136 #endif
1137 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1138         if (dir->etype == ET_UNIX)
1139         {
1140                 read_directory_unix(dir, path);
1141
1142                 if (Globals.prescan_node) {
1143                         s = path;
1144                         d = buffer;
1145
1146                         while(*s)
1147                                 *d++ = *s++;
1148
1149                         *d++ = TEXT('/');
1150
1151                         for(entry=dir->down; entry; entry=entry->next)
1152                                 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1153                                         lstrcpy(d, entry->data.cFileName);
1154                                         read_directory_unix(entry, buffer);
1155                                         SortDirectory(entry, sortOrder);
1156                                 }
1157                 }
1158         }
1159         else
1160 #endif
1161         {
1162                 read_directory_win(dir, path);
1163
1164                 if (Globals.prescan_node) {
1165                         s = path;
1166                         d = buffer;
1167
1168                         while(*s)
1169                                 *d++ = *s++;
1170
1171                         *d++ = TEXT('\\');
1172
1173                         for(entry=dir->down; entry; entry=entry->next)
1174                                 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1175                                         lstrcpy(d, entry->data.cFileName);
1176                                         read_directory_win(entry, buffer);
1177                                         SortDirectory(entry, sortOrder);
1178                                 }
1179                 }
1180         }
1181
1182         SortDirectory(dir, sortOrder);
1183 }
1184
1185
1186 static ChildWnd* alloc_child_window(LPCTSTR path, LPITEMIDLIST pidl, HWND hwnd)
1187 {
1188         TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
1189         ChildWnd* child = (ChildWnd*) malloc(sizeof(ChildWnd));
1190         Root* root = &child->root;
1191         Entry* entry;
1192
1193         memset(child, 0, sizeof(ChildWnd));
1194
1195         child->left.treePane = TRUE;
1196         child->left.visible_cols = 0;
1197
1198         child->right.treePane = FALSE;
1199 #ifndef _NO_EXTENSIONS
1200         child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
1201 #else
1202         child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES;
1203 #endif
1204
1205         child->pos.length = sizeof(WINDOWPLACEMENT);
1206         child->pos.flags = 0;
1207         child->pos.showCmd = SW_SHOWNORMAL;
1208         child->pos.rcNormalPosition.left = CW_USEDEFAULT;
1209         child->pos.rcNormalPosition.top = CW_USEDEFAULT;
1210         child->pos.rcNormalPosition.right = CW_USEDEFAULT;
1211         child->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
1212
1213         child->focus_pane = 0;
1214         child->split_pos = DEFAULT_SPLIT_POS;
1215         child->sortOrder = SORT_NAME;
1216         child->header_wdths_ok = FALSE;
1217
1218         if (path)
1219         {
1220                 lstrcpy(child->path, path);
1221
1222                 _tsplitpath(path, drv, dir, name, ext);
1223         }
1224
1225         root->entry.level = 0;
1226
1227 #ifdef _SHELL_FOLDERS
1228         if (pidl)
1229         {
1230                 root->drive_type = DRIVE_UNKNOWN;
1231                 lstrcpy(drv, TEXT("\\"));
1232                 lstrcpy(root->volname, TEXT("Desktop"));
1233                 root->fs_flags = 0;
1234                 lstrcpy(root->fs, TEXT("Shell"));
1235
1236                 entry = read_tree_shell(root, pidl, child->sortOrder, hwnd);
1237         }
1238         else
1239 #endif
1240 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1241         if (*path == '/')
1242         {
1243                 root->drive_type = GetDriveType(path);
1244
1245                 lstrcat(drv, TEXT("/"));
1246                 lstrcpy(root->volname, TEXT("root fs"));
1247                 root->fs_flags = 0;
1248                 lstrcpy(root->fs, TEXT("unixfs"));
1249
1250                 lstrcpy(root->path, TEXT("/"));
1251                 entry = read_tree_unix(root, path, child->sortOrder, hwnd);
1252         }
1253         else
1254 #endif
1255         {
1256                 root->drive_type = GetDriveType(path);
1257
1258                 lstrcat(drv, TEXT("\\"));
1259                 GetVolumeInformation(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
1260
1261                 lstrcpy(root->path, drv);
1262                 entry = read_tree_win(root, path, child->sortOrder, hwnd);
1263         }
1264
1265 #ifdef _SHELL_FOLDERS
1266         if (root->entry.etype == ET_SHELL)
1267                 lstrcpy(root->entry.data.cFileName, TEXT("Desktop"));
1268         else
1269 #endif
1270                 wsprintf(root->entry.data.cFileName, TEXT("%s - %s"), drv, root->fs);
1271
1272         root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1273
1274         child->left.root = &root->entry;
1275         child->right.root = NULL;
1276
1277         set_curdir(child, entry, hwnd);
1278
1279         return child;
1280 }
1281
1282
1283 /* free all memory associated with a child window */
1284 static void free_child_window(ChildWnd* child)
1285 {
1286         free_entries(&child->root.entry);
1287         free(child);
1288 }
1289
1290
1291 /* get full path of specified directory entry */
1292 static void get_path(Entry* dir, PTSTR path)
1293 {
1294         Entry* entry;
1295         int len = 0;
1296         int level = 0;
1297
1298 #ifdef _SHELL_FOLDERS
1299         if (dir->etype == ET_SHELL)
1300         {
1301                 SFGAOF attribs;
1302                 HRESULT hr = S_OK;
1303
1304                 path[0] = TEXT('\0');
1305
1306                 attribs = 0;
1307
1308                 if (dir->folder)
1309                         hr = (*dir->folder->lpVtbl->GetAttributesOf)(dir->folder, 1, (LPCITEMIDLIST*)&dir->pidl, &attribs);
1310
1311                 if (SUCCEEDED(hr) && (attribs&SFGAO_FILESYSTEM)) {
1312                         IShellFolder* parent = dir->up? dir->up->folder: Globals.iDesktop;
1313
1314                         hr = path_from_pidl(parent, dir->pidl, path, MAX_PATH);
1315                 }
1316         }
1317         else
1318 #endif
1319         {
1320                 for(entry=dir; entry; level++) {
1321                         LPCTSTR name;
1322                         int l;
1323
1324                         {
1325                                 LPCTSTR s;
1326                                 name = entry->data.cFileName;
1327                                 s = name;
1328
1329                                 for(l=0; *s && *s!=TEXT('/') && *s!=TEXT('\\'); s++)
1330                                         l++;
1331                         }
1332
1333                         if (entry->up) {
1334                                 if (l > 0) {
1335                                         memmove(path+l+1, path, len*sizeof(TCHAR));
1336                                         memcpy(path+1, name, l*sizeof(TCHAR));
1337                                         len += l+1;
1338
1339 #ifndef _NO_EXTENSIONS
1340                                         if (entry->etype == ET_UNIX)
1341                                                 path[0] = TEXT('/');
1342                                         else
1343 #endif
1344                                         path[0] = TEXT('\\');
1345                                 }
1346
1347                                 entry = entry->up;
1348                         } else {
1349                                 memmove(path+l, path, len*sizeof(TCHAR));
1350                                 memcpy(path, name, l*sizeof(TCHAR));
1351                                 len += l;
1352                                 break;
1353                         }
1354                 }
1355
1356                 if (!level) {
1357 #ifndef _NO_EXTENSIONS
1358                         if (entry->etype == ET_UNIX)
1359                                 path[len++] = TEXT('/');
1360                         else
1361 #endif
1362                                 path[len++] = TEXT('\\');
1363                 }
1364
1365                 path[len] = TEXT('\0');
1366         }
1367 }
1368
1369
1370 static void resize_frame_rect(HWND hwnd, PRECT prect)
1371 {
1372         int new_top;
1373         RECT rt;
1374
1375         if (IsWindowVisible(Globals.htoolbar)) {
1376                 SendMessage(Globals.htoolbar, WM_SIZE, 0, 0);
1377                 GetClientRect(Globals.htoolbar, &rt);
1378                 prect->top = rt.bottom+3;
1379                 prect->bottom -= rt.bottom+3;
1380         }
1381
1382         if (IsWindowVisible(Globals.hdrivebar)) {
1383                 SendMessage(Globals.hdrivebar, WM_SIZE, 0, 0);
1384                 GetClientRect(Globals.hdrivebar, &rt);
1385                 new_top = --prect->top + rt.bottom+3;
1386                 MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
1387                 prect->top = new_top;
1388                 prect->bottom -= rt.bottom+2;
1389         }
1390
1391         if (IsWindowVisible(Globals.hstatusbar)) {
1392                 int parts[] = {300, 500};
1393
1394                 SendMessage(Globals.hstatusbar, WM_SIZE, 0, 0);
1395                 SendMessage(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1396                 GetClientRect(Globals.hstatusbar, &rt);
1397                 prect->bottom -= rt.bottom;
1398         }
1399
1400         MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
1401 }
1402
1403 static void resize_frame(HWND hwnd, int cx, int cy)
1404 {
1405         RECT rect;
1406
1407         rect.left   = 0;
1408         rect.top    = 0;
1409         rect.right  = cx;
1410         rect.bottom = cy;
1411
1412         resize_frame_rect(hwnd, &rect);
1413 }
1414
1415 static void resize_frame_client(HWND hwnd)
1416 {
1417         RECT rect;
1418
1419         GetClientRect(hwnd, &rect);
1420
1421         resize_frame_rect(hwnd, &rect);
1422 }
1423
1424
1425 static HHOOK hcbthook;
1426 static ChildWnd* newchild = NULL;
1427
1428 LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
1429 {
1430         if (code==HCBT_CREATEWND && newchild) {
1431                 ChildWnd* child = newchild;
1432                 newchild = NULL;
1433
1434                 child->hwnd = (HWND) wparam;
1435                 SetWindowLong(child->hwnd, GWL_USERDATA, (LPARAM)child);
1436         }
1437
1438         return CallNextHookEx(hcbthook, code, wparam, lparam);
1439 }
1440
1441 static HWND create_child_window(ChildWnd* child)
1442 {
1443         MDICREATESTRUCT mcs;
1444         int idx;
1445
1446         mcs.szClass = WINEFILETREE;
1447         mcs.szTitle = (LPTSTR)child->path;
1448         mcs.hOwner  = Globals.hInstance;
1449         mcs.x       = child->pos.rcNormalPosition.left;
1450         mcs.y       = child->pos.rcNormalPosition.top;
1451         mcs.cx      = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
1452         mcs.cy      = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
1453         mcs.style   = 0;
1454         mcs.lParam  = 0;
1455
1456         hcbthook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId());
1457
1458         newchild = child;
1459         child->hwnd = (HWND) SendMessage(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
1460         if (!child->hwnd) {
1461                 UnhookWindowsHookEx(hcbthook);
1462                 return 0;
1463         }
1464
1465         UnhookWindowsHookEx(hcbthook);
1466
1467         idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), child->left.cur);
1468         ListBox_SetCurSel(child->left.hwnd, idx);
1469
1470         return child->hwnd;
1471 }
1472
1473
1474 struct ExecuteDialog {
1475         TCHAR   cmd[MAX_PATH];
1476         int             cmdshow;
1477 };
1478
1479
1480 static BOOL CALLBACK ExecuteDialogWndProg(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1481 {
1482         static struct ExecuteDialog* dlg;
1483
1484         switch(nmsg) {
1485                 case WM_INITDIALOG:
1486                         dlg = (struct ExecuteDialog*) lparam;
1487                         return 1;
1488
1489                 case WM_COMMAND: {
1490                         int id = (int)wparam;
1491
1492                         if (id == IDOK) {
1493                                 GetWindowText(GetDlgItem(hwnd, 201), dlg->cmd, MAX_PATH);
1494                                 dlg->cmdshow = Button_GetState(GetDlgItem(hwnd,214))&BST_CHECKED?
1495                                                                                                 SW_SHOWMINIMIZED: SW_SHOWNORMAL;
1496                                 EndDialog(hwnd, id);
1497                         } else if (id == IDCANCEL)
1498                                 EndDialog(hwnd, id);
1499
1500                         return 1;}
1501         }
1502
1503         return 0;
1504 }
1505
1506
1507 #ifndef _NO_EXTENSIONS
1508
1509 static struct FullScreenParameters {
1510         BOOL    mode;
1511         RECT    orgPos;
1512         BOOL    wasZoomed;
1513 } g_fullscreen = {
1514     FALSE,      /* mode */
1515         {0, 0, 0, 0},
1516         FALSE
1517 };
1518
1519 void frame_get_clientspace(HWND hwnd, PRECT prect)
1520 {
1521         RECT rt;
1522
1523         if (!IsIconic(hwnd))
1524                 GetClientRect(hwnd, prect);
1525         else {
1526                 WINDOWPLACEMENT wp;
1527
1528                 GetWindowPlacement(hwnd, &wp);
1529
1530                 prect->left = prect->top = 0;
1531                 prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
1532                                                 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
1533                 prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
1534                                                 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
1535                                                 GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
1536         }
1537
1538         if (IsWindowVisible(Globals.htoolbar)) {
1539                 GetClientRect(Globals.htoolbar, &rt);
1540                 prect->top += rt.bottom+2;
1541         }
1542
1543         if (IsWindowVisible(Globals.hdrivebar)) {
1544                 GetClientRect(Globals.hdrivebar, &rt);
1545                 prect->top += rt.bottom+2;
1546         }
1547
1548         if (IsWindowVisible(Globals.hstatusbar)) {
1549                 GetClientRect(Globals.hstatusbar, &rt);
1550                 prect->bottom -= rt.bottom;
1551         }
1552 }
1553
1554 static BOOL toggle_fullscreen(HWND hwnd)
1555 {
1556         RECT rt;
1557
1558         if ((g_fullscreen.mode=!g_fullscreen.mode)) {
1559                 GetWindowRect(hwnd, &g_fullscreen.orgPos);
1560                 g_fullscreen.wasZoomed = IsZoomed(hwnd);
1561
1562                 Frame_CalcFrameClient(hwnd, &rt);
1563                 ClientToScreen(hwnd, (LPPOINT)&rt.left);
1564                 ClientToScreen(hwnd, (LPPOINT)&rt.right);
1565
1566                 rt.left = g_fullscreen.orgPos.left-rt.left;
1567                 rt.top = g_fullscreen.orgPos.top-rt.top;
1568                 rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
1569                 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
1570
1571                 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1572         } else {
1573                 MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
1574                                                         g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
1575                                                         g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
1576
1577                 if (g_fullscreen.wasZoomed)
1578                         ShowWindow(hwnd, WS_MAXIMIZE);
1579         }
1580
1581         return g_fullscreen.mode;
1582 }
1583
1584 static void fullscreen_move(HWND hwnd)
1585 {
1586         RECT rt, pos;
1587         GetWindowRect(hwnd, &pos);
1588
1589         Frame_CalcFrameClient(hwnd, &rt);
1590         ClientToScreen(hwnd, (LPPOINT)&rt.left);
1591         ClientToScreen(hwnd, (LPPOINT)&rt.right);
1592
1593         rt.left = pos.left-rt.left;
1594         rt.top = pos.top-rt.top;
1595         rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
1596         rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
1597
1598         MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1599 }
1600
1601 #endif
1602
1603
1604 static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
1605 {
1606         BOOL vis = IsWindowVisible(hchild);
1607
1608         CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
1609
1610         ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
1611
1612 #ifndef _NO_EXTENSIONS
1613         if (g_fullscreen.mode)
1614                 fullscreen_move(hwnd);
1615 #endif
1616
1617         resize_frame_client(hwnd);
1618 }
1619
1620 BOOL activate_drive_window(LPCTSTR path)
1621 {
1622         TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
1623         HWND child_wnd;
1624
1625         _tsplitpath(path, drv1, 0, 0, 0);
1626
1627         /* search for a already open window for the same drive */
1628         for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1629                 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
1630
1631                 if (child) {
1632                         _tsplitpath(child->root.path, drv2, 0, 0, 0);
1633
1634                         if (!lstrcmpi(drv2, drv1)) {
1635                                 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1636
1637                                 if (IsMinimized(child_wnd))
1638                                         ShowWindow(child_wnd, SW_SHOWNORMAL);
1639
1640                                 return TRUE;
1641                         }
1642                 }
1643         }
1644
1645         return FALSE;
1646 }
1647
1648 BOOL activate_fs_window(LPCTSTR filesys)
1649 {
1650         HWND child_wnd;
1651
1652         /* search for a already open window of the given file system name */
1653         for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1654                 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
1655
1656                 if (child) {
1657                         if (!lstrcmpi(child->root.fs, filesys)) {
1658                                 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1659
1660                                 if (IsMinimized(child_wnd))
1661                                         ShowWindow(child_wnd, SW_SHOWNORMAL);
1662
1663                                 return TRUE;
1664                         }
1665                 }
1666         }
1667
1668         return FALSE;
1669 }
1670
1671 LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1672 {
1673         switch(nmsg) {
1674                 case WM_CLOSE:
1675                         DestroyWindow(hwnd);
1676
1677                          /* clear handle variables */
1678                         Globals.hMenuFrame = 0;
1679                         Globals.hMenuView = 0;
1680                         Globals.hMenuOptions = 0;
1681                         Globals.hMainWnd = 0;
1682                         Globals.hmdiclient = 0;
1683                         Globals.hdrivebar = 0;
1684                         break;
1685
1686                 case WM_DESTROY:
1687                          /* don't exit desktop when closing file manager window */
1688                         if (!Globals.hwndParent)
1689                                 PostQuitMessage(0);
1690                         break;
1691
1692                 case WM_COMMAND: {
1693                         UINT cmd = LOWORD(wparam);
1694                         HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
1695
1696                         if (SendMessage(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam))
1697                                 break;
1698
1699                         if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) {
1700                                 TCHAR drv[_MAX_DRIVE], path[MAX_PATH];
1701                                 ChildWnd* child;
1702                                 LPCTSTR root = Globals.drives;
1703                                 int i;
1704
1705                                 for(i=cmd-ID_DRIVE_FIRST; i--; root++)
1706                                         while(*root)
1707                                                 root++;
1708
1709                                 if (activate_drive_window(root))
1710                                         return 0;
1711
1712                                 _tsplitpath(root, drv, 0, 0, 0);
1713
1714                                 if (!SetCurrentDirectory(drv)) {
1715                                         display_error(hwnd, GetLastError());
1716                                         return 0;
1717                                 }
1718
1719                                 GetCurrentDirectory(MAX_PATH, path); /*TODO: store last directory per drive */
1720                                 child = alloc_child_window(path, NULL, hwnd);
1721
1722                                 if (!create_child_window(child))
1723                                         free(child);
1724                         } else switch(cmd) {
1725                                 case ID_FILE_EXIT:
1726                                         SendMessage(hwnd, WM_CLOSE, 0, 0);
1727                                         break;
1728
1729                                 case ID_WINDOW_NEW: {
1730                                         TCHAR path[MAX_PATH];
1731                                         ChildWnd* child;
1732
1733                                         GetCurrentDirectory(MAX_PATH, path);
1734                                         child = alloc_child_window(path, NULL, hwnd);
1735
1736                                         if (!create_child_window(child))
1737                                                 free(child);
1738                                         break;}
1739
1740                                 case ID_WINDOW_CASCADE:
1741                                         SendMessage(Globals.hmdiclient, WM_MDICASCADE, 0, 0);
1742                                         break;
1743
1744                                 case ID_WINDOW_TILE_HORZ:
1745                                         SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
1746                                         break;
1747
1748                                 case ID_WINDOW_TILE_VERT:
1749                                         SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
1750                                         break;
1751
1752                                 case ID_WINDOW_ARRANGE:
1753                                         SendMessage(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0);
1754                                         break;
1755
1756                                 case ID_VIEW_TOOL_BAR:
1757                                         toggle_child(hwnd, cmd, Globals.htoolbar);
1758                                         break;
1759
1760                                 case ID_VIEW_DRIVE_BAR:
1761                                         toggle_child(hwnd, cmd, Globals.hdrivebar);
1762                                         break;
1763
1764                                 case ID_VIEW_STATUSBAR:
1765                                         toggle_child(hwnd, cmd, Globals.hstatusbar);
1766                                         break;
1767
1768                                 case ID_EXECUTE: {
1769                                         struct ExecuteDialog dlg;
1770
1771                                         memset(&dlg, 0, sizeof(struct ExecuteDialog));
1772
1773                                         if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_EXECUTE), hwnd, ExecuteDialogWndProg, (LPARAM)&dlg) == IDOK) {
1774                                                 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow);
1775
1776                                                 if ((int)hinst <= 32)
1777                                                         display_error(hwnd, GetLastError());
1778                                         }
1779                                         break;}
1780
1781                                 case ID_HELP:
1782                                         WinHelp(hwnd, TEXT("winfile"), HELP_INDEX, 0);
1783                                         break;
1784
1785 #ifndef _NO_EXTENSIONS
1786                                 case ID_VIEW_FULLSCREEN:
1787                                         CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
1788                                         break;
1789
1790 #ifdef __WINE__
1791                                 case ID_DRIVE_UNIX_FS: {
1792                                         TCHAR path[MAX_PATH];
1793                                         ChildWnd* child;
1794
1795                                         if (activate_fs_window(TEXT("unixfs")))
1796                                                 break;
1797
1798                                         getcwd(path, MAX_PATH);
1799                                         child = alloc_child_window(path, NULL, hwnd);
1800
1801                                         if (!create_child_window(child))
1802                                                 free(child);
1803                                         break;}
1804 #endif
1805 #ifdef _SHELL_FOLDERS
1806                                 case ID_DRIVE_SHELL_NS: {
1807                                         TCHAR path[MAX_PATH];
1808                                         ChildWnd* child;
1809
1810                                         if (activate_fs_window(TEXT("Shell")))
1811                                                 break;
1812
1813                                         GetCurrentDirectory(MAX_PATH, path);
1814                                         child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
1815
1816                                         if (!create_child_window(child))
1817                                                 free(child);
1818                                         break;}
1819 #endif
1820 #endif
1821
1822                                 /*TODO: There are even more menu items! */
1823
1824 #ifndef _NO_EXTENSIONS
1825 #ifdef _WINE_
1826                                 case ID_LICENSE:
1827                                         WineLicense(Globals.hMainWnd);
1828                                         break;
1829
1830                                 case ID_NO_WARRANTY:
1831                                         WineWarranty(Globals.hMainWnd);
1832                                         break;
1833 #endif
1834
1835                                 case ID_ABOUT_WINE:
1836                                         ShellAbout(hwnd, TEXT("WINE"), TEXT("Winefile"), 0);
1837                                         break;
1838
1839                                 case ID_ABOUT:  /*ID_ABOUT_WINE: */
1840                                         ShellAbout(hwnd, TEXT("Winefile"), NULL, 0);
1841                                         break;
1842 #endif  /* _NO_EXTENSIONS */
1843
1844                                 default:
1845                                         /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
1846                                                 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
1847                                         else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
1848                                                 (cmd<SC_SIZE || cmd>SC_RESTORE))
1849                                                 MessageBox(hwnd, TEXT("Not yet implemented"), TEXT("Winefile"), MB_OK);
1850
1851                                         return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
1852                         }
1853                         break;}
1854
1855                 case WM_SIZE:
1856                         resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
1857                         break;  /* do not pass message to DefFrameProc */
1858
1859 #ifndef _NO_EXTENSIONS
1860                 case WM_GETMINMAXINFO: {
1861                         LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
1862
1863                         lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
1864                         lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
1865                         break;}
1866
1867                 case FRM_CALC_CLIENT:
1868                         frame_get_clientspace(hwnd, (PRECT)lparam);
1869                         return TRUE;
1870 #endif /* _NO_EXTENSIONS */
1871
1872                 default:
1873                         return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
1874         }
1875
1876         return 0;
1877 }
1878
1879
1880 static const LPTSTR g_pos_names[COLUMNS] = {
1881         TEXT(""),                       /* symbol */
1882         TEXT("Name"),
1883         TEXT("Size"),
1884         TEXT("CDate"),
1885 #ifndef _NO_EXTENSIONS
1886         TEXT("ADate"),
1887         TEXT("MDate"),
1888         TEXT("Index/Inode"),
1889         TEXT("Links"),
1890 #endif /* _NO_EXTENSIONS */
1891         TEXT("Attributes"),
1892 #ifndef _NO_EXTENSIONS
1893         TEXT("Security")
1894 #endif
1895 };
1896
1897 static const int g_pos_align[] = {
1898         0,
1899         HDF_LEFT,       /* Name */
1900         HDF_RIGHT,      /* Size */
1901         HDF_LEFT,       /* CDate */
1902 #ifndef _NO_EXTENSIONS
1903         HDF_LEFT,       /* ADate */
1904         HDF_LEFT,       /* MDate */
1905         HDF_LEFT,       /* Index */
1906         HDF_CENTER,     /* Links */
1907 #endif
1908         HDF_CENTER,     /* Attributes */
1909 #ifndef _NO_EXTENSIONS
1910         HDF_LEFT        /* Security */
1911 #endif
1912 };
1913
1914 static void resize_tree(ChildWnd* child, int cx, int cy)
1915 {
1916         HDWP hdwp = BeginDeferWindowPos(4);
1917         RECT rt;
1918
1919         rt.left   = 0;
1920         rt.top    = 0;
1921         rt.right  = cx;
1922         rt.bottom = cy;
1923
1924         cx = child->split_pos + SPLIT_WIDTH/2;
1925
1926 #ifndef _NO_EXTENSIONS
1927         {
1928                 WINDOWPOS wp;
1929                 HD_LAYOUT hdl;
1930
1931                 hdl.prc   = &rt;
1932                 hdl.pwpos = &wp;
1933
1934                 Header_Layout(child->left.hwndHeader, &hdl);
1935
1936                 DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
1937                                                 wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
1938                 DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
1939                                                 rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
1940         }
1941 #endif /* _NO_EXTENSIONS */
1942
1943         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);
1944         DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
1945
1946         EndDeferWindowPos(hdwp);
1947 }
1948
1949
1950 #ifndef _NO_EXTENSIONS
1951
1952 static HWND create_header(HWND parent, Pane* pane, int id)
1953 {
1954         HD_ITEM hdi;
1955         int idx;
1956
1957         HWND hwnd = CreateWindow(WC_HEADER, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ/*TODO: |HDS_BUTTONS + sort orders*/,
1958                                                                 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
1959         if (!hwnd)
1960                 return 0;
1961
1962         SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), FALSE);
1963
1964         hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
1965
1966         for(idx=0; idx<COLUMNS; idx++) {
1967                 hdi.pszText = g_pos_names[idx];
1968                 hdi.fmt = HDF_STRING | g_pos_align[idx];
1969                 hdi.cxy = pane->widths[idx];
1970                 Header_InsertItem(hwnd, idx, &hdi);
1971         }
1972
1973         return hwnd;
1974 }
1975
1976 #endif /* _NO_EXTENSIONS */
1977
1978
1979 static void init_output(HWND hwnd)
1980 {
1981         TCHAR b[16];
1982         HFONT old_font;
1983         HDC hdc = GetDC(hwnd);
1984
1985         if (GetNumberFormat(LOCALE_USER_DEFAULT, 0, TEXT("1000"), 0, b, 16) > 4)
1986                 Globals.num_sep = b[1];
1987         else
1988                 Globals.num_sep = TEXT('.');
1989
1990         old_font = SelectFont(hdc, Globals.hfont);
1991         GetTextExtentPoint32(hdc, TEXT(" "), 1, &Globals.spaceSize);
1992         SelectFont(hdc, old_font);
1993         ReleaseDC(hwnd, hdc);
1994 }
1995
1996 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
1997
1998
1999 /* calculate prefered width for all visible columns */
2000
2001 static BOOL calc_widths(Pane* pane, BOOL anyway)
2002 {
2003         int col, x, cx, spc=3*Globals.spaceSize.cx;
2004         int entries = ListBox_GetCount(pane->hwnd);
2005         int orgWidths[COLUMNS];
2006         int orgPositions[COLUMNS+1];
2007         HFONT hfontOld;
2008         HDC hdc;
2009         int cnt;
2010
2011         if (!anyway) {
2012                 memcpy(orgWidths, pane->widths, sizeof(orgWidths));
2013                 memcpy(orgPositions, pane->positions, sizeof(orgPositions));
2014         }
2015
2016         for(col=0; col<COLUMNS; col++)
2017                 pane->widths[col] = 0;
2018
2019         hdc = GetDC(pane->hwnd);
2020         hfontOld = SelectFont(hdc, Globals.hfont);
2021
2022         for(cnt=0; cnt<entries; cnt++) {
2023                 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2024
2025                 DRAWITEMSTRUCT dis;
2026
2027                 dis.CtlType               = 0;
2028                 dis.CtlID                 = 0;
2029                 dis.itemID                = 0;
2030                 dis.itemAction    = 0;
2031                 dis.itemState     = 0;
2032                 dis.hwndItem      = pane->hwnd;
2033                 dis.hDC                   = hdc;
2034                 dis.rcItem.left   = 0;
2035                 dis.rcItem.top    = 0;
2036                 dis.rcItem.right  = 0;
2037                 dis.rcItem.bottom = 0;
2038                 /*dis.itemData    = 0; */
2039
2040                 draw_item(pane, &dis, entry, COLUMNS);
2041         }
2042
2043         SelectObject(hdc, hfontOld);
2044         ReleaseDC(pane->hwnd, hdc);
2045
2046         x = 0;
2047         for(col=0; col<COLUMNS; col++) {
2048                 pane->positions[col] = x;
2049                 cx = pane->widths[col];
2050
2051                 if (cx) {
2052                         cx += spc;
2053
2054                         if (cx < IMAGE_WIDTH)
2055                                 cx = IMAGE_WIDTH;
2056
2057                         pane->widths[col] = cx;
2058                 }
2059
2060                 x += cx;
2061         }
2062
2063         pane->positions[COLUMNS] = x;
2064
2065         ListBox_SetHorizontalExtent(pane->hwnd, x);
2066
2067         /* no change? */
2068         if (!memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
2069                 return FALSE;
2070
2071         /* don't move, if only collapsing an entry */
2072         if (!anyway && pane->widths[0]<orgWidths[0] &&
2073                 !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
2074                 pane->widths[0] = orgWidths[0];
2075                 memcpy(pane->positions, orgPositions, sizeof(orgPositions));
2076
2077                 return FALSE;
2078         }
2079
2080         InvalidateRect(pane->hwnd, 0, TRUE);
2081
2082         return TRUE;
2083 }
2084
2085
2086 /* calculate one prefered column width */
2087
2088 static void calc_single_width(Pane* pane, int col)
2089 {
2090         HFONT hfontOld;
2091         int x, cx;
2092         int entries = ListBox_GetCount(pane->hwnd);
2093         int cnt;
2094         HDC hdc;
2095
2096         pane->widths[col] = 0;
2097
2098         hdc = GetDC(pane->hwnd);
2099         hfontOld = SelectFont(hdc, Globals.hfont);
2100
2101         for(cnt=0; cnt<entries; cnt++) {
2102                 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2103                 DRAWITEMSTRUCT dis;
2104
2105                 dis.CtlType               = 0;
2106                 dis.CtlID                 = 0;
2107                 dis.itemID                = 0;
2108                 dis.itemAction    = 0;
2109                 dis.itemState     = 0;
2110                 dis.hwndItem      = pane->hwnd;
2111                 dis.hDC                   = hdc;
2112                 dis.rcItem.left   = 0;
2113                 dis.rcItem.top    = 0;
2114                 dis.rcItem.right  = 0;
2115                 dis.rcItem.bottom = 0;
2116                 /*dis.itemData    = 0; */
2117
2118                 draw_item(pane, &dis, entry, col);
2119         }
2120
2121         SelectObject(hdc, hfontOld);
2122         ReleaseDC(pane->hwnd, hdc);
2123
2124         cx = pane->widths[col];
2125
2126         if (cx) {
2127                 cx += 3*Globals.spaceSize.cx;
2128
2129                 if (cx < IMAGE_WIDTH)
2130                         cx = IMAGE_WIDTH;
2131         }
2132
2133         pane->widths[col] = cx;
2134
2135         x = pane->positions[col] + cx;
2136
2137         for(; col<COLUMNS; ) {
2138                 pane->positions[++col] = x;
2139                 x += pane->widths[col];
2140         }
2141
2142         ListBox_SetHorizontalExtent(pane->hwnd, x);
2143 }
2144
2145
2146 /* insert listbox entries after index idx */
2147
2148 static void insert_entries(Pane* pane, Entry* dir, int idx)
2149 {
2150         Entry* entry = dir;
2151
2152         if (!entry)
2153                 return;
2154
2155         ShowWindow(pane->hwnd, SW_HIDE);
2156
2157         for(; entry; entry=entry->next) {
2158 #ifndef _LEFT_FILES
2159                 if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2160                         continue;
2161 #endif
2162
2163                 /* don't display entries "." and ".." in the left pane */
2164                 if (pane->treePane && (entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
2165                                 && entry->data.cFileName[0]==TEXT('.'))
2166                         if (
2167 #ifndef _NO_EXTENSIONS
2168                                 entry->data.cFileName[1]==TEXT('\0') ||
2169 #endif
2170                                 (entry->data.cFileName[1]==TEXT('.') && entry->data.cFileName[2]==TEXT('\0')))
2171                                 continue;
2172
2173                 if (idx != -1)
2174                         idx++;
2175
2176                 ListBox_InsertItemData(pane->hwnd, idx, entry);
2177
2178                 if (pane->treePane && entry->expanded)
2179                         insert_entries(pane, entry->down, idx);
2180         }
2181
2182         ShowWindow(pane->hwnd, SW_SHOW);
2183 }
2184
2185
2186 static WNDPROC g_orgTreeWndProc;
2187
2188 static void create_tree_window(HWND parent, Pane* pane, int id, int id_header)
2189 {
2190         static int s_init = 0;
2191         Entry* entry = pane->root;
2192
2193         pane->hwnd = CreateWindow(TEXT("ListBox"), TEXT(""), WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
2194                                                                 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
2195                                                                 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2196
2197         SetWindowLong(pane->hwnd, GWL_USERDATA, (LPARAM)pane);
2198         g_orgTreeWndProc = SubclassWindow(pane->hwnd, TreeWndProc);
2199
2200         SendMessage(pane->hwnd, WM_SETFONT, (WPARAM)Globals.hfont, FALSE);
2201
2202         /* insert entries into listbox */
2203         if (entry)
2204                 insert_entries(pane, entry, -1);
2205
2206         /* calculate column widths */
2207         if (!s_init) {
2208                 s_init = 1;
2209                 init_output(pane->hwnd);
2210         }
2211
2212         calc_widths(pane, TRUE);
2213
2214 #ifndef _NO_EXTENSIONS
2215         pane->hwndHeader = create_header(parent, pane, id_header);
2216 #endif
2217 }
2218
2219
2220 static void InitChildWindow(ChildWnd* child)
2221 {
2222         create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT);
2223         create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT);
2224 }
2225
2226
2227 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols)
2228 {
2229         SYSTEMTIME systime;
2230         FILETIME lft;
2231         int len = 0;
2232
2233         *buffer = TEXT('\0');
2234
2235         if (!ft->dwLowDateTime && !ft->dwHighDateTime)
2236                 return;
2237
2238         if (!FileTimeToLocalFileTime(ft, &lft))
2239                 {err: _tcscpy(buffer,TEXT("???")); return;}
2240
2241         if (!FileTimeToSystemTime(&lft, &systime))
2242                 goto err;
2243
2244         if (visible_cols & COL_DATE) {
2245                 len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
2246                 if (!len)
2247                         goto err;
2248         }
2249
2250         if (visible_cols & COL_TIME) {
2251                 if (len)
2252                         buffer[len-1] = ' ';
2253
2254                 buffer[len++] = ' ';
2255
2256                 if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
2257                         buffer[len] = TEXT('\0');
2258         }
2259 }
2260
2261
2262 static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2263 {
2264         RECT rt = {0, 0, 0, 0};
2265
2266         DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2267
2268         if (rt.right > pane->widths[col])
2269                 pane->widths[col] = rt.right;
2270 }
2271
2272 static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2273 {
2274         RECT rt = {0, 0, 0, 0};
2275
2276 /*      DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2277         DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2278
2279         DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2280         /*FIXME rt (0,0) ??? */
2281
2282         if (rt.right > pane->widths[col])
2283                 pane->widths[col] = rt.right;
2284 }
2285
2286
2287 static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str, DWORD flags)
2288 {
2289         int x = dis->rcItem.left;
2290         RECT rt;
2291
2292         rt.left   = x+pane->positions[col]+Globals.spaceSize.cx;
2293         rt.top    = dis->rcItem.top;
2294         rt.right  = x+pane->positions[col+1]-Globals.spaceSize.cx;
2295         rt.bottom = dis->rcItem.bottom;
2296
2297         DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
2298 }
2299
2300 static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2301 {
2302         int x = dis->rcItem.left;
2303         RECT rt;
2304
2305         rt.left   = x+pane->positions[col]+Globals.spaceSize.cx;
2306         rt.top    = dis->rcItem.top;
2307         rt.right  = x+pane->positions[col+1]-Globals.spaceSize.cx;
2308         rt.bottom = dis->rcItem.bottom;
2309
2310 /*      DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2311         DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2312
2313         DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2314 }
2315
2316 static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2317 {
2318         int x = dis->rcItem.left;
2319         RECT rt;
2320         LPCTSTR s = str;
2321         TCHAR b[128];
2322         LPTSTR d = b;
2323         int pos;
2324
2325         rt.left   = x+pane->positions[col]+Globals.spaceSize.cx;
2326         rt.top    = dis->rcItem.top;
2327         rt.right  = x+pane->positions[col+1]-Globals.spaceSize.cx;
2328         rt.bottom = dis->rcItem.bottom;
2329
2330         if (*s)
2331                 *d++ = *s++;
2332
2333         /* insert number separator characters */
2334         pos = lstrlen(s) % 3;
2335
2336         while(*s)
2337                 if (pos--)
2338                         *d++ = *s++;
2339                 else {
2340                         *d++ = Globals.num_sep;
2341                         pos = 3;
2342                 }
2343
2344         DrawText(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
2345 }
2346
2347
2348 static int is_exe_file(LPCTSTR ext)
2349 {
2350         static const LPCTSTR executable_extensions[] = {
2351                 TEXT("COM"),
2352                 TEXT("EXE"),
2353                 TEXT("BAT"),
2354                 TEXT("CMD"),
2355 #ifndef _NO_EXTENSIONS
2356                 TEXT("CMM"),
2357                 TEXT("BTM"),
2358                 TEXT("AWK"),
2359 #endif /* _NO_EXTENSIONS */
2360                 0
2361         };
2362
2363         TCHAR ext_buffer[_MAX_EXT];
2364         const LPCTSTR* p;
2365         LPCTSTR s;
2366         LPTSTR d;
2367
2368         for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
2369                 d++;
2370
2371         for(p=executable_extensions; *p; p++)
2372                 if (!_tcscmp(ext_buffer, *p))
2373                         return 1;
2374
2375         return 0;
2376 }
2377
2378 static int is_registered_type(LPCTSTR ext)
2379 {
2380         /* TODO */
2381
2382         return 1;
2383 }
2384
2385
2386 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
2387 {
2388         TCHAR buffer[BUFFER_LEN];
2389         DWORD attrs;
2390         int visible_cols = pane->visible_cols;
2391         COLORREF bkcolor, textcolor;
2392         RECT focusRect = dis->rcItem;
2393         HBRUSH hbrush;
2394         enum IMAGE img;
2395         int img_pos, cx;
2396         int col = 0;
2397
2398         if (entry) {
2399                 attrs = entry->data.dwFileAttributes;
2400
2401                 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
2402                         if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('.')
2403                                         && entry->data.cFileName[2]==TEXT('\0'))
2404                                 img = IMG_FOLDER_UP;
2405 #ifndef _NO_EXTENSIONS
2406                         else if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('\0'))
2407                                 img = IMG_FOLDER_CUR;
2408 #endif
2409                         else if (
2410 #ifdef _NO_EXTENSIONS
2411                                          entry->expanded ||
2412 #endif
2413                                          (pane->treePane && (dis->itemState&ODS_FOCUS)))
2414                                 img = IMG_OPEN_FOLDER;
2415                         else
2416                                 img = IMG_FOLDER;
2417                 } else {
2418                         LPCTSTR ext = _tcsrchr(entry->data.cFileName, '.');
2419                         if (!ext)
2420                                 ext = TEXT("");
2421
2422                         if (is_exe_file(ext))
2423                                 img = IMG_EXECUTABLE;
2424                         else if (is_registered_type(ext))
2425                                 img = IMG_DOCUMENT;
2426                         else
2427                                 img = IMG_FILE;
2428                 }
2429         } else {
2430                 attrs = 0;
2431                 img = IMG_NONE;
2432         }
2433
2434         if (pane->treePane) {
2435                 if (entry) {
2436                         img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+Globals.spaceSize.cx);
2437
2438                         if (calcWidthCol == -1) {
2439                                 int x;
2440                                 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
2441                                 Entry* up;
2442                                 RECT rt_clip;
2443                                 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
2444                                 HRGN hrgn;
2445
2446                                 rt_clip.left   = dis->rcItem.left;
2447                                 rt_clip.top    = dis->rcItem.top;
2448                                 rt_clip.right  = dis->rcItem.left+pane->widths[col];
2449                                 rt_clip.bottom = dis->rcItem.bottom;
2450
2451                                 hrgn = CreateRectRgnIndirect(&rt_clip);
2452
2453                                 if (!GetClipRgn(dis->hDC, hrgn_org)) {
2454                                         DeleteObject(hrgn_org);
2455                                         hrgn_org = 0;
2456                                 }
2457
2458                                 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
2459                                 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
2460                                 DeleteObject(hrgn);
2461
2462                                 if ((up=entry->up) != NULL) {
2463                                         MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
2464                                         LineTo(dis->hDC, img_pos-2, y);
2465
2466                                         x = img_pos - IMAGE_WIDTH/2;
2467
2468                                         do {
2469                                                 x -= IMAGE_WIDTH+Globals.spaceSize.cx;
2470
2471                                                 if (up->next
2472 #ifndef _LEFT_FILES
2473                                                         && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
2474 #endif
2475                                                         ) {
2476                                                         MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2477                                                         LineTo(dis->hDC, x, dis->rcItem.bottom);
2478                                                 }
2479                                         } while((up=up->up) != NULL);
2480                                 }
2481
2482                                 x = img_pos - IMAGE_WIDTH/2;
2483
2484                                 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2485                                 LineTo(dis->hDC, x, y);
2486
2487                                 if (entry->next
2488 #ifndef _LEFT_FILES
2489                                         && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
2490 #endif
2491                                         )
2492                                         LineTo(dis->hDC, x, dis->rcItem.bottom);
2493
2494                                 if (entry->down && entry->expanded) {
2495                                         x += IMAGE_WIDTH+Globals.spaceSize.cx;
2496                                         MoveToEx(dis->hDC, x, dis->rcItem.top+IMAGE_HEIGHT, 0);
2497                                         LineTo(dis->hDC, x, dis->rcItem.bottom);
2498                                 }
2499
2500                                 SelectClipRgn(dis->hDC, hrgn_org);
2501                                 if (hrgn_org) DeleteObject(hrgn_org);
2502                                 /* SelectObject(dis->hDC, holdPen); */
2503                         } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
2504                                 int right = img_pos + IMAGE_WIDTH - Globals.spaceSize.cx;
2505
2506                                 if (right > pane->widths[col])
2507                                         pane->widths[col] = right;
2508                         }
2509                 } else  {
2510                         img_pos = dis->rcItem.left;
2511                 }
2512         } else {
2513                 img_pos = dis->rcItem.left;
2514
2515                 if (calcWidthCol==col || calcWidthCol==COLUMNS)
2516                         pane->widths[col] = IMAGE_WIDTH;
2517         }
2518
2519         if (calcWidthCol == -1) {
2520                 focusRect.left = img_pos -2;
2521
2522 #ifdef _NO_EXTENSIONS
2523                 if (pane->treePane && entry) {
2524                         RECT rt = {0};
2525
2526                         DrawText(dis->hDC, entry->data.cFileName, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2527
2528                         focusRect.right = dis->rcItem.left+pane->positions[col+1]+Globals.spaceSize.cx + rt.right +2;
2529                 }
2530 #else
2531
2532                 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
2533                         textcolor = COLOR_COMPRESSED;
2534                 else
2535 #endif /* _NO_EXTENSIONS */
2536                         textcolor = RGB(0,0,0);
2537
2538                 if (dis->itemState & ODS_FOCUS) {
2539                         textcolor = RGB(255,255,255);
2540                         bkcolor = COLOR_SELECTION;
2541                 } else {
2542                         bkcolor = RGB(255,255,255);
2543                 }
2544
2545                 hbrush = CreateSolidBrush(bkcolor);
2546                 FillRect(dis->hDC, &focusRect, hbrush);
2547                 DeleteObject(hbrush);
2548
2549                 SetBkMode(dis->hDC, TRANSPARENT);
2550                 SetTextColor(dis->hDC, textcolor);
2551
2552                 cx = pane->widths[col];
2553
2554                 if (cx && img!=IMG_NONE) {
2555                         if (cx > IMAGE_WIDTH)
2556                                 cx = IMAGE_WIDTH;
2557
2558 #ifdef _SHELL_FOLDERS
2559                         if (entry->hicon && entry->hicon!=(HICON)-1)
2560                                 DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
2561                         else
2562 #endif
2563                                 ImageList_DrawEx(Globals.himl, img, dis->hDC,
2564                                                                  img_pos, dis->rcItem.top, cx,
2565                                                                  IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
2566                 }
2567         }
2568
2569         if (!entry)
2570                 return;
2571
2572 #ifdef _NO_EXTENSIONS
2573         if (img >= IMG_FOLDER_UP)
2574                 return;
2575 #endif
2576
2577         col++;
2578
2579         /* ouput file name */
2580         if (calcWidthCol == -1)
2581                 output_text(pane, dis, col, entry->data.cFileName, 0);
2582         else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2583                 calc_width(pane, dis, col, entry->data.cFileName);
2584
2585         col++;
2586
2587 #ifdef _NO_EXTENSIONS
2588   if (!pane->treePane) {
2589 #endif
2590
2591         /* display file size */
2592         if (visible_cols & COL_SIZE) {
2593 #ifdef _NO_EXTENSIONS
2594                 if (!(attrs&FILE_ATTRIBUTE_DIRECTORY))
2595 #endif
2596                 {
2597                         ULONGLONG size;
2598
2599                         size = ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow;
2600
2601                         _stprintf(buffer, TEXT("%") LONGLONGARG TEXT("d"), size);
2602
2603                         if (calcWidthCol == -1)
2604                                 output_number(pane, dis, col, buffer);
2605                         else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2606                                 calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
2607                 }
2608
2609                 col++;
2610         }
2611
2612         /* display file date */
2613         if (visible_cols & (COL_DATE|COL_TIME)) {
2614 #ifndef _NO_EXTENSIONS
2615                 format_date(&entry->data.ftCreationTime, buffer, visible_cols);
2616                 if (calcWidthCol == -1)
2617                         output_text(pane, dis, col, buffer, 0);
2618                 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2619                         calc_width(pane, dis, col, buffer);
2620                 col++;
2621
2622                 format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
2623                 if (calcWidthCol == -1)
2624                         output_text(pane, dis, col, buffer, 0);
2625                 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2626                         calc_width(pane, dis, col, buffer);
2627                 col++;
2628 #endif /* _NO_EXTENSIONS */
2629
2630                 format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
2631                 if (calcWidthCol == -1)
2632                         output_text(pane, dis, col, buffer, 0);
2633                 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2634                         calc_width(pane, dis, col, buffer);
2635                 col++;
2636         }
2637
2638 #ifndef _NO_EXTENSIONS
2639         if (entry->bhfi_valid) {
2640             ULONGLONG index = ((ULONGLONG)entry->bhfi.nFileIndexHigh << 32) | entry->bhfi.nFileIndexLow;
2641
2642                 if (visible_cols & COL_INDEX) {
2643                         _stprintf(buffer, TEXT("%") LONGLONGARG TEXT("X"), index);
2644                         if (calcWidthCol == -1)
2645                                 output_text(pane, dis, col, buffer, DT_RIGHT);
2646                         else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2647                                 calc_width(pane, dis, col, buffer);
2648                         col++;
2649                 }
2650
2651                 if (visible_cols & COL_LINKS) {
2652                         wsprintf(buffer, TEXT("%d"), entry->bhfi.nNumberOfLinks);
2653                         if (calcWidthCol == -1)
2654                                 output_text(pane, dis, col, buffer, DT_CENTER);
2655                         else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2656                                 calc_width(pane, dis, col, buffer);
2657                         col++;
2658                 }
2659         } else
2660                 col += 2;
2661 #endif /* _NO_EXTENSIONS */
2662
2663         /* show file attributes */
2664         if (visible_cols & COL_ATTRIBUTES) {
2665 #ifdef _NO_EXTENSIONS
2666                 _tcscpy(buffer, TEXT(" \t \t \t \t "));
2667 #else
2668                 _tcscpy(buffer, TEXT(" \t \t \t \t \t \t \t \t \t \t \t "));
2669 #endif
2670
2671                 if (attrs & FILE_ATTRIBUTE_NORMAL)                                      buffer[ 0] = 'N';
2672                 else {
2673                         if (attrs & FILE_ATTRIBUTE_READONLY)                    buffer[ 2] = 'R';
2674                         if (attrs & FILE_ATTRIBUTE_HIDDEN)                              buffer[ 4] = 'H';
2675                         if (attrs & FILE_ATTRIBUTE_SYSTEM)                              buffer[ 6] = 'S';
2676                         if (attrs & FILE_ATTRIBUTE_ARCHIVE)                             buffer[ 8] = 'A';
2677                         if (attrs & FILE_ATTRIBUTE_COMPRESSED)                  buffer[10] = 'C';
2678 #ifndef _NO_EXTENSIONS
2679                         if (attrs & FILE_ATTRIBUTE_DIRECTORY)                   buffer[12] = 'D';
2680                         if (attrs & FILE_ATTRIBUTE_ENCRYPTED)                   buffer[14] = 'E';
2681                         if (attrs & FILE_ATTRIBUTE_TEMPORARY)                   buffer[16] = 'T';
2682                         if (attrs & FILE_ATTRIBUTE_SPARSE_FILE)                 buffer[18] = 'P';
2683                         if (attrs & FILE_ATTRIBUTE_REPARSE_POINT)               buffer[20] = 'Q';
2684                         if (attrs & FILE_ATTRIBUTE_OFFLINE)                             buffer[22] = 'O';
2685                         if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
2686 #endif /* _NO_EXTENSIONS */
2687                 }
2688
2689                 if (calcWidthCol == -1)
2690                         output_tabbed_text(pane, dis, col, buffer);
2691                 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2692                         calc_tabbed_width(pane, dis, col, buffer);
2693
2694                 col++;
2695         }
2696
2697 /*TODO
2698         if (flags.security) {
2699                 DWORD rights = get_access_mask();
2700
2701                 tcscpy(buffer, TEXT(" \t \t \t  \t  \t \t \t  \t  \t \t \t "));
2702
2703                 if (rights & FILE_READ_DATA)                    buffer[ 0] = 'R';
2704                 if (rights & FILE_WRITE_DATA)                   buffer[ 2] = 'W';
2705                 if (rights & FILE_APPEND_DATA)                  buffer[ 4] = 'A';
2706                 if (rights & FILE_READ_EA)                              {buffer[6] = 'entry'; buffer[ 7] = 'R';}
2707                 if (rights & FILE_WRITE_EA)                             {buffer[9] = 'entry'; buffer[10] = 'W';}
2708                 if (rights & FILE_EXECUTE)                              buffer[12] = 'X';
2709                 if (rights & FILE_DELETE_CHILD)                 buffer[14] = 'D';
2710                 if (rights & FILE_READ_ATTRIBUTES)              {buffer[16] = 'a'; buffer[17] = 'R';}
2711                 if (rights & FILE_WRITE_ATTRIBUTES)             {buffer[19] = 'a'; buffer[20] = 'W';}
2712                 if (rights & WRITE_DAC)                                 buffer[22] = 'C';
2713                 if (rights & WRITE_OWNER)                               buffer[24] = 'O';
2714                 if (rights & SYNCHRONIZE)                               buffer[26] = 'S';
2715
2716                 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
2717         }
2718
2719         if (flags.description) {
2720                 get_description(buffer);
2721                 output_text(dis, col++, buffer, 0, psize);
2722         }
2723 */
2724
2725 #ifdef _NO_EXTENSIONS
2726   }
2727
2728         /* draw focus frame */
2729         if ((dis->itemState&ODS_FOCUS) && calcWidthCol==-1) {
2730                 /* Currently [04/2000] Wine neither behaves exactly the same */
2731                 /* way as WIN 95 nor like Windows NT... */
2732                 HGDIOBJ lastBrush;
2733                 HPEN lastPen;
2734                 HPEN hpen;
2735
2736                 if (!(GetVersion() & 0x80000000)) {     /* Windows NT? */
2737                         LOGBRUSH lb = {PS_SOLID, RGB(255,255,255)};
2738                         hpen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, 0);
2739                 } else
2740                         hpen = CreatePen(PS_DOT, 0, RGB(255,255,255));
2741
2742                 lastPen = SelectPen(dis->hDC, hpen);
2743                 lastBrush = SelectObject(dis->hDC, GetStockObject(HOLLOW_BRUSH));
2744                 SetROP2(dis->hDC, R2_XORPEN);
2745                 Rectangle(dis->hDC, focusRect.left, focusRect.top, focusRect.right, focusRect.bottom);
2746                 SelectObject(dis->hDC, lastBrush);
2747                 SelectObject(dis->hDC, lastPen);
2748                 DeleteObject(hpen);
2749         }
2750 #endif /* _NO_EXTENSIONS */
2751 }
2752
2753
2754 #ifdef _NO_EXTENSIONS
2755
2756 static void draw_splitbar(HWND hwnd, int x)
2757 {
2758         RECT rt;
2759         HDC hdc = GetDC(hwnd);
2760
2761         GetClientRect(hwnd, &rt);
2762
2763         rt.left = x - SPLIT_WIDTH/2;
2764         rt.right = x + SPLIT_WIDTH/2+1;
2765
2766         InvertRect(hdc, &rt);
2767
2768         ReleaseDC(hwnd, hdc);
2769 }
2770
2771 #endif /* _NO_EXTENSIONS */
2772
2773
2774 #ifndef _NO_EXTENSIONS
2775
2776 static void set_header(Pane* pane)
2777 {
2778         HD_ITEM item;
2779         int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
2780         int i=0, x=0;
2781
2782         item.mask = HDI_WIDTH;
2783         item.cxy = 0;
2784
2785         for(; x+pane->widths[i]<scroll_pos && i<COLUMNS; i++) {
2786                 x += pane->widths[i];
2787                 Header_SetItem(pane->hwndHeader, i, &item);
2788         }
2789
2790         if (i < COLUMNS) {
2791                 x += pane->widths[i];
2792                 item.cxy = x - scroll_pos;
2793                 Header_SetItem(pane->hwndHeader, i++, &item);
2794
2795                 for(; i<COLUMNS; i++) {
2796                         item.cxy = pane->widths[i];
2797                         x += pane->widths[i];
2798                         Header_SetItem(pane->hwndHeader, i, &item);
2799                 }
2800         }
2801 }
2802
2803 static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
2804 {
2805         switch(pnmh->code) {
2806                 case HDN_TRACK:
2807                 case HDN_ENDTRACK: {
2808                         HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
2809                         int idx = phdn->iItem;
2810                         int dx = phdn->pitem->cxy - pane->widths[idx];
2811                         int i;
2812
2813                         RECT clnt;
2814                         GetClientRect(pane->hwnd, &clnt);
2815
2816                         /* move immediate to simulate HDS_FULLDRAG (for now [04/2000] not realy needed with WINELIB) */
2817                         Header_SetItem(pane->hwndHeader, idx, phdn->pitem);
2818
2819                         pane->widths[idx] += dx;
2820
2821                         for(i=idx; ++i<=COLUMNS; )
2822                                 pane->positions[i] += dx;
2823
2824                         {
2825                                 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
2826                                 RECT rt_scr;
2827                                 RECT rt_clip;
2828
2829                                 rt_scr.left   = pane->positions[idx+1]-scroll_pos;
2830                                 rt_scr.top    = 0;
2831                                 rt_scr.right  = clnt.right;
2832                                 rt_scr.bottom = clnt.bottom;
2833
2834                                 rt_clip.left   = pane->positions[idx]-scroll_pos;
2835                                 rt_clip.top    = 0;
2836                                 rt_clip.right  = clnt.right;
2837                                 rt_clip.bottom = clnt.bottom;
2838
2839                                 if (rt_scr.left < 0) rt_scr.left = 0;
2840                                 if (rt_clip.left < 0) rt_clip.left = 0;
2841
2842                                 ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
2843
2844                                 rt_clip.right = pane->positions[idx+1];
2845                                 RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
2846
2847                                 if (pnmh->code == HDN_ENDTRACK) {
2848                                         ListBox_SetHorizontalExtent(pane->hwnd, pane->positions[COLUMNS]);
2849
2850                                         if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
2851                                                 set_header(pane);
2852                                 }
2853                         }
2854
2855                         return FALSE;
2856                 }
2857
2858                 case HDN_DIVIDERDBLCLICK: {
2859                         HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
2860                         HD_ITEM item;
2861
2862                         calc_single_width(pane, phdn->iItem);
2863                         item.mask = HDI_WIDTH;
2864                         item.cxy = pane->widths[phdn->iItem];
2865
2866                         Header_SetItem(pane->hwndHeader, phdn->iItem, &item);
2867                         InvalidateRect(pane->hwnd, 0, TRUE);
2868                         break;}
2869         }
2870
2871         return 0;
2872 }
2873
2874 #endif /* _NO_EXTENSIONS */
2875
2876
2877 static void scan_entry(ChildWnd* child, Entry* entry, HWND hwnd)
2878 {
2879         TCHAR path[MAX_PATH];
2880         int idx = ListBox_GetCurSel(child->left.hwnd);
2881         HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
2882
2883         /* delete sub entries in left pane */
2884         for(;;) {
2885                 LRESULT res = ListBox_GetItemData(child->left.hwnd, idx+1);
2886                 Entry* sub = (Entry*) res;
2887
2888                 if (res==LB_ERR || !sub || sub->level<=entry->level)
2889                         break;
2890
2891                 ListBox_DeleteString(child->left.hwnd, idx+1);
2892         }
2893
2894         /* empty right pane */
2895         ListBox_ResetContent(child->right.hwnd);
2896
2897         /* release memory */
2898         free_entries(entry);
2899
2900         /* read contents from disk */
2901 #ifdef _SHELL_FOLDERS
2902         if (entry->etype == ET_SHELL)
2903         {
2904                 read_directory(entry, NULL, child->sortOrder, hwnd);
2905         }
2906         else
2907 #endif
2908         {
2909                 get_path(entry, path);
2910                 read_directory(entry, path, child->sortOrder, hwnd);
2911         }
2912
2913         /* insert found entries in right pane */
2914         insert_entries(&child->right, entry->down, -1);
2915         calc_widths(&child->right, FALSE);
2916 #ifndef _NO_EXTENSIONS
2917         set_header(&child->right);
2918 #endif
2919
2920         child->header_wdths_ok = FALSE;
2921
2922         SetCursor(old_cursor);
2923 }
2924
2925
2926 /* expand a directory entry */
2927
2928 static BOOL expand_entry(ChildWnd* child, Entry* dir)
2929 {
2930         int idx;
2931         Entry* p;
2932
2933         if (!dir || dir->expanded || !dir->down)
2934                 return FALSE;
2935
2936         p = dir->down;
2937
2938         if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
2939                 p = p->next;
2940
2941                 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
2942                                 p->data.cFileName[2]=='\0' && p->next)
2943                         p = p->next;
2944         }
2945
2946         /* no subdirectories ? */
2947         if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2948                 return FALSE;
2949
2950         idx = ListBox_FindItemData(child->left.hwnd, 0, dir);
2951
2952         dir->expanded = TRUE;
2953
2954         /* insert entries in left pane */
2955         insert_entries(&child->left, p, idx);
2956
2957         if (!child->header_wdths_ok) {
2958                 if (calc_widths(&child->left, FALSE)) {
2959 #ifndef _NO_EXTENSIONS
2960                         set_header(&child->left);
2961 #endif
2962
2963                         child->header_wdths_ok = TRUE;
2964                 }
2965         }
2966
2967         return TRUE;
2968 }
2969
2970
2971 static void collapse_entry(Pane* pane, Entry* dir)
2972 {
2973         int idx = ListBox_FindItemData(pane->hwnd, 0, dir);
2974
2975         ShowWindow(pane->hwnd, SW_HIDE);
2976
2977         /* hide sub entries */
2978         for(;;) {
2979                 LRESULT res = ListBox_GetItemData(pane->hwnd, idx+1);
2980                 Entry* sub = (Entry*) res;
2981
2982                 if (res==LB_ERR || !sub || sub->level<=dir->level)
2983                         break;
2984
2985                 ListBox_DeleteString(pane->hwnd, idx+1);
2986         }
2987
2988         dir->expanded = FALSE;
2989
2990         ShowWindow(pane->hwnd, SW_SHOW);
2991 }
2992
2993
2994 static void set_curdir(ChildWnd* child, Entry* entry, HWND hwnd)
2995 {
2996         TCHAR path[MAX_PATH];
2997
2998         path[0] = '\0';
2999
3000         child->left.cur = entry;
3001         child->right.root = entry->down? entry->down: entry;
3002         child->right.cur = entry;
3003
3004         if (!entry->scanned)
3005                 scan_entry(child, entry, hwnd);
3006         else {
3007                 ListBox_ResetContent(child->right.hwnd);
3008                 insert_entries(&child->right, entry->down, -1);
3009                 calc_widths(&child->right, FALSE);
3010 #ifndef _NO_EXTENSIONS
3011                 set_header(&child->right);
3012 #endif
3013         }
3014
3015         get_path(entry, path);
3016         lstrcpy(child->path, path);
3017
3018         if (child->hwnd)        /* only change window title, if the window already exists */
3019                 SetWindowText(child->hwnd, path);
3020
3021         if (path[0])
3022                 SetCurrentDirectory(path);
3023 }
3024
3025
3026 BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow)
3027 {
3028         HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3029
3030         if ((int)hinst <= 32) {
3031                 display_error(hwnd, GetLastError());
3032                 return FALSE;
3033         }
3034
3035         return TRUE;
3036 }
3037
3038 #ifdef UNICODE
3039 BOOL launch_fileA(HWND hwnd, LPSTR cmd, UINT nCmdShow)
3040 {
3041         HINSTANCE hinst = ShellExecuteA(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3042
3043         if ((int)hinst <= 32) {
3044                 display_error(hwnd, GetLastError());
3045                 return FALSE;
3046         }
3047
3048         return TRUE;
3049 }
3050 #endif
3051
3052
3053 BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
3054 {
3055         TCHAR cmd[MAX_PATH];
3056
3057 #ifdef _SHELL_FOLDERS
3058         if (entry->etype == ET_SHELL) {
3059                 BOOL ret = TRUE;
3060
3061                 SHELLEXECUTEINFO shexinfo;
3062
3063                 shexinfo.cbSize = sizeof(SHELLEXECUTEINFO);
3064                 shexinfo.fMask = SEE_MASK_IDLIST;
3065                 shexinfo.hwnd = hwnd;
3066                 shexinfo.nShow = nCmdShow;
3067                 shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
3068
3069                 if (!ShellExecuteEx(&shexinfo)) {
3070                         display_error(hwnd, GetLastError());
3071                         ret = FALSE;
3072                 }
3073
3074                 if (shexinfo.lpIDList != entry->pidl)
3075                         (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, shexinfo.lpIDList);
3076
3077                 return ret;
3078         }
3079 #endif
3080
3081         get_path(entry, cmd);
3082
3083          /* start program, open document... */
3084         return launch_file(hwnd, cmd, nCmdShow);
3085 }
3086
3087
3088 static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
3089 {
3090         Entry* entry = pane->cur;
3091
3092         if (!entry)
3093                 return;
3094
3095         if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
3096                 int scanned_old = entry->scanned;
3097
3098                 if (!scanned_old)
3099                         scan_entry(child, entry, hwnd);
3100
3101 #ifndef _NO_EXTENSIONS
3102                 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
3103                         return;
3104 #endif
3105
3106                 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
3107                         entry = child->left.cur->up;
3108                         collapse_entry(&child->left, entry);
3109                         goto focus_entry;
3110                 } else if (entry->expanded)
3111                         collapse_entry(pane, child->left.cur);
3112                 else {
3113                         expand_entry(child, child->left.cur);
3114
3115                         if (!pane->treePane) focus_entry: {
3116                                 int idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), entry);
3117                                 ListBox_SetCurSel(child->left.hwnd, idx);
3118                                 set_curdir(child, entry, hwnd);
3119                         }
3120                 }
3121
3122                 if (!scanned_old) {
3123                         calc_widths(pane, FALSE);
3124
3125 #ifndef _NO_EXTENSIONS
3126                         set_header(pane);
3127 #endif
3128                 }
3129         } else {
3130                 launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
3131         }
3132 }
3133
3134
3135 static BOOL pane_command(Pane* pane, UINT cmd)
3136 {
3137         switch(cmd) {
3138                 case ID_VIEW_NAME:
3139                         if (pane->visible_cols) {
3140                                 pane->visible_cols = 0;
3141                                 calc_widths(pane, TRUE);
3142 #ifndef _NO_EXTENSIONS
3143                                 set_header(pane);
3144 #endif
3145                                 InvalidateRect(pane->hwnd, 0, TRUE);
3146                                 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
3147                                 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
3148                                 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3149                         }
3150                         break;
3151
3152                 case ID_VIEW_ALL_ATTRIBUTES:
3153                         if (pane->visible_cols != COL_ALL) {
3154                                 pane->visible_cols = COL_ALL;
3155                                 calc_widths(pane, TRUE);
3156 #ifndef _NO_EXTENSIONS
3157                                 set_header(pane);
3158 #endif
3159                                 InvalidateRect(pane->hwnd, 0, TRUE);
3160                                 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
3161                                 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
3162                                 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3163                         }
3164                         break;
3165
3166 #ifndef _NO_EXTENSIONS
3167                 case ID_PREFERED_SIZES: {
3168                         calc_widths(pane, TRUE);
3169                         set_header(pane);
3170                         InvalidateRect(pane->hwnd, 0, TRUE);
3171                         break;}
3172 #endif
3173
3174                         /* TODO: more command ids... */
3175
3176                 default:
3177                         return FALSE;
3178         }
3179
3180         return TRUE;
3181 }
3182
3183
3184 LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3185 {
3186         static int last_split;
3187
3188         ChildWnd* child = (ChildWnd*) GetWindowLong(hwnd, GWL_USERDATA);
3189         ASSERT(child);
3190
3191         switch(nmsg) {
3192                 case WM_DRAWITEM: {
3193                         LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
3194                         Entry* entry = (Entry*) dis->itemData;
3195
3196                         if (dis->CtlID == IDW_TREE_LEFT)
3197                                 draw_item(&child->left, dis, entry, -1);
3198                         else
3199                                 draw_item(&child->right, dis, entry, -1);
3200
3201                         return TRUE;}
3202
3203                 case WM_CREATE:
3204                         InitChildWindow(child);
3205                         break;
3206
3207                 case WM_NCDESTROY:
3208                         free_child_window(child);
3209                         SetWindowLong(hwnd, GWL_USERDATA, 0);
3210                         break;
3211
3212                 case WM_PAINT: {
3213                         PAINTSTRUCT ps;
3214                         HBRUSH lastBrush;
3215                         RECT rt;
3216                         GetClientRect(hwnd, &rt);
3217                         BeginPaint(hwnd, &ps);
3218                         rt.left = child->split_pos-SPLIT_WIDTH/2;
3219                         rt.right = child->split_pos+SPLIT_WIDTH/2+1;
3220                         lastBrush = SelectBrush(ps.hdc, (HBRUSH)GetStockObject(COLOR_SPLITBAR));
3221                         Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
3222                         SelectObject(ps.hdc, lastBrush);
3223 #ifdef _NO_EXTENSIONS
3224                         rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL);
3225                         FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH));
3226 #endif
3227                         EndPaint(hwnd, &ps);
3228                         break;}
3229
3230                 case WM_SETCURSOR:
3231                         if (LOWORD(lparam) == HTCLIENT) {
3232                                 POINT pt;
3233                                 GetCursorPos(&pt);
3234                                 ScreenToClient(hwnd, &pt);
3235
3236                                 if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
3237                                         SetCursor(LoadCursor(0, IDC_SIZEWE));
3238                                         return TRUE;
3239                                 }
3240                         }
3241                         goto def;
3242
3243                 case WM_LBUTTONDOWN: {
3244                         RECT rt;
3245                         int x = LOWORD(lparam);
3246
3247                         GetClientRect(hwnd, &rt);
3248
3249                         if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
3250                                 last_split = child->split_pos;
3251 #ifdef _NO_EXTENSIONS
3252                                 draw_splitbar(hwnd, last_split);
3253 #endif
3254                                 SetCapture(hwnd);
3255                         }
3256
3257                         break;}
3258
3259                 case WM_LBUTTONUP:
3260                         if (GetCapture() == hwnd) {
3261 #ifdef _NO_EXTENSIONS
3262                                 RECT rt;
3263                                 int x = LOWORD(lparam);
3264                                 draw_splitbar(hwnd, last_split);
3265                                 last_split = -1;
3266                                 GetClientRect(hwnd, &rt);
3267                                 child->split_pos = x;
3268                                 resize_tree(child, rt.right, rt.bottom);
3269 #endif
3270                                 ReleaseCapture();
3271                         }
3272                         break;
3273
3274 #ifdef _NO_EXTENSIONS
3275                 case WM_CAPTURECHANGED:
3276                         if (GetCapture()==hwnd && last_split>=0)
3277                                 draw_splitbar(hwnd, last_split);
3278                         break;
3279 #endif
3280
3281                 case WM_KEYDOWN:
3282                         if (wparam == VK_ESCAPE)
3283                                 if (GetCapture() == hwnd) {
3284                                         RECT rt;
3285 #ifdef _NO_EXTENSIONS
3286                                         draw_splitbar(hwnd, last_split);
3287 #else
3288                                         child->split_pos = last_split;
3289 #endif
3290                                         GetClientRect(hwnd, &rt);
3291                                         resize_tree(child, rt.right, rt.bottom);
3292                                         last_split = -1;
3293                                         ReleaseCapture();
3294                                         SetCursor(LoadCursor(0, IDC_ARROW));
3295                                 }
3296                         break;
3297
3298                 case WM_MOUSEMOVE:
3299                         if (GetCapture() == hwnd) {
3300                                 RECT rt;
3301                                 int x = LOWORD(lparam);
3302
3303 #ifdef _NO_EXTENSIONS
3304                                 HDC hdc = GetDC(hwnd);
3305                                 GetClientRect(hwnd, &rt);
3306
3307                                 rt.left = last_split-SPLIT_WIDTH/2;
3308                                 rt.right = last_split+SPLIT_WIDTH/2+1;
3309                                 InvertRect(hdc, &rt);
3310
3311                                 last_split = x;
3312                                 rt.left = x-SPLIT_WIDTH/2;
3313                                 rt.right = x+SPLIT_WIDTH/2+1;
3314                                 InvertRect(hdc, &rt);
3315
3316                                 ReleaseDC(hwnd, hdc);
3317 #else
3318                                 GetClientRect(hwnd, &rt);
3319
3320                                 if (x>=0 && x<rt.right) {
3321                                         child->split_pos = x;
3322                                         resize_tree(child, rt.right, rt.bottom);
3323                                         rt.left = x-SPLIT_WIDTH/2;
3324                                         rt.right = x+SPLIT_WIDTH/2+1;
3325                                         InvalidateRect(hwnd, &rt, FALSE);
3326                                         UpdateWindow(child->left.hwnd);
3327                                         UpdateWindow(hwnd);
3328                                         UpdateWindow(child->right.hwnd);
3329                                 }
3330 #endif
3331                         }
3332                         break;
3333
3334 #ifndef _NO_EXTENSIONS
3335                 case WM_GETMINMAXINFO:
3336                         DefMDIChildProc(hwnd, nmsg, wparam, lparam);
3337
3338                         {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
3339
3340                         lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
3341                         lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
3342                         break;}
3343 #endif /* _NO_EXTENSIONS */
3344
3345                 case WM_SETFOCUS:
3346                         SetCurrentDirectory(child->path);
3347                         SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
3348                         break;
3349
3350                 case WM_DISPATCH_COMMAND: {
3351                         Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3352
3353                         switch(LOWORD(wparam)) {
3354                                 case ID_WINDOW_NEW: {
3355                                         ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
3356
3357                                         if (!create_child_window(new_child))
3358                                                 free(new_child);
3359
3360                                         break;}
3361
3362                                 case ID_REFRESH:
3363                                         scan_entry(child, pane->cur, hwnd);
3364                                         break;
3365
3366                                 case ID_ACTIVATE:
3367                                         activate_entry(child, pane, hwnd);
3368                                         break;
3369
3370                                 default:
3371                                         return pane_command(pane, LOWORD(wparam));
3372                         }
3373
3374                         return TRUE;}
3375
3376                 case WM_COMMAND: {
3377                         Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3378
3379                         switch(HIWORD(wparam)) {
3380                                 case LBN_SELCHANGE: {
3381                                         int idx = ListBox_GetCurSel(pane->hwnd);
3382                                         Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
3383
3384                                         if (pane == &child->left)
3385                                                 set_curdir(child, entry, hwnd);
3386                                         else
3387                                                 pane->cur = entry;
3388                                         break;}
3389
3390                                 case LBN_DBLCLK:
3391                                         activate_entry(child, pane, hwnd);
3392                                         break;
3393                         }
3394                         break;}
3395
3396 #ifndef _NO_EXTENSIONS
3397                 case WM_NOTIFY: {
3398                         NMHDR* pnmh = (NMHDR*) lparam;
3399                         return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
3400 #endif
3401
3402                 case WM_SIZE:
3403                         if (wparam != SIZE_MINIMIZED)
3404                                 resize_tree(child, LOWORD(lparam), HIWORD(lparam));
3405                         /* fall through */
3406
3407                 default: def:
3408                         return DefMDIChildProc(hwnd, nmsg, wparam, lparam);
3409         }
3410
3411         return 0;
3412 }
3413
3414
3415 LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3416 {
3417         ChildWnd* child = (ChildWnd*) GetWindowLong(GetParent(hwnd), GWL_USERDATA);
3418         Pane* pane = (Pane*) GetWindowLong(hwnd, GWL_USERDATA);
3419         ASSERT(child);
3420
3421         switch(nmsg) {
3422 #ifndef _NO_EXTENSIONS
3423                 case WM_HSCROLL:
3424                         set_header(pane);
3425                         break;
3426 #endif
3427
3428                 case WM_SETFOCUS:
3429                         child->focus_pane = pane==&child->right? 1: 0;
3430                         ListBox_SetSel(hwnd, TRUE, 1);
3431                         /*TODO: check menu items */
3432                         break;
3433
3434                 case WM_KEYDOWN:
3435                         if (wparam == VK_TAB) {
3436                                 /*TODO: SetFocus(Globals.hdrivebar) */
3437                                 SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
3438                         }
3439         }
3440
3441         return CallWindowProc(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
3442 }
3443
3444
3445 static void InitInstance(HINSTANCE hinstance)
3446 {
3447         WNDCLASSEX wcFrame;
3448         WNDCLASS wcChild;
3449         ATOM hChildClass;
3450
3451         INITCOMMONCONTROLSEX icc = {
3452                 sizeof(INITCOMMONCONTROLSEX),
3453                 ICC_BAR_CLASSES
3454         };
3455
3456         HDC hdc = GetDC(0);
3457
3458         setlocale(LC_COLLATE, "");      /* set collating rules to local settings for compareName */
3459
3460         InitCommonControlsEx(&icc);
3461
3462
3463         /* register frame window class */
3464
3465         wcFrame.cbSize        = sizeof(WNDCLASSEX);
3466         wcFrame.style         = 0;
3467         wcFrame.lpfnWndProc   = FrameWndProc;
3468         wcFrame.cbClsExtra    = 0;
3469         wcFrame.cbWndExtra    = 0;
3470         wcFrame.hInstance     = hinstance;
3471         wcFrame.hIcon         = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_WINEFILE));
3472         wcFrame.hCursor       = LoadCursor(0, IDC_ARROW);
3473         wcFrame.hbrBackground = 0;
3474         wcFrame.lpszMenuName  = 0;
3475         wcFrame.lpszClassName = WINEFILEFRAME;
3476         wcFrame.hIconSm       = (HICON)LoadImage(hinstance,
3477                                                                                          MAKEINTRESOURCE(IDI_WINEFILE),
3478                                                                                          IMAGE_ICON,
3479                                                                                          GetSystemMetrics(SM_CXSMICON),
3480                                                                                          GetSystemMetrics(SM_CYSMICON),
3481                                                                                          LR_SHARED);
3482
3483         Globals.hframeClass = RegisterClassEx(&wcFrame);
3484
3485
3486         /* register tree windows class */
3487
3488         wcChild.style         = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
3489         wcChild.lpfnWndProc   = ChildWndProc;
3490         wcChild.cbClsExtra    = 0;
3491         wcChild.cbWndExtra    = 0;
3492         wcChild.hInstance     = hinstance;
3493         wcChild.hIcon         = 0;
3494         wcChild.hCursor       = LoadCursor(0, IDC_ARROW);
3495         wcChild.hbrBackground = 0;
3496         wcChild.lpszMenuName  = 0;
3497         wcChild.lpszClassName = WINEFILETREE;
3498
3499         hChildClass = RegisterClass(&wcChild);
3500
3501
3502         Globals.haccel = LoadAccelerators(hinstance, MAKEINTRESOURCE(IDA_WINEFILE));
3503
3504         Globals.hfont = CreateFont(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("MS Sans Serif"));
3505
3506         ReleaseDC(0, hdc);
3507
3508         Globals.hInstance = hinstance;
3509
3510 #ifdef _SHELL_FOLDERS
3511         CoInitialize(NULL);
3512         CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
3513         SHGetDesktopFolder(&Globals.iDesktop);
3514         Globals.cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
3515 #endif
3516 }
3517
3518
3519 void show_frame(HWND hwndParent, int cmdshow)
3520 {
3521         TCHAR path[MAX_PATH];
3522         ChildWnd* child;
3523         HMENU hMenuFrame, hMenuWindow;
3524
3525         CLIENTCREATESTRUCT ccs;
3526
3527         if (Globals.hMainWnd)
3528                 return;
3529
3530         Globals.hwndParent = hwndParent;
3531
3532         hMenuFrame = LoadMenu(Globals.hInstance, MAKEINTRESOURCE(IDM_WINEFILE));
3533         hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
3534
3535         Globals.hMenuFrame = hMenuFrame;
3536         Globals.hMenuView = GetSubMenu(hMenuFrame, 3);
3537         Globals.hMenuOptions = GetSubMenu(hMenuFrame, 4);
3538
3539         ccs.hWindowMenu  = hMenuWindow;
3540         ccs.idFirstChild = IDW_FIRST_CHILD;
3541
3542
3543         /* create main window */
3544         Globals.hMainWnd = CreateWindowEx(0, (LPCTSTR)(int)Globals.hframeClass, TEXT("Wine File"), WS_OVERLAPPEDWINDOW,
3545                                         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3546                                         hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
3547
3548
3549         Globals.hmdiclient = CreateWindowEx(0, TEXT("MDICLIENT"), NULL,
3550                                         WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
3551                                         0, 0, 0, 0,
3552                                         Globals.hMainWnd, 0, Globals.hInstance, &ccs);
3553
3554
3555         {
3556                 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0};
3557                 int btn = 1;
3558                 PTSTR p;
3559
3560                 Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
3561                                         IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
3562                                         1, 16, 13, 16, 13, sizeof(TBBUTTON));
3563                 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
3564
3565                 GetLogicalDriveStrings(BUFFER_LEN, Globals.drives);
3566
3567                 drivebarBtn.fsStyle = TBSTYLE_BUTTON;
3568
3569 #ifndef _NO_EXTENSIONS
3570 #ifdef __WINE__
3571                 /* insert unix file system button */
3572                 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)TEXT("/\0"));
3573
3574                 drivebarBtn.idCommand = ID_DRIVE_UNIX_FS;
3575                 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3576                 drivebarBtn.iString++;
3577 #endif
3578 #ifdef _SHELL_FOLDERS
3579                 /* insert shell namespace button */
3580                 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)TEXT("Shell\0"));
3581
3582                 drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
3583                 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3584                 drivebarBtn.iString++;
3585 #endif
3586
3587                 /* register windows drive root strings */
3588                 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)Globals.drives);
3589 #endif
3590
3591                 drivebarBtn.idCommand = ID_DRIVE_FIRST;
3592
3593                 for(p=Globals.drives; *p; ) {
3594 #ifdef _NO_EXTENSIONS
3595                   /* insert drive letter */
3596                         TCHAR b[3] = {tolower(*p)};
3597                         SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b);
3598 #endif
3599                         switch(GetDriveType(p)) {
3600                                 case DRIVE_REMOVABLE:   drivebarBtn.iBitmap = 1;        break;
3601                                 case DRIVE_CDROM:               drivebarBtn.iBitmap = 3;        break;
3602                                 case DRIVE_REMOTE:              drivebarBtn.iBitmap = 4;        break;
3603                                 case DRIVE_RAMDISK:             drivebarBtn.iBitmap = 5;        break;
3604                                 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
3605                         }
3606
3607                         SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3608                         drivebarBtn.idCommand++;
3609                         drivebarBtn.iString++;
3610
3611                         while(*p++);
3612                 }
3613         }
3614
3615         {
3616                 TBBUTTON toolbarBtns[] = {
3617                         {0, 0, 0, TBSTYLE_SEP, {0, 0}, 0, 0},
3618                         {0, ID_WINDOW_NEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0},
3619                         {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0},
3620                         {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0},
3621                         {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0},
3622 /*TODO
3623                         {4, ID_... , TBSTATE_ENABLED, TBSTYLE_BUTTON},
3624                         {5, ID_... , TBSTATE_ENABLED, TBSTYLE_BUTTON},
3625 */              };
3626
3627                 Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
3628                         IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
3629                         sizeof(toolbarBtns)/sizeof(TBBUTTON), 16, 15, 16, 15, sizeof(TBBUTTON));
3630                 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
3631         }
3632
3633         Globals.hstatusbar = CreateStatusWindow(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
3634         CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
3635
3636 /* CreateStatusWindow does not accept WS_BORDER
3637         Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
3638                                         WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
3639                                         Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
3640
3641         /*TODO: read paths and window placements from registry */
3642         GetCurrentDirectory(MAX_PATH, path);
3643
3644         ShowWindow(Globals.hMainWnd, cmdshow);
3645
3646 #if defined(_SHELL_FOLDERS) && !defined(_WINE_)
3647          /* Shell Namespace as default: */
3648         child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
3649 #else
3650         child = alloc_child_window(path, NULL, Globals.hMainWnd);
3651 #endif
3652
3653         child->pos.showCmd = SW_SHOWMAXIMIZED;
3654         child->pos.rcNormalPosition.left = 0;
3655         child->pos.rcNormalPosition.top = 0;
3656         child->pos.rcNormalPosition.right = 320;
3657         child->pos.rcNormalPosition.bottom = 280;
3658
3659         if (!create_child_window(child))
3660                 free(child);
3661
3662         SetWindowPlacement(child->hwnd, &child->pos);
3663
3664         Globals.himl = ImageList_LoadBitmap(Globals.hInstance, MAKEINTRESOURCE(IDB_IMAGES), 16, 0, RGB(0,255,0));
3665
3666         Globals.prescan_node = FALSE;
3667
3668         UpdateWindow(Globals.hMainWnd);
3669 }
3670
3671 void ExitInstance()
3672 {
3673 #ifdef _SHELL_FOLDERS
3674         (*Globals.iDesktop->lpVtbl->Release)(Globals.iDesktop);
3675         (*Globals.iMalloc->lpVtbl->Release)(Globals.iMalloc);
3676         CoUninitialize();
3677 #endif
3678
3679         ImageList_Destroy(Globals.himl);
3680 }
3681
3682
3683 /* search for already running win[e]files */
3684
3685 static int g_foundPrevInstance = 0;
3686
3687 static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam)
3688 {
3689         TCHAR cls[128];
3690
3691         GetClassName(hwnd, cls, 128);
3692
3693         if (!lstrcmp(cls, (LPCTSTR)lparam)) {
3694                 g_foundPrevInstance++;
3695                 return FALSE;
3696         }
3697
3698         return TRUE;
3699 }
3700
3701 /* search for window of given class name to allow only one running instance */
3702 int find_window_class(LPCTSTR classname)
3703 {
3704         EnumWindows(EnumWndProc, (LPARAM)classname);
3705
3706         if (g_foundPrevInstance)
3707                 return 1;
3708
3709         return 0;
3710 }
3711
3712
3713 int winefile_main(HINSTANCE hinstance, HWND hwndParent, int cmdshow)
3714 {
3715         MSG msg;
3716
3717         InitInstance(hinstance);
3718
3719 #ifndef _ROS_   /* don't maximize if being called from the ROS desktop */
3720         if (cmdshow == SW_SHOWNORMAL)
3721                 /*TODO: read window placement from registry */
3722                 cmdshow = SW_MAXIMIZE;
3723 #endif
3724
3725         show_frame(hwndParent, cmdshow);
3726
3727         while(GetMessage(&msg, 0, 0, 0)) {
3728                 if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
3729                         continue;
3730
3731                 if (Globals.hMainWnd && TranslateAccelerator(Globals.hMainWnd, Globals.haccel, &msg))
3732                         continue;
3733
3734                 TranslateMessage(&msg);
3735                 DispatchMessage(&msg);
3736         }
3737
3738         ExitInstance();
3739
3740         return msg.wParam;
3741 }
3742
3743
3744 #ifndef _ROS_
3745
3746 int APIENTRY WinMain(HINSTANCE hinstance,
3747                                          HINSTANCE previnstance,
3748                                          LPSTR     cmdline,
3749                                          int       cmdshow)
3750 {
3751 #ifdef _NO_EXTENSIONS
3752         if (find_window_class(WINEFILEFRAME))
3753                 return 1;
3754 #endif
3755
3756         winefile_main(hinstance, 0, cmdshow);
3757
3758         return 0;
3759 }
3760
3761 #endif