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
38 //#include <winspool.h>
47 //#include "entries.h"
53 extern HINSTANCE hInst
;
56 static void init_output(HWND hWnd
)
60 HDC hdc
= GetDC(hWnd
);
62 if (GetNumberFormat(LOCALE_USER_DEFAULT
, 0, _T("1000"), 0, b
, 16) > 4)
63 Globals
.num_sep
= b
[1];
65 Globals
.num_sep
= _T('.');
67 old_font
= SelectFont(hdc
, Globals
.hFont
);
68 GetTextExtentPoint32(hdc
, _T(" "), 1, &Globals
.spaceSize
);
69 SelectFont(hdc
, old_font
);
73 static void AddEntryToList(HWND hwndLV
, int idx
, Entry
* entry
)
77 item
.mask
= LVIF_TEXT
| LVIF_PARAM
;
82 // item.pszText = entry->data.cFileName;
83 item
.pszText
= LPSTR_TEXTCALLBACK
;
84 item
.cchTextMax
= strlen(entry
->data
.cFileName
);
86 // item.iImage = I_IMAGECALLBACK;
87 item
.lParam
= (LPARAM
)entry
;
88 #if (_WIN32_IE >= 0x0300)
91 ListView_InsertItem(hwndLV
, &item
);
94 // insert listctrl entries after index idx
95 static void InsertListEntries(Pane
* pane
, Entry
* parent
, int idx
)
97 Entry
* entry
= parent
;
101 ShowWindow(pane
->hWnd
, SW_HIDE
);
107 for(; entry
; entry
=entry
->next
) {
109 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
112 //ListBox_InsertItemData(pane->hWnd, idx, entry);
113 AddEntryToList(pane
->hWnd
, idx
, entry
);
116 ShowWindow(pane
->hWnd
, SW_SHOW
);
119 static void CreateListColumns(HWND hWndListView
)
126 lvC
.mask
= LVCF_FMT
| LVCF_WIDTH
| LVCF_TEXT
| LVCF_SUBITEM
;
127 lvC
.fmt
= LVCFMT_LEFT
;
129 lvC
.pszText
= szText
;
131 // Load the column labels from the resource file.
132 for (index
= 0; index
< 4; index
++) {
133 lvC
.iSubItem
= index
;
134 LoadString(hInst
, IDS_LIST_COLUMN_FIRST
+ index
, szText
, sizeof(szText
));
135 if (ListView_InsertColumn(hWndListView
, index
, &lvC
) == -1) {
136 // TODO: handle failure condition...
142 static HWND
CreateListView(HWND hwndParent
, int id
)
144 RECT rcClient
; // dimensions of client area
145 HWND hwndLV
; // handle to list view control
147 // Get the dimensions of the parent window's client area, and create the list view control.
148 GetClientRect(hwndParent
, &rcClient
);
149 hwndLV
= CreateWindowEx(0, WC_LISTVIEW
, "List View",
150 // WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_REPORT | LVS_NOCOLUMNHEADER,
151 WS_VISIBLE
| WS_CHILD
| WS_BORDER
| LVS_REPORT
,
152 // WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_LIST | LVS_NOCOLUMNHEADER,
153 0, 0, rcClient
.right
, rcClient
.bottom
,
154 hwndParent
, (HMENU
)id
, hInst
, NULL
);
156 // Initialize the image list, and add items to the control.
158 if (!InitListViewImageLists(hwndLV) ||
159 !InitListViewItems(hwndLV, lpszPathName)) {
160 DestroyWindow(hwndLV);
164 ListView_SetExtendedListViewStyle(hwndLV
, LVS_EX_FULLROWSELECT
);
165 CreateListColumns(hwndLV
);
170 // OnGetDispInfo - processes the LVN_GETDISPINFO
171 // notification message.
173 void OnGetDispInfo(NMLVDISPINFO
* plvdi
)
175 static char buffer
[200];
177 // LVITEM* pItem = &(plvdi->item);
178 // Entry* entry = (Entry*)pItem->lParam;
179 Entry
* entry
= (Entry
*)plvdi
->item
.lParam
;
182 switch (plvdi
->item
.iSubItem
) {
184 plvdi
->item
.pszText
= entry
->data
.cFileName
;
185 // item.cchTextMax = strlen(entry->data.cFileName);
186 // plvdi->item.pszText = rgPetInfo[plvdi->item.iItem].szKind;
189 if (entry
->bhfi_valid
) {
190 //entry->bhfi.nFileSizeLow;
191 //entry->bhfi.nFileSizeHigh;
193 //entry->bhfi.ftCreationTime
195 wsprintf(buffer
, "%u", entry
->bhfi
.nFileSizeLow
);
196 plvdi
->item
.pszText
= buffer
;
198 plvdi
->item
.pszText
= "unknown";
202 plvdi
->item
.pszText
= "TODO:";
205 //entry->bhfi.dwFileAttributes
206 // plvdi->item.pszText = "rhsa";
208 if (entry
->bhfi
.dwFileAttributes
& FILE_ATTRIBUTE_ARCHIVE
) strcat(buffer
, "a"); else strcat(buffer
, " ");
209 if (entry
->bhfi
.dwFileAttributes
& FILE_ATTRIBUTE_COMPRESSED
) strcat(buffer
, "c"); else strcat(buffer
, " ");
210 if (entry
->bhfi
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) strcat(buffer
, "d"); else strcat(buffer
, " ");
211 if (entry
->bhfi
.dwFileAttributes
& FILE_ATTRIBUTE_ENCRYPTED
) strcat(buffer
, "e"); else strcat(buffer
, " ");
212 if (entry
->bhfi
.dwFileAttributes
& FILE_ATTRIBUTE_HIDDEN
) strcat(buffer
, "h"); else strcat(buffer
, " ");
213 if (entry
->bhfi
.dwFileAttributes
& FILE_ATTRIBUTE_NORMAL
) strcat(buffer
, "n"); else strcat(buffer
, " ");
214 if (entry
->bhfi
.dwFileAttributes
& FILE_ATTRIBUTE_OFFLINE
) strcat(buffer
, "o"); else strcat(buffer
, " ");
215 if (entry
->bhfi
.dwFileAttributes
& FILE_ATTRIBUTE_READONLY
) strcat(buffer
, "r"); else strcat(buffer
, " ");
216 if (entry
->bhfi
.dwFileAttributes
& FILE_ATTRIBUTE_REPARSE_POINT
) strcat(buffer
, "p"); else strcat(buffer
, " ");
217 if (entry
->bhfi
.dwFileAttributes
& FILE_ATTRIBUTE_SPARSE_FILE
) strcat(buffer
, "f"); else strcat(buffer
, " ");
218 if (entry
->bhfi
.dwFileAttributes
& FILE_ATTRIBUTE_SYSTEM
) strcat(buffer
, "s"); else strcat(buffer
, " ");
219 if (entry
->bhfi
.dwFileAttributes
& FILE_ATTRIBUTE_TEMPORARY
) strcat(buffer
, "t"); else strcat(buffer
, " ");
220 plvdi
->item
.pszText
= buffer
;
222 FILE_ATTRIBUTE_ARCHIVE The file or directory is an archive file. Applications use this attribute to mark files for backup or removal.
223 FILE_ATTRIBUTE_COMPRESSED The file or directory is compressed. For a file, this means that all of the data in the file is compressed. For a directory, this means that compression is the default for newly created files and subdirectories.
224 FILE_ATTRIBUTE_DIRECTORY The handle identifies a directory.
225 FILE_ATTRIBUTE_ENCRYPTED The file or directory is encrypted. For a file, this means that all data in the file is encrypted. For a directory, this means that encryption is the default for newly created files and subdirectories.
226 FILE_ATTRIBUTE_HIDDEN The file or directory is hidden. It is not included in an ordinary directory listing.
227 FILE_ATTRIBUTE_NORMAL The file has no other attributes. This attribute is valid only if used alone.
228 FILE_ATTRIBUTE_OFFLINE The file data is not immediately available. This attribute indicates that the file data has been physically moved to offline storage. This attribute is used by Remote Storage, the hierarchical storage management software in Windows 2000. Applications should not arbitrarily change this attribute.
229 FILE_ATTRIBUTE_READONLY The file or directory is read-only. Applications can read the file but cannot write to it or delete it. In the case of a directory, applications cannot delete it.
230 FILE_ATTRIBUTE_REPARSE_POINT The file has an associated reparse point.
231 FILE_ATTRIBUTE_SPARSE_FILE The file is a sparse file.
232 FILE_ATTRIBUTE_SYSTEM The file or directory is part of the operating system or is used exclusively by the operating system.
233 FILE_ATTRIBUTE_TEMPORARY The file is being used for temporary storage. File systems attempt to keep all the data in memory for quicker access, rather than flushing the data back to mass storage. A temporary file should be deleted by the application as soon as it is no longer needed.
241 typedef struct _BY_HANDLE_FILE_INFORMATION {
242 DWORD dwFileAttributes;
243 FILETIME ftCreationTime;
244 FILETIME ftLastAccessTime;
245 FILETIME ftLastWriteTime;
246 DWORD dwVolumeSerialNumber;
249 DWORD nNumberOfLinks;
250 DWORD nFileIndexHigh;
252 } BY_HANDLE_FILE_INFORMATION, *PBY_HANDLE_FILE_INFORMATION;
256 // OnEndLabelEdit - processes the LVN_ENDLABELEDIT
257 // notification message.
258 // Returns TRUE if the label is changed, or FALSE otherwise.
260 BOOL
OnEndLabelEdit(NMLVDISPINFO
* plvdi
)
262 if (plvdi
->item
.iItem
== -1)
265 // Copy the new label text to the application-defined structure.
266 // lstrcpyn(rgPetInfo[plvdi->item.iItem].szKind, plvdi->item.pszText, 10);
269 // To make a more robust application you should send an EM_LIMITTEXT
270 // message to the edit control to prevent the user from entering too
271 // many characters in the field.
275 ////////////////////////////////////////////////////////////////////////////////
276 static WNDPROC g_orgListWndProc
;
278 static LRESULT CALLBACK
ListWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
280 ChildWnd
* child
= (ChildWnd
*)GetWindowLong(GetParent(hWnd
), GWL_USERDATA
);
281 Pane
* pane
= (Pane
*)GetWindowLong(hWnd
, GWL_USERDATA
);
287 //CreateListView(hWnd);
291 switch (((LPNMHDR
)lParam
)->code
) {
292 case LVN_GETDISPINFO
:
293 OnGetDispInfo((NMLVDISPINFO
*)lParam
);
295 case LVN_ENDLABELEDIT
:
296 return OnEndLabelEdit((NMLVDISPINFO
*)lParam
);
303 child
->nFocusPanel
= pane
==&child
->right
? 1: 0;
304 ListBox_SetSel(hWnd
, TRUE
, 1);
305 //TODO: check menu items
309 if (wParam
== VK_TAB
) {
310 //TODO: SetFocus(Globals.hDriveBar)
311 SetFocus(child
->nFocusPanel
? child
->left
.hWnd
: child
->right
.hWnd
);
314 return CallWindowProc(g_orgListWndProc
, hWnd
, message
, wParam
, lParam
);
318 void CreateListWnd(HWND parent
, Pane
* pane
, int id
, LPSTR lpszPathName
)
320 // static int s_init = 0;
321 Entry
* entry
= pane
->root
;
325 pane
->hWnd
= CreateListView(parent
, id
);
327 pane
->hWnd
= CreateWindow(_T("ListBox"), _T(""), WS_CHILD
|WS_VISIBLE
|WS_HSCROLL
|WS_VSCROLL
|
328 LBS_DISABLENOSCROLL
|LBS_NOINTEGRALHEIGHT
|LBS_OWNERDRAWFIXED
|LBS_NOTIFY
,
329 0, 0, 0, 0, parent
, (HMENU
)id
, Globals
.hInstance
, 0);
331 SetWindowLong(pane
->hWnd
, GWL_USERDATA
, (LPARAM
)pane
);
332 g_orgListWndProc
= SubclassWindow(pane
->hWnd
, ListWndProc
);
333 SendMessage(pane
->hWnd
, WM_SETFONT
, (WPARAM
)Globals
.hFont
, FALSE
);
335 // insert entries into listbox
337 InsertListEntries(pane
, entry
, -1);
339 // calculate column widths
342 // init_output(pane->hWnd);
344 // calc_widths(pane, TRUE);