52eff0ea32cfdfbd3eae6a9baba295a28dfb5a43
[reactos.git] / rosapps / regedit / treeview.c
1 /*
2 * ReactOS regedit
3 *
4 * treeview.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 "treeview.h"
42
43 #include "trace.h"
44
45
46 // Global variables and constants
47 // Image_Open, Image_Closed, and Image_Root - integer variables for
48 // indexes of the images.
49 // CX_BITMAP and CY_BITMAP - width and height of an icon.
50 // NUM_BITMAPS - number of bitmaps to add to the image list.
51 int Image_Open;
52 int Image_Closed;
53 int Image_Root;
54
55 #define CX_BITMAP 16
56 #define CY_BITMAP 16
57 #define NUM_BITMAPS 3
58
59
60 #if 0
61 /*
62 // AddItemToTree - adds items to a tree view control.
63 // Returns the handle to the newly added item.
64 // hwndTV - handle to the tree view control.
65 // lpszItem - text of the item to add.
66 // nLevel - level at which to add the item.
67
68 HTREEITEM AddItemToTree(HWND hwndTV, LPTSTR lpszItem, int nLevel)
69 {
70 TVITEM tvi;
71 TVINSERTSTRUCT tvins;
72 static HTREEITEM hPrev = (HTREEITEM)TVI_FIRST;
73 static HTREEITEM hPrevRootItem = NULL;
74 static HTREEITEM hPrevLev2Item = NULL;
75 HTREEITEM hti;
76
77 tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
78
79 // Set the text of the item.
80 tvi.pszText = lpszItem;
81 tvi.cchTextMax = lstrlen(lpszItem);
82
83 // Assume the item is not a parent item, so give it an image.
84 tvi.iImage = Image_Root;
85 tvi.iSelectedImage = Image_Root;
86
87 tvi.cChildren = 1;
88
89
90 // Save the heading level in the item's application-defined data area.
91 tvi.lParam = (LPARAM)nLevel;
92
93 tvins.item = tvi;
94 tvins.hInsertAfter = hPrev;
95
96 // Set the parent item based on the specified level.
97 if (nLevel == 1)
98 tvins.hParent = TVI_ROOT;
99 else if (nLevel == 2)
100 tvins.hParent = hPrevRootItem;
101 else
102 tvins.hParent = hPrevLev2Item;
103
104 // Add the item to the tree view control.
105 hPrev = (HTREEITEM)SendMessage(hwndTV, TVM_INSERTITEM, 0, (LPARAM)(LPTVINSERTSTRUCT)&tvins);
106
107 // Save the handle to the item.
108 if (nLevel == 1)
109 hPrevRootItem = hPrev;
110 else if (nLevel == 2)
111 hPrevLev2Item = hPrev;
112
113 // The new item is a child item. Give the parent item a
114 // closed folder bitmap to indicate it now has child items.
115 if (nLevel > 1) {
116 hti = TreeView_GetParent(hwndTV, hPrev);
117 tvi.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
118 tvi.hItem = hti;
119 tvi.iImage = Image_Closed;
120 tvi.iSelectedImage = Image_Closed;
121 TreeView_SetItem(hwndTV, &tvi);
122 }
123
124 return hPrev;
125 }
126 */
127 #endif
128
129
130 static void init_output(HWND hWnd)
131 {
132 // TCHAR b[16];
133 // HFONT old_font;
134 HDC hdc = GetDC(hWnd);
135
136 // if (GetNumberFormat(LOCALE_USER_DEFAULT, 0, _T("1000"), 0, b, 16) > 4)
137 // Globals.num_sep = b[1];
138 // else
139 // Globals.num_sep = _T('.');
140
141 // old_font = SelectFont(hdc, Globals.hFont);
142 // GetTextExtentPoint32(hdc, _T(" "), 1, &Globals.spaceSize);
143 // SelectFont(hdc, old_font);
144 ReleaseDC(hWnd, hdc);
145 }
146
147 static HTREEITEM AddEntryToTree(HWND hwndTV, Entry* entry, LPTSTR label)
148 {
149 HTREEITEM hItem = 0;
150 TVITEM tvi;
151 TVINSERTSTRUCT tvins;
152 static HTREEITEM hPrev = (HTREEITEM)TVI_FIRST;
153 static HTREEITEM hPrevRootItem = NULL;
154 static HTREEITEM hPrevLev2Item = NULL;
155
156 //TRACE("AddEntryToTree(level:%u - %s)\n", entry->level, entry->data.cFileName);
157
158 tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
159 /*
160 // Set the text of the item.
161 tvi.pszText = entry->data.cFileName;
162 tvi.cchTextMax = lstrlen(entry->data.cFileName);
163 // Assume the item is not a parent item, so give it an image.
164 tvi.iImage = Image_Root;
165 tvi.iSelectedImage = Image_Root;
166 tvi.cChildren = 1;
167 // Save the heading level in the item's application-defined data area.
168 //tvi.lParam = (LPARAM)entry->level;
169 */
170 if (label != NULL) {
171 tvi.pszText = label;
172 tvi.cchTextMax = _tcslen(label);
173 } else {
174 tvi.pszText = LPSTR_TEXTCALLBACK;
175 tvi.cchTextMax = 0;
176 }
177 tvi.iImage = I_IMAGECALLBACK;
178 tvi.iSelectedImage = I_IMAGECALLBACK;
179 tvi.cChildren = I_CHILDRENCALLBACK;
180 // Save the entry pointer in the item's application-defined data area.
181 tvi.lParam = (LPARAM)entry;
182
183 tvins.item = tvi;
184 tvins.hInsertAfter = hPrev;
185
186 // Set the parent item based on the specified level.
187 if (entry->level == 0) {
188 tvins.hParent = TVI_ROOT;
189 } else if (entry->level == 1) {
190 tvins.hParent = hPrevRootItem;
191 } else {
192 tvins.hParent = hPrevLev2Item;
193 if (hPrevLev2Item) {
194 tvins.hParent = entry->up->hTreeItem;
195 }
196 }
197
198 // Add the item to the tree view control.
199 hPrev = (HTREEITEM)SendMessage(hwndTV, TVM_INSERTITEM, 0, (LPARAM)(LPTVINSERTSTRUCT)&tvins);
200
201 // Save the handle to the item.
202 if (entry->level == 0)
203 hPrevRootItem = hPrev;
204 else if (entry->level == 1)
205 hPrevLev2Item = hPrev;
206 /*
207 // The new item is a child item. Give the parent item a
208 // closed folder bitmap to indicate it now has child items.
209 if (entry->level > 1) {
210 HTREEITEM hti;
211 hti = TreeView_GetParent(hwndTV, hPrev);
212 tvi.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
213 tvi.hItem = hti;
214 tvi.iImage = Image_Closed;
215 tvi.iSelectedImage = Image_Closed;
216 TreeView_SetItem(hwndTV, &tvi);
217 }
218 */
219 hItem = hPrev;
220 return hItem;
221 }
222
223 // insert treectrl entries after index idx
224 static void insert_tree_entries(HWND hWnd, Entry* entry, int idx)
225 {
226 static HTREEITEM hItemVisible;
227 static int hItemVisibleIdx;
228
229 if (!entry)
230 return;
231
232 if (entry->hTreeItem)
233 return;
234
235 ShowWindow(hWnd, SW_HIDE);
236 for(; entry; entry=entry->next) {
237 /*
238 #ifndef _LEFT_FILES
239 if (!(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
240 continue;
241 #endif
242 // don't display entries "." and ".." in the left pane
243 if ((entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) && entry->data.cFileName[0]==_T('.')) {
244 if (entry->data.cFileName[1] == _T('\0') ||
245 (entry->data.cFileName[1] == _T('.') &&
246 entry->data.cFileName[2] == _T('\0'))) {
247 continue;
248 }
249 }
250 //TRACE("Adding item %u [level:%u] - %s\n", ++idx, entry->level, entry->data.cFileName);
251 */
252 if (entry->hTreeItem) continue;
253
254 entry->hTreeItem = AddEntryToTree(hWnd, entry, NULL);
255 if (entry->expanded) {
256 insert_tree_entries(hWnd, entry->down, idx + 1);
257 TreeView_Expand(hWnd, entry->hTreeItem, TVE_EXPAND);
258 }
259 if (idx > hItemVisibleIdx) {
260 hItemVisibleIdx = idx;
261 hItemVisible = entry->hTreeItem;
262 }
263 }
264 if (hItemVisible && idx == 0) {
265 TreeView_SelectSetFirstVisible(hWnd, hItemVisible);
266 }
267 ShowWindow(hWnd, SW_SHOW);
268 }
269
270 static BOOL InitTreeViewItems(HWND hwndTV, Root* pRoot/*LPCTSTR pHostName*/)
271 {
272 // HRESULT key;
273 //HRESULT openKey(LPSTR stdInput)
274 // key = openKey("HKEY_CLASSES_ROOT");
275 //LPSTR getRegKeyName(LPSTR lpLine);
276 //HKEY getRegClass(LPSTR lpLine);
277 // closeKey();
278
279 #define MAX_NAME_LEN 500
280
281 HKEY hKey;
282 LONG errCode;
283 Entry* pPrevEntry;
284 Entry* pEntry = &pRoot->entry;
285 HTREEITEM hRootItem;
286
287 // TCHAR* pHostName = _T("My Computer");
288 // HTREEITEM hRootItem = AddItemToTree(hwndTV, pHostName, 1);
289 // pEntry = malloc(sizeof(Entry));
290 // memset(pEntry, 0, sizeof(Entry));
291 // memset(pEntry, 0, sizeof(Entry));
292 //insert_tree_entries(hwndTV, pEntry, 0);
293 pEntry->level = 0;
294 pEntry->hTreeItem = AddEntryToTree(hwndTV, pEntry, pRoot->path);
295 hRootItem = pEntry->hTreeItem;
296 pPrevEntry = pEntry;
297 //HTREEITEM AddItemToTree(HWND hwndTV, LPTSTR lpszItem, int nLevel)
298 //HTREEITEM AddEntryToTree(HWND hwndTV, Entry* entry)
299 //static void insert_tree_entries(HWND hWnd, Entry* entry, int idx)
300
301 pEntry = malloc(sizeof(Entry));
302 memset(pEntry, 0, sizeof(Entry));
303 pEntry->up = &pRoot->entry;
304 pEntry->level = 1;
305 pEntry->hTreeItem = AddEntryToTree(hwndTV, pEntry, _T("HKEY_CLASSES_ROOT"));
306
307 pEntry = malloc(sizeof(Entry));
308 memset(pEntry, 0, sizeof(Entry));
309 pEntry->up = &pRoot->entry;
310 pEntry->level = 1;
311 pEntry->hTreeItem = AddEntryToTree(hwndTV, pEntry, _T("HKEY_CURRENT_USER"));
312
313 pEntry = malloc(sizeof(Entry));
314 memset(pEntry, 0, sizeof(Entry));
315 pEntry->up = &pRoot->entry;
316 pEntry->level = 1;
317 pEntry->hTreeItem = AddEntryToTree(hwndTV, pEntry, _T("HKEY_LOCAL_MACHINE"));
318
319 pPrevEntry = pEntry;
320
321 errCode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, NULL, 0, KEY_READ, &hKey);
322 if (errCode == ERROR_SUCCESS) {
323 TCHAR Name[MAX_NAME_LEN];
324 TCHAR Class[MAX_NAME_LEN];
325 FILETIME LastWriteTime;
326 DWORD dwIndex = 0L;
327 DWORD cName = MAX_NAME_LEN;
328 DWORD cClass = MAX_NAME_LEN;
329 while (RegEnumKeyEx(hKey, dwIndex, Name, &cName, NULL, Class, &cClass, &LastWriteTime) == ERROR_SUCCESS) {
330 //AddItemToTree(hwndTV, Name, 2);
331 pEntry = malloc(sizeof(Entry));
332 memset(pEntry, 0, sizeof(Entry));
333 pEntry->up = pPrevEntry;
334 pEntry->hKey = hKey;
335 pEntry->bKey = TRUE;
336 //insert_tree_entries(hwndTV, pEntry, 0);
337 pEntry->level = 2;
338 // pEntry->hTreeItem = AddEntryToTree(hwndTV, pEntry, Name);
339 pEntry->hTreeItem = AddEntryToTree(hwndTV, pEntry, NULL);
340 cName = MAX_NAME_LEN;
341 cClass = MAX_NAME_LEN;
342 ++dwIndex;
343 }
344 RegCloseKey(hKey);
345 TreeView_Expand(hwndTV, hRootItem, TVE_EXPAND);
346 }
347
348 pEntry = malloc(sizeof(Entry));
349 memset(pEntry, 0, sizeof(Entry));
350 pEntry->up = &pRoot->entry;
351 pEntry->level = 1;
352 pEntry->hTreeItem = AddEntryToTree(hwndTV, pEntry, _T("HKEY_USERS"));
353
354 pEntry = malloc(sizeof(Entry));
355 memset(pEntry, 0, sizeof(Entry));
356 pEntry->up = &pRoot->entry;
357 pEntry->level = 1;
358 pEntry->hTreeItem = AddEntryToTree(hwndTV, pEntry, _T("HKEY_CURRENT_CONFIG"));
359
360 return TRUE;
361 }
362 /*
363 AddItemToTree(hwndTV, _T("HKEY_CLASSES_ROOT"), 2);
364 AddItemToTree(hwndTV, _T("HKEY_CURRENT_USER"), 2);
365 AddItemToTree(hwndTV, _T("HKEY_LOCAL_MACHINE"), 2);
366 AddItemToTree(hwndTV, _T("HKEY_USERS"), 2);
367 AddItemToTree(hwndTV, _T("HKEY_CURRENT_CONFIG"), 2);
368 */
369 /*
370 LONG RegOpenKeyEx(
371 HKEY hKey, // handle to open key
372 LPCTSTR lpSubKey, // subkey name
373 DWORD ulOptions, // reserved
374 REGSAM samDesired, // security access mask
375 PHKEY phkResult // handle to open key
376 );
377
378 LONG RegEnumKey(
379 HKEY hKey, // handle to key to query
380 DWORD dwIndex, // index of subkey to query
381 LPTSTR lpName, // buffer for subkey name
382 DWORD cbName // size of subkey name buffer
383 );
384
385 LONG RegEnumKeyEx(
386 HKEY hKey, // handle to key to enumerate
387 DWORD dwIndex, // subkey index
388 LPTSTR lpName, // subkey name
389 LPDWORD lpcName, // size of subkey buffer
390 LPDWORD lpReserved, // reserved
391 LPTSTR lpClass, // class string buffer
392 LPDWORD lpcClass, // size of class string buffer
393 PFILETIME lpftLastWriteTime // last write time
394 );
395 */
396
397 /*
398 RegCloseKey
399 RegConnectRegistryW
400 RegCreateKeyW
401 RegDeleteKeyW
402 RegDeleteValueW
403 RegEnumKeyW
404 RegEnumValueW
405 RegFlushKey
406 RegOpenKeyExA
407 RegOpenKeyExW
408 RegOpenKeyW
409 RegQueryInfoKeyW
410 RegQueryValueExA
411 RegQueryValueExW
412 RegSetValueExA
413 RegSetValueExW
414 RegSetValueW
415 */
416
417 // InitTreeViewImageLists - creates an image list, adds three bitmaps
418 // to it, and associates the image list with a tree view control.
419 // Returns TRUE if successful, or FALSE otherwise.
420 // hwndTV - handle to the tree view control.
421
422 static BOOL InitTreeViewImageLists(HWND hwndTV)
423 {
424 HIMAGELIST himl; // handle to image list
425 HBITMAP hbmp; // handle to bitmap
426
427 // Create the image list.
428 if ((himl = ImageList_Create(CX_BITMAP, CY_BITMAP,
429 FALSE, NUM_BITMAPS, 0)) == NULL)
430 return FALSE;
431
432 // Add the open file, closed file, and document bitmaps.
433 hbmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_OPEN_FILE));
434 Image_Open = ImageList_Add(himl, hbmp, (HBITMAP) NULL);
435 DeleteObject(hbmp);
436
437 hbmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_CLOSED_FILE));
438 Image_Closed = ImageList_Add(himl, hbmp, (HBITMAP) NULL);
439 DeleteObject(hbmp);
440
441 hbmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_ROOT));
442 Image_Root = ImageList_Add(himl, hbmp, (HBITMAP) NULL);
443 DeleteObject(hbmp);
444
445 // Fail if not all of the images were added.
446 if (ImageList_GetImageCount(himl) < 3)
447 return FALSE;
448
449 // Associate the image list with the tree view control.
450 TreeView_SetImageList(hwndTV, himl, TVSIL_NORMAL);
451
452 return TRUE;
453 }
454
455 #ifndef _MSC_VER
456 #define NMTVDISPINFO TV_DISPINFO
457 #define NMTVDISPINFO TV_DISPINFO
458 #endif
459
460 static void OnGetDispInfo(NMTVDISPINFO* ptvdi)
461 {
462 FILETIME LastWriteTime;
463 TCHAR Class[MAX_NAME_LEN];
464 DWORD cClass = MAX_NAME_LEN;
465 // TCHAR Name[MAX_NAME_LEN];
466 // DWORD cName = MAX_NAME_LEN;
467 // DWORD dwIndex = 0L;
468
469 Entry* pEntry = (Entry*)ptvdi->item.lParam;
470 ASSERT(pEntry);
471
472 if (ptvdi->item.mask & TVIF_CHILDREN ) {
473 ptvdi->item.cChildren = 5;
474 }
475 if (ptvdi->item.mask & TVIF_IMAGE) {
476 ptvdi->item.iImage = Image_Root;
477 }
478 if (ptvdi->item.mask & TVIF_SELECTEDIMAGE) {
479 ptvdi->item.iSelectedImage = Image_Closed;
480 }
481 if (ptvdi->item.mask & TVIF_TEXT) {
482 ptvdi->item.pszText = _T("Unknown");
483 ptvdi->item.cchTextMax = _tcslen(ptvdi->item.pszText);
484 if (pEntry->bKey == TRUE) {
485 DWORD nSubKeys;
486 DWORD MaxSubKeyLen;
487 DWORD MaxClassLen;
488 DWORD ValueCount;
489 DWORD MaxValueNameLen;
490 DWORD MaxValueLen;
491 DWORD SecurityDescriptorLen;
492
493 HKEY hKey = pEntry->hKey;
494 LONG result = RegQueryInfoKey(pEntry->hKey, Class, &cClass, 0,
495 &nSubKeys, &MaxSubKeyLen, &MaxClassLen, &ValueCount,
496 &MaxValueNameLen, &MaxValueLen, &SecurityDescriptorLen,
497 &LastWriteTime);
498 if (result == ERROR_SUCCESS) {
499 // ptvdi->item.pszText = Class;
500 // ptvdi->item.cchTextMax = cClass;
501 }
502 }
503 // ptvdi->item.pszText = entry->data.cFileName;
504 // ptvdi->item.cchTextMax = lstrlen(entry->data.cFileName);
505 }
506 }
507
508 // OnEndLabelEdit - processes the LVN_ENDLABELEDIT notification message.
509 // Returns TRUE if the label is changed, or FALSE otherwise.
510
511 static BOOL OnEndLabelEdit(NMTVDISPINFO* ptvdi)
512 {
513 // if (ptvdi->item.iItem == -1)
514 // return FALSE;
515
516 // Copy the new label text to the application-defined structure.
517 // lstrcpyn(rgPetInfo[ptvdi->item.iItem].szKind, ptvdi->item.pszText, 10);
518
519 return TRUE;
520 // To make a more robust application you should send an EM_LIMITTEXT
521 // message to the edit control to prevent the user from entering too
522 // many characters in the field.
523 }
524
525 static BOOL OnExpand(int flag, HTREEITEM* pti)
526 {
527 TRACE(_T("TreeWndProc(...) OnExpand()\n"));
528 //TRACE("OnExpand(...) entry name: %s\n", entry->data.cFileName);
529 /*
530 TVE_COLLAPSE Collapses the list.
531 TVE_COLLAPSERESET Collapses the list and removes the child items. The TVIS_EXPANDEDONCE state flag is reset. This flag must be used with the TVE_COLLAPSE flag.
532 TVE_EXPAND Expands the list.
533 TVE_EXPANDPARTIAL Version 4.70. Partially expands the list. In this state, the child items are visible and the parent item's plus symbol is displayed. This flag must be used in combination with the TVE_EXPAND flag.
534 TVE_TOGGLE Collapses the list if it is expanded or expands it if it is collapsed.
535 */
536 return TRUE;
537 }
538
539 static BOOL OnExpanding(HWND hWnd, NMTREEVIEW* pnmtv)
540 {
541 static int expanding;
542
543 Entry* entry = (Entry*)pnmtv->itemNew.lParam;
544 TRACE(_T("TreeWndProc(...) OnExpanding() entry: %p\n"), entry);
545 if (expanding) return FALSE;
546 expanding = TRUE;
547 if (entry) {
548 insert_tree_entries(hWnd, entry->down, 0);
549 // insert_tree_entries(hWnd, entry, 0);
550 }
551 expanding = FALSE;
552 return TRUE;
553 }
554
555 /*
556 static BOOL OnSelChanged(NMTREEVIEW* pnmtv)
557 {
558 LPARAM parm = pnmtv->itemNew.lParam;
559 ChildWnd* child = (ChildWnd*)pnmtv->itemNew.lParam;
560 return TRUE;
561 }
562 */
563
564 ////////////////////////////////////////////////////////////////////////////////
565 static WNDPROC g_orgTreeWndProc;
566
567 static LRESULT CALLBACK TreeWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
568 {
569 // ChildWnd* child = (ChildWnd*)GetWindowLong(GetParent(hWnd), GWL_USERDATA);
570 // Pane* pane = (Pane*)GetWindowLong(hWnd, GWL_USERDATA);
571 // ASSERT(child);
572 switch (message) {
573 case WM_NOTIFY:
574 switch (((LPNMHDR)lParam)->code) {
575 case TVM_EXPAND:
576 //return OnExpand((int)wParam, (HTREEITEM*)lParam);
577 OnExpand((int)wParam, (HTREEITEM*)lParam);
578 break;
579 case TVN_GETDISPINFO:
580 OnGetDispInfo((NMTVDISPINFO*)lParam);
581 break;
582 case TVN_ITEMEXPANDING:
583 return OnExpanding(hWnd, (NMTREEVIEW*)lParam);
584 break;
585 case TVN_SELCHANGED:
586 // return OnSelChanged((NMTREEVIEW*)lParam);
587 // break;
588 #if 0
589 case TVN_SINGLEEXPAND:
590 TRACE("TreeWndProc(...) TVN_SINGLEEXPAND\n");
591 //lpnmtv = (LPNMTREEVIEW)lParam;
592 //return TVNRET_DEFAULT;
593 // return TVNRET_SKIPOLD; // Skip default processing of the item being unselected.
594 // return TVNRET_SKIPNEW; // Skip default processing of the item being selected.
595 break;
596 #endif
597 case TVN_ENDLABELEDIT:
598 return OnEndLabelEdit((NMTVDISPINFO*)lParam);
599 break;
600 }
601 return 0;
602 break;
603 case WM_SETFOCUS:
604 //child->nFocusPanel = pane == &child->right? 1: 0;
605 //TODO: check menu items
606 break;
607 case WM_KEYDOWN:
608 if (wParam == VK_TAB) {
609 //SetFocus(child->nFocusPanel ? child->left.hWnd: child->right.hWnd);
610 }
611 break;
612 }
613 return CallWindowProc(g_orgTreeWndProc, hWnd, message, wParam, lParam);
614 }
615
616 // CreateTreeView - creates a tree view control.
617 // Returns the handle to the new control if successful,
618 // or NULL otherwise.
619 // hwndParent - handle to the control's parent window.
620
621 HWND CreateTreeView(HWND hwndParent/*, Pane* pane*/, int id, Root* pRoot/*LPTSTR lpszPathName*/)
622 {
623 RECT rcClient; // dimensions of client area
624 HWND hwndTV; // handle to tree view control
625 // static int s_init = 0;
626 // Entry* entry = pane->root;
627 // pane->treePane = 1;
628
629 // Get the dimensions of the parent window's client area, and create
630 // the tree view control.
631 GetClientRect(hwndParent, &rcClient);
632 hwndTV = CreateWindowEx(0, WC_TREEVIEW, _T("Tree View"),
633 WS_VISIBLE | WS_CHILD | WS_BORDER | TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT,
634 0, 0, rcClient.right, rcClient.bottom,
635 hwndParent, (HMENU)id, hInst, NULL);
636 // Initialize the image list, and add items to the control.
637 if (!InitTreeViewImageLists(hwndTV) || !InitTreeViewItems(hwndTV, pRoot)) {
638 DestroyWindow(hwndTV);
639 return NULL;
640 }
641
642 SetWindowLong(hwndTV, GWL_USERDATA, (LPARAM)0);
643 g_orgTreeWndProc = SubclassWindow(hwndTV, TreeWndProc);
644 //SendMessage(hwndTV, WM_SETFONT, (WPARAM)Globals.hFont, FALSE);
645
646 // insert entries into treectrl
647 // if (entry) {
648 // insert_tree_entries(hwndTV, entry, 0);
649 // }
650
651 // calculate column widths
652 // if (!s_init) {
653 // s_init = 1;
654 // init_output(hwndTV);
655 // }
656
657 return hwndTV;
658 }
659