4e105a313e1f26ff62a9e4cf9f309d206bdb75f8
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.
26 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
45 Entry
* find_entry_win(Entry
* parent
, LPCTSTR name
)
49 for(entry
=parent
->down
; entry
; entry
=entry
->next
) {
51 LPCTSTR q
= entry
->data
.cFileName
;
54 if (!*p
|| *p
==_T('\\') || *p
==_T('/'))
56 } while(tolower(*p
++) == tolower(*q
++));
59 q
= entry
->data
.cAlternateFileName
;
62 if (!*p
|| *p
==_T('\\') || *p
==_T('/'))
64 } while(tolower(*p
++) == tolower(*q
++));
71 Entry
* read_tree_win(Root
* root
, LPCTSTR path
, int sortOrder
)
73 TCHAR buffer
[MAX_PATH
];
74 Entry
* entry
= &root
->entry
;
78 #ifndef _NO_EXTENSIONS
79 entry
->unix_dir
= FALSE
;
83 while(*s
&& *s
!=_T('\\') && *s
!=_T('/'))
86 while(*s
==_T('\\') || *s
==_T('/'))
92 read_directory(entry
, buffer
, sortOrder
);
95 entry
->expanded
= TRUE
;
100 entry
= find_entry_win(entry
, s
);
107 #if !defined(_NO_EXTENSIONS) && defined(__linux__)
109 static Entry
* find_entry_unix(Entry
* parent
, LPCTSTR name
)
113 for(entry
=parent
->down
; entry
; entry
=entry
->next
) {
115 LPCTSTR q
= entry
->data
.cFileName
;
118 if (!*p
|| *p
==_T('/'))
120 } while(*p
++ == *q
++);
126 static Entry
* read_tree_unix(Root
* root
, LPCTSTR path
, int sortOrder
)
128 TCHAR buffer
[MAX_PATH
];
129 Entry
* entry
= &root
->entry
;
133 entry
->unix_dir
= TRUE
;
136 while(*s
&& *s
!=_T('/'))
145 read_directory(entry
, buffer
, sortOrder
);
148 entry
->expanded
= TRUE
;
153 entry
= find_entry_unix(entry
, s
);
162 // recursively free all child entries
163 void free_entries(Entry
* parent
)
165 Entry
*entry
, *next
=parent
->down
;
178 // insert listbox entries after index idx
179 void insert_entries(Pane
* pane
, Entry
* parent
, int idx
)
182 Entry* entry = parent;
186 ShowWindow(pane->hWnd, SW_HIDE);
187 for(; entry; entry=entry->next) {
189 if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
192 // don't display entries "." and ".." in the left pane
193 if (pane->treePane && (entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
194 && entry->data.cFileName[0]==_T('.'))
196 #ifndef _NO_EXTENSIONS
197 entry->data.cFileName[1]==_T('\0') ||
199 (entry->data.cFileName[1]==_T('.') && entry->data.cFileName[2]==_T('\0')))
203 ListBox_InsertItemData(pane->hWnd, idx, entry);
204 if (pane->treePane && entry->expanded)
205 insert_entries(pane, entry->down, idx);
207 ShowWindow(pane->hWnd, SW_SHOW);
212 void scan_entry(ChildWnd
* child
, Entry
* entry
)
214 TCHAR path
[MAX_PATH
];
216 int idx = ListBox_GetCurSel(child->left.hWnd);
217 HCURSOR crsrOld = SetCursor(LoadCursor(0, IDC_WAIT));
219 // delete sub entries in left pane
221 LRESULT res = ListBox_GetItemData(child->left.hWnd, idx+1);
222 Entry* sub = (Entry*) res;
224 if (res==LB_ERR || !sub || sub->level<=entry->level)
227 ListBox_DeleteString(child->left.hWnd, idx+1);
231 ListBox_ResetContent(child->right.hWnd);
236 // read contents from disk
237 get_path(entry
, path
);
238 read_directory(entry
, path
, child
->sortOrder
);
240 // insert found entries in right pane
241 insert_entries(&child->right, entry->down, -1);
242 calc_widths(&child->right, FALSE);
243 #ifndef _NO_EXTENSIONS
244 set_header(&child->right);
247 child->header_wdths_ok = FALSE;
254 // expand a directory entry
255 BOOL
expand_entry(ChildWnd
* child
, Entry
* dir
)
260 if (!dir
|| dir
->expanded
|| !dir
->down
)
265 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='\0' && p
->next
) {
268 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='.' &&
269 p
->data
.cFileName
[2]=='\0' && p
->next
)
273 // no subdirectories ?
274 if (!(p
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
277 idx = ListBox_FindItemData(child->left.hWnd, 0, dir);
279 dir
->expanded
= TRUE
;
281 // insert entries in left pane
282 insert_entries(&child
->left
, p
, idx
);
284 if (!child->header_wdths_ok) {
285 if (calc_widths(&child->left, FALSE)) {
286 #ifndef _NO_EXTENSIONS
287 set_header(&child->left);
290 child->header_wdths_ok = TRUE;
298 void collapse_entry(Pane
* pane
, Entry
* dir
)
300 int idx
= ListBox_FindItemData(pane
->hWnd
, 0, dir
);
302 ShowWindow(pane
->hWnd
, SW_HIDE
);
306 LRESULT res
= ListBox_GetItemData(pane
->hWnd
, idx
+1);
307 Entry
* sub
= (Entry
*) res
;
309 if (res
==LB_ERR
|| !sub
|| sub
->level
<=dir
->level
)
312 ListBox_DeleteString(pane
->hWnd
, idx
+1);
315 dir
->expanded
= FALSE
;
317 ShowWindow(pane
->hWnd
, SW_SHOW
);
321 void activate_entry(ChildWnd
* child
, Pane
* pane
)
323 Entry
* entry
= pane
->cur
;
328 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
329 int scanned_old
= entry
->scanned
;
332 scan_entry(child
, entry
);
334 #ifndef _NO_EXTENSIONS
335 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='\0')
339 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='.' && entry
->data
.cFileName
[2]=='\0') {
340 entry
= child
->left
.cur
->up
;
341 collapse_entry(&child
->left
, entry
);
343 } else if (entry
->expanded
)
344 collapse_entry(pane
, child
->left
.cur
);
346 expand_entry(child
, child
->left
.cur
);
348 if (!pane
->treePane
) focus_entry
: {
349 int idx
= ListBox_FindItemData(child
->left
.hWnd
, ListBox_GetCurSel(child
->left
.hWnd
), entry
);
350 ListBox_SetCurSel(child
->left
.hWnd
, idx
);
351 set_curdir(child
, entry
);
356 calc_widths(pane
, FALSE
);
358 #ifndef _NO_EXTENSIONS
364 //TODO: start program, open document...