9d0e714f900ab89c0bc546899802d99c48d5505d
[reactos.git] / rosapps / regedit / listview.c
1 /*
2 * ReactOS regedit
3 *
4 * listview.c
5 *
6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
7 *
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.
12 *
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.
17 *
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.
21 */
22
23 #ifdef _MSC_VER
24 #include "stdafx.h"
25 #else
26 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
27 #include <windows.h>
28 #include <commctrl.h>
29 #include <stdlib.h>
30 #include <malloc.h>
31 #include <memory.h>
32 #include <tchar.h>
33 #include <process.h>
34 #include <stdio.h>
35 #endif
36
37 #include <windowsx.h>
38 #include <assert.h>
39 #define ASSERT assert
40 #include "main.h"
41 #include "listview.h"
42
43
44 ////////////////////////////////////////////////////////////////////////////////
45 // Global Variables:
46 //
47
48 static WNDPROC g_orgListWndProc;
49
50
51 ////////////////////////////////////////////////////////////////////////////////
52 // Local module support methods
53 //
54
55
56
57 #define MAX_LIST_COLUMNS (IDS_LIST_COLUMN_LAST - IDS_LIST_COLUMN_FIRST + 1)
58 static int default_column_widths[MAX_LIST_COLUMNS] = { 200, 175, 400 };
59 static int column_alignment[MAX_LIST_COLUMNS] = { LVCFMT_LEFT, LVCFMT_LEFT, LVCFMT_LEFT };
60
61 static void CreateListColumns(HWND hWndListView)
62 {
63 TCHAR szText[50];
64 int index;
65 LV_COLUMN lvC;
66
67 // Create columns.
68 lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
69 lvC.pszText = szText;
70
71 // Load the column labels from the resource file.
72 for (index = 0; index < MAX_LIST_COLUMNS; index++) {
73 lvC.iSubItem = index;
74 lvC.cx = default_column_widths[index];
75 lvC.fmt = column_alignment[index];
76 LoadString(hInst, IDS_LIST_COLUMN_FIRST + index, szText, sizeof(szText));
77 if (ListView_InsertColumn(hWndListView, index, &lvC) == -1) {
78 // TODO: handle failure condition...
79 break;
80 }
81 }
82 }
83
84
85 // OnGetDispInfo - processes the LVN_GETDISPINFO
86 // notification message.
87
88 static void OnGetDispInfo(NMLVDISPINFO* plvdi)
89 {
90 static TCHAR buffer[200];
91 // Entry* entry = (Entry*)plvdi->item.lParam;
92 // ASSERT(entry);
93 plvdi->item.pszText = NULL;
94
95 switch (plvdi->item.iSubItem) {
96 case 0:
97 // plvdi->item.pszText = entry->data.cFileName;
98 break;
99 case 1:
100 break;
101 case 2:
102 break;
103 case 3:
104 break;
105 case 4:
106 break;
107 default:
108 _tcscpy(buffer, _T(" "));
109 plvdi->item.pszText = buffer;
110 break;
111 }
112 }
113 static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
114 {
115 switch (LOWORD(wParam)) {
116 // case ID_FILE_OPEN:
117 // break;
118 default:
119 return FALSE;
120 }
121 return TRUE;
122 }
123 ////////////////////////////////////////////////////////////////////////////////
124
125 static LRESULT CALLBACK ListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
126 {
127 // ChildWnd* child = (ChildWnd*)GetWindowLong(GetParent(hWnd), GWL_USERDATA);
128 // Pane* pane = (Pane*)GetWindowLong(hWnd, GWL_USERDATA);
129 // ASSERT(child);
130
131 switch (message) {
132 /*
133 case WM_CREATE:
134 //CreateListView(hWnd);
135 return 0;
136 */
137 case WM_COMMAND:
138 if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
139 return CallWindowProc(g_orgListWndProc, hWnd, message, wParam, lParam);
140 }
141 break;
142 case WM_NOTIFY:
143 switch (((LPNMHDR)lParam)->code) {
144 case LVN_GETDISPINFO:
145 OnGetDispInfo((NMLVDISPINFO*)lParam);
146 break;
147 case NM_DBLCLK:
148 {
149 NMITEMACTIVATE* nmitem = (LPNMITEMACTIVATE)lParam;
150 LVHITTESTINFO info;
151
152 if (nmitem->hdr.hwndFrom != hWnd) break;
153 // if (nmitem->hdr.idFrom != IDW_LISTVIEW) break;
154 // if (nmitem->hdr.code != ???) break;
155 #ifdef _MSC_VER
156 switch (nmitem->uKeyFlags) {
157 case LVKF_ALT: // The ALT key is pressed.
158 // properties dialog box ?
159 break;
160 case LVKF_CONTROL: // The CTRL key is pressed.
161 // run dialog box for providing parameters...
162 break;
163 case LVKF_SHIFT: // The SHIFT key is pressed.
164 break;
165 }
166 #endif
167 info.pt.x = nmitem->ptAction.x;
168 info.pt.y = nmitem->ptAction.y;
169 if (ListView_HitTest(hWnd, &info) != -1) {
170 LVITEM item;
171 item.mask = LVIF_PARAM;
172 item.iItem = info.iItem;
173 if (ListView_GetItem(hWnd, &item)) {
174 // Entry* entry = (Entry*)item.lParam;
175 // OpenTarget(hWnd, entry->data.cFileName);
176 }
177 }
178 }
179 break;
180
181 default:
182 return CallWindowProc(g_orgListWndProc, hWnd, message, wParam, lParam);
183 }
184 break;
185 case WM_KEYDOWN:
186 if (wParam == VK_TAB) {
187 //TODO: SetFocus(Globals.hDriveBar)
188 //SetFocus(child->nFocusPanel? child->left.hWnd: child->right.hWnd);
189 }
190 break;
191 default:
192 return CallWindowProc(g_orgListWndProc, hWnd, message, wParam, lParam);
193 break;
194 }
195 return 0;
196 }
197
198
199 HWND CreateListView(HWND hwndParent/*, Pane* pane*/, int id, Root* pRoot/*Entry* pEntry*/)
200 {
201 RECT rcClient; // dimensions of client area
202 HWND hwndLV; // handle to list view control
203 // Entry* entry = pane->root;
204 // pane->treePane = 0;
205
206 // Get the dimensions of the parent window's client area, and create the list view control.
207 GetClientRect(hwndParent, &rcClient);
208 hwndLV = CreateWindowEx(0, WC_LISTVIEW, _T("List View"),
209 WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_REPORT,
210 0, 0, rcClient.right, rcClient.bottom,
211 hwndParent, (HMENU)id, hInst, NULL);
212
213 // Initialize the image list, and add items to the control.
214 /*
215 if (!InitListViewImageLists(hwndLV) ||
216 !InitListViewItems(hwndLV, lpszPathName)) {
217 DestroyWindow(hwndLV);
218 return FALSE;
219 }
220 */
221 ListView_SetExtendedListViewStyle(hwndLV, LVS_EX_FULLROWSELECT);
222 CreateListColumns(hwndLV);
223
224 SetWindowLong(hwndLV, GWL_USERDATA, (LPARAM)pRoot);
225 g_orgListWndProc = SubclassWindow(hwndLV, ListWndProc);
226 //SendMessage(hwndLV, WM_SETFONT, (WPARAM)Globals.hFont, FALSE);
227
228 // insert entries into listbox
229 // if (entry) {
230 // InsertListEntries(hwndLV, entry, -1);
231 // }
232
233 return hwndLV;
234 }
235
236 void RefreshList(HWND hWnd, Entry* entry)
237 {
238 if (hWnd != NULL) {
239 ListView_DeleteAllItems(hWnd);
240 /*
241 if (entry != NULL) {
242 TRACE("RefreshList(...) entry name: %s\n", entry->data.cFileName);
243 InsertListEntries(hWnd, entry, -1);
244 }
245 */
246 }
247 }
248