6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
41 Entry
* find_entry_win(Entry
* parent
, LPCTSTR name
)
45 for(entry
=parent
->down
; entry
; entry
=entry
->next
) {
47 LPCTSTR q
= entry
->data
.cFileName
;
50 if (!*p
|| *p
==_T('\\') || *p
==_T('/'))
52 } while(tolower(*p
++) == tolower(*q
++));
55 q
= entry
->data
.cAlternateFileName
;
58 if (!*p
|| *p
==_T('\\') || *p
==_T('/'))
60 } while(tolower(*p
++) == tolower(*q
++));
67 Entry
* read_tree_win(Root
* root
, LPCTSTR path
, int sortOrder
)
69 TCHAR buffer
[MAX_PATH
];
70 Entry
* entry
= &root
->entry
;
74 #ifndef _NO_EXTENSIONS
75 entry
->unix_dir
= FALSE
;
79 while(*s
&& *s
!=_T('\\') && *s
!=_T('/'))
82 while(*s
==_T('\\') || *s
==_T('/'))
88 read_directory(entry
, buffer
, sortOrder
);
91 entry
->expanded
= TRUE
;
96 entry
= find_entry_win(entry
, s
);
103 #if !defined(_NO_EXTENSIONS) && defined(__linux__)
105 static Entry
* find_entry_unix(Entry
* parent
, LPCTSTR name
)
109 for(entry
=parent
->down
; entry
; entry
=entry
->next
) {
111 LPCTSTR q
= entry
->data
.cFileName
;
114 if (!*p
|| *p
==_T('/'))
116 } while(*p
++ == *q
++);
122 static Entry
* read_tree_unix(Root
* root
, LPCTSTR path
, int sortOrder
)
124 TCHAR buffer
[MAX_PATH
];
125 Entry
* entry
= &root
->entry
;
129 entry
->unix_dir
= TRUE
;
132 while(*s
&& *s
!=_T('/'))
141 read_directory(entry
, buffer
, sortOrder
);
144 entry
->expanded
= TRUE
;
149 entry
= find_entry_unix(entry
, s
);
158 // recursively free all child entries
159 void free_entries(Entry
* parent
)
161 Entry
*entry
, *next
=parent
->down
;
174 // insert listbox entries after index idx
175 void insert_entries(HWND hWnd
, Entry
* parent
, int idx
)
177 Entry
* entry
= parent
;
181 ShowWindow(hWnd
, SW_HIDE
);
182 for(; entry
; entry
=entry
->next
) {
184 if (!(entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
187 // don't display entries "." and ".." in the left pane
188 if ((entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
)
189 && entry
->data
.cFileName
[0]==_T('.'))
191 #ifndef _NO_EXTENSIONS
192 entry
->data
.cFileName
[1]==_T('\0') ||
194 (entry
->data
.cFileName
[1]==_T('.') && entry
->data
.cFileName
[2]==_T('\0')))
198 ListBox_InsertItemData(hWnd
, idx
, entry
);
200 insert_entries(hWnd
, entry
->down
, idx
);
202 ShowWindow(hWnd
, SW_SHOW
);
206 void scan_entry(ChildWnd
* child
, Entry
* entry
)
208 TCHAR path
[MAX_PATH
];
210 int idx = ListBox_GetCurSel(child->hTreeWnd);
211 HCURSOR crsrOld = SetCursor(LoadCursor(0, IDC_WAIT));
213 // delete sub entries in left pane
215 LRESULT res = ListBox_GetItemData(child->hTreeWnd, idx+1);
216 Entry* sub = (Entry*) res;
218 if (res==LB_ERR || !sub || sub->level<=entry->level)
221 ListBox_DeleteString(child->hTreeWnd, idx+1);
225 ListBox_ResetContent(child->hListWnd);
230 // read contents from disk
231 get_path(entry
, path
);
232 read_directory(entry
, path
, child
->sortOrder
);
234 // insert found entries in right pane
235 insert_entries(&child->right, entry->down, -1);
236 calc_widths(&child->right, FALSE);
237 #ifndef _NO_EXTENSIONS
238 set_header(&child->right);
241 child->header_wdths_ok = FALSE;
248 // expand a directory entry
249 BOOL
expand_entry(ChildWnd
* child
, Entry
* dir
)
254 if (!dir
|| dir
->expanded
|| !dir
->down
)
259 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='\0' && p
->next
) {
262 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='.' &&
263 p
->data
.cFileName
[2]=='\0' && p
->next
)
267 // no subdirectories ?
268 if (!(p
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
271 idx = ListBox_FindItemData(child->hTreeWnd, 0, dir);
273 dir
->expanded
= TRUE
;
275 // insert entries in left pane
276 insert_entries(child
->hTreeWnd
, p
, idx
);
278 if (!child->header_wdths_ok) {
279 if (calc_widths(&child->left, FALSE)) {
280 #ifndef _NO_EXTENSIONS
281 set_header(&child->left);
284 child->header_wdths_ok = TRUE;
292 void collapse_entry(Pane
* pane
, Entry
* dir
)
294 int idx
= ListBox_FindItemData(pane
->hWnd
, 0, dir
);
296 ShowWindow(pane
->hWnd
, SW_HIDE
);
300 LRESULT res
= ListBox_GetItemData(pane
->hWnd
, idx
+1);
301 Entry
* sub
= (Entry
*) res
;
303 if (res
==LB_ERR
|| !sub
|| sub
->level
<=dir
->level
)
306 ListBox_DeleteString(pane
->hWnd
, idx
+1);
309 dir
->expanded
= FALSE
;
311 ShowWindow(pane
->hWnd
, SW_SHOW
);
315 void activate_entry(ChildWnd
* child
, Pane
* pane
)
317 Entry
* entry
= pane
->cur
;
322 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
323 int scanned_old
= entry
->scanned
;
326 scan_entry(child
, entry
);
328 #ifndef _NO_EXTENSIONS
329 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='\0')
333 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
334 entry = child->left.cur->up;
335 collapse_entry(&child->left, entry);
337 } else if (entry->expanded)
338 collapse_entry(pane, child->left.cur);
340 expand_entry(child, child->left.cur);
342 if (!pane->treePane) focus_entry: {
343 int idx = ListBox_FindItemData(child->hTreeWnd, ListBox_GetCurSel(child->hTreeWnd), entry);
344 ListBox_SetCurSel(child->hTreeWnd, idx);
345 set_curdir(child, entry);
350 calc_widths(pane
, FALSE
);
351 #ifndef _NO_EXTENSIONS
357 //TODO: start program, open document...