276c0b6491d2c06e9e15f51dc79aa9f4c1b5f9d0
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
;
182 // insert listbox entries after index idx
183 void insert_entries(Pane
* pane
, Entry
* parent
, int idx
)
185 Entry
* entry
= parent
;
190 ShowWindow(pane
->hwnd
, SW_HIDE
);
192 for(; entry
; entry
=entry
->next
) {
194 if (pane
->treePane
&& !(entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
198 // don't display entries "." and ".." in the left pane
199 if (pane
->treePane
&& (entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
)
200 && entry
->data
.cFileName
[0]==_T('.'))
202 #ifndef _NO_EXTENSIONS
203 entry
->data
.cFileName
[1]==_T('\0') ||
205 (entry
->data
.cFileName
[1]==_T('.') && entry
->data
.cFileName
[2]==_T('\0')))
211 ListBox_InsertItemData(pane
->hwnd
, idx
, entry
);
213 if (pane
->treePane
&& entry
->expanded
)
214 insert_entries(pane
, entry
->down
, idx
);
217 ShowWindow(pane
->hwnd
, SW_SHOW
);
221 void scan_entry(ChildWnd
* child
, Entry
* entry
)
223 TCHAR path
[MAX_PATH
];
224 int idx
= ListBox_GetCurSel(child
->left
.hwnd
);
225 HCURSOR crsrOld
= SetCursor(LoadCursor(0, IDC_WAIT
));
227 // delete sub entries in left pane
229 LRESULT res
= ListBox_GetItemData(child
->left
.hwnd
, idx
+1);
230 Entry
* sub
= (Entry
*) res
;
232 if (res
==LB_ERR
|| !sub
|| sub
->level
<=entry
->level
)
235 ListBox_DeleteString(child
->left
.hwnd
, idx
+1);
239 ListBox_ResetContent(child
->right
.hwnd
);
244 // read contents from disk
245 get_path(entry
, path
);
246 read_directory(entry
, path
, child
->sortOrder
);
248 // insert found entries in right pane
249 insert_entries(&child
->right
, entry
->down
, -1);
250 calc_widths(&child
->right
, FALSE
);
251 #ifndef _NO_EXTENSIONS
252 set_header(&child
->right
);
255 child
->header_wdths_ok
= FALSE
;
261 // expand a directory entry
262 BOOL
expand_entry(ChildWnd
* child
, Entry
* dir
)
267 if (!dir
|| dir
->expanded
|| !dir
->down
)
272 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='\0' && p
->next
) {
275 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='.' &&
276 p
->data
.cFileName
[2]=='\0' && p
->next
)
280 // no subdirectories ?
281 if (!(p
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
284 idx
= ListBox_FindItemData(child
->left
.hwnd
, 0, dir
);
286 dir
->expanded
= TRUE
;
288 // insert entries in left pane
289 insert_entries(&child
->left
, p
, idx
);
291 if (!child
->header_wdths_ok
) {
292 if (calc_widths(&child
->left
, FALSE
)) {
293 #ifndef _NO_EXTENSIONS
294 set_header(&child
->left
);
297 child
->header_wdths_ok
= TRUE
;
305 void collapse_entry(Pane
* pane
, Entry
* dir
)
307 int idx
= ListBox_FindItemData(pane
->hwnd
, 0, dir
);
309 ShowWindow(pane
->hwnd
, SW_HIDE
);
313 LRESULT res
= ListBox_GetItemData(pane
->hwnd
, idx
+1);
314 Entry
* sub
= (Entry
*) res
;
316 if (res
==LB_ERR
|| !sub
|| sub
->level
<=dir
->level
)
319 ListBox_DeleteString(pane
->hwnd
, idx
+1);
322 dir
->expanded
= FALSE
;
324 ShowWindow(pane
->hwnd
, SW_SHOW
);
328 void activate_entry(ChildWnd
* child
, Pane
* pane
)
330 Entry
* entry
= pane
->cur
;
335 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
336 int scanned_old
= entry
->scanned
;
339 scan_entry(child
, entry
);
341 #ifndef _NO_EXTENSIONS
342 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='\0')
346 if (entry
->data
.cFileName
[0]=='.' && entry
->data
.cFileName
[1]=='.' && entry
->data
.cFileName
[2]=='\0') {
347 entry
= child
->left
.cur
->up
;
348 collapse_entry(&child
->left
, entry
);
350 } else if (entry
->expanded
)
351 collapse_entry(pane
, child
->left
.cur
);
353 expand_entry(child
, child
->left
.cur
);
355 if (!pane
->treePane
) focus_entry
: {
356 int idx
= ListBox_FindItemData(child
->left
.hwnd
, ListBox_GetCurSel(child
->left
.hwnd
), entry
);
357 ListBox_SetCurSel(child
->left
.hwnd
, idx
);
358 set_curdir(child
, entry
);
363 calc_widths(pane
, FALSE
);
365 #ifndef _NO_EXTENSIONS
371 //TODO: start program, open document...