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
44 // Global variables and constants
45 // Image_Open, Image_Closed, and Image_Root - integer variables for
46 // indexes of the images.
47 // CX_BITMAP and CY_BITMAP - width and height of an icon.
48 // NUM_BITMAPS - number of bitmaps to add to the image list.
58 // AddItemToTree - adds items to a tree view control.
59 // Returns the handle to the newly added item.
60 // hwndTV - handle to the tree view control.
61 // lpszItem - text of the item to add.
62 // nLevel - level at which to add the item.
64 HTREEITEM
AddItemToTree(HWND hwndTV
, LPTSTR lpszItem
, int nLevel
)
68 static HTREEITEM hPrev
= (HTREEITEM
)TVI_FIRST
;
69 static HTREEITEM hPrevRootItem
= NULL
;
70 static HTREEITEM hPrevLev2Item
= NULL
;
73 tvi
.mask
= TVIF_TEXT
| TVIF_IMAGE
| TVIF_SELECTEDIMAGE
| TVIF_CHILDREN
| TVIF_PARAM
;
75 // Set the text of the item.
76 tvi
.pszText
= lpszItem
;
77 tvi
.cchTextMax
= lstrlen(lpszItem
);
79 // Assume the item is not a parent item, so give it an image.
80 tvi
.iImage
= Image_Root
;
81 tvi
.iSelectedImage
= Image_Root
;
86 // Save the heading level in the item's application-defined data area.
87 tvi
.lParam
= (LPARAM
)nLevel
;
90 tvins
.hInsertAfter
= hPrev
;
92 // Set the parent item based on the specified level.
94 tvins
.hParent
= TVI_ROOT
;
96 tvins
.hParent
= hPrevRootItem
;
98 tvins
.hParent
= hPrevLev2Item
;
100 // Add the item to the tree view control.
101 hPrev
= (HTREEITEM
)SendMessage(hwndTV
, TVM_INSERTITEM
, 0, (LPARAM
)(LPTVINSERTSTRUCT
)&tvins
);
103 // Save the handle to the item.
105 hPrevRootItem
= hPrev
;
106 else if (nLevel
== 2)
107 hPrevLev2Item
= hPrev
;
109 // The new item is a child item. Give the parent item a
110 // closed folder bitmap to indicate it now has child items.
112 hti
= TreeView_GetParent(hwndTV
, hPrev
);
113 tvi
.mask
= TVIF_IMAGE
| TVIF_SELECTEDIMAGE
;
115 tvi
.iImage
= Image_Closed
;
116 tvi
.iSelectedImage
= Image_Closed
;
117 TreeView_SetItem(hwndTV
, &tvi
);
123 static void init_output(HWND hWnd
)
127 HDC hdc
= GetDC(hWnd
);
129 // if (GetNumberFormat(LOCALE_USER_DEFAULT, 0, _T("1000"), 0, b, 16) > 4)
130 // Globals.num_sep = b[1];
132 // Globals.num_sep = _T('.');
134 // old_font = SelectFont(hdc, Globals.hFont);
135 // GetTextExtentPoint32(hdc, _T(" "), 1, &Globals.spaceSize);
136 // SelectFont(hdc, old_font);
137 ReleaseDC(hWnd
, hdc
);
140 HTREEITEM AddEntryToTree(HWND hwndTV, Entry* entry)
147 static BOOL
InitTreeViewItems(HWND hwndTV
)
151 hItem
= AddItemToTree(hwndTV
, _T("My Computer"), 1);
152 AddItemToTree(hwndTV
, _T("HKEY_CLASSES_ROOT"), 2);
153 AddItemToTree(hwndTV
, _T("HKEY_CURRENT_USER"), 2);
154 AddItemToTree(hwndTV
, _T("HKEY_LOCAL_MACHINE"), 2);
155 AddItemToTree(hwndTV
, _T("HKEY_USERS"), 2);
156 AddItemToTree(hwndTV
, _T("HKEY_CURRENT_CONFIG"), 2);
158 TreeView_Expand(hwndTV
, hItem
, TVE_EXPAND
);
162 // InitTreeViewImageLists - creates an image list, adds three bitmaps
163 // to it, and associates the image list with a tree view control.
164 // Returns TRUE if successful, or FALSE otherwise.
165 // hwndTV - handle to the tree view control.
167 static BOOL
InitTreeViewImageLists(HWND hwndTV
)
169 HIMAGELIST himl
; // handle to image list
170 HBITMAP hbmp
; // handle to bitmap
172 // Create the image list.
173 if ((himl
= ImageList_Create(CX_BITMAP
, CY_BITMAP
,
174 FALSE
, NUM_BITMAPS
, 0)) == NULL
)
177 // Add the open file, closed file, and document bitmaps.
178 hbmp
= LoadBitmap(hInst
, MAKEINTRESOURCE(IDB_OPEN_FILE
));
179 Image_Open
= ImageList_Add(himl
, hbmp
, (HBITMAP
) NULL
);
182 hbmp
= LoadBitmap(hInst
, MAKEINTRESOURCE(IDB_CLOSED_FILE
));
183 Image_Closed
= ImageList_Add(himl
, hbmp
, (HBITMAP
) NULL
);
186 hbmp
= LoadBitmap(hInst
, MAKEINTRESOURCE(IDB_ROOT
));
187 Image_Root
= ImageList_Add(himl
, hbmp
, (HBITMAP
) NULL
);
190 // Fail if not all of the images were added.
191 if (ImageList_GetImageCount(himl
) < 3)
194 // Associate the image list with the tree view control.
195 TreeView_SetImageList(hwndTV
, himl
, TVSIL_NORMAL
);
201 #define NMTVDISPINFO TV_DISPINFO
202 #define NMTVDISPINFO TV_DISPINFO
205 static void OnGetDispInfo(NMTVDISPINFO
* ptvdi
)
208 Entry* entry = (Entry*)ptvdi->item.lParam;
211 if (ptvdi->item.mask & TVIF_CHILDREN ) {
212 ptvdi->item.cChildren = 5;
214 if (ptvdi->item.mask & TVIF_IMAGE) {
215 ptvdi->item.iImage = Image_Root;
217 if (ptvdi->item.mask & TVIF_SELECTEDIMAGE) {
218 ptvdi->item.iSelectedImage = Image_Closed;
220 if (ptvdi->item.mask & TVIF_TEXT) {
221 ptvdi->item.pszText = entry->data.cFileName;
222 ptvdi->item.cchTextMax = lstrlen(entry->data.cFileName);
224 static BOOL OnExpand(int flag, HTREEITEM* pti)
226 TRACE(_T("TreeWndProc(...) OnExpand()\n"));
230 static BOOL OnExpanding(HWND hWnd, NMTREEVIEW* pnmtv)
232 static int expanding;
234 if (expanding) return FALSE;
243 static BOOL OnSelChanged(NMTREEVIEW* pnmtv)
245 LPARAM parm = pnmtv->itemNew.lParam;
246 ChildWnd* child = (ChildWnd*)pnmtv->itemNew.lParam;
251 ////////////////////////////////////////////////////////////////////////////////
252 static WNDPROC g_orgTreeWndProc
;
254 static LRESULT CALLBACK
TreeWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
256 // ChildWnd* child = (ChildWnd*)GetWindowLong(GetParent(hWnd), GWL_USERDATA);
257 // Pane* pane = (Pane*)GetWindowLong(hWnd, GWL_USERDATA);
263 return CallWindowProc(g_orgTreeWndProc
, hWnd
, message
, wParam
, lParam
);
266 // CreateTreeView - creates a tree view control.
267 // Returns the handle to the new control if successful,
268 // or NULL otherwise.
269 // hwndParent - handle to the control's parent window.
271 HWND
CreateTreeView(HWND hwndParent
/*, Pane* pane*/, int id
, LPTSTR lpszPathName
)
273 RECT rcClient
; // dimensions of client area
274 HWND hwndTV
; // handle to tree view control
275 // static int s_init = 0;
276 // Entry* entry = pane->root;
277 // pane->treePane = 1;
279 // Get the dimensions of the parent window's client area, and create
280 // the tree view control.
281 GetClientRect(hwndParent
, &rcClient
);
282 hwndTV
= CreateWindowEx(0, WC_TREEVIEW
, _T("Tree View"),
283 WS_VISIBLE
| WS_CHILD
| WS_BORDER
| TVS_HASLINES
| TVS_HASBUTTONS
| TVS_LINESATROOT
,
284 0, 0, rcClient
.right
, rcClient
.bottom
,
285 hwndParent
, (HMENU
)id
, hInst
, NULL
);
286 // Initialize the image list, and add items to the control.
287 if (!InitTreeViewImageLists(hwndTV
) || !InitTreeViewItems(hwndTV
)) {
288 DestroyWindow(hwndTV
);
292 SetWindowLong(hwndTV
, GWL_USERDATA
, (LPARAM
)0);
293 g_orgTreeWndProc
= SubclassWindow(hwndTV
, TreeWndProc
);
294 //SendMessage(hwndTV, WM_SETFONT, (WPARAM)Globals.hFont, FALSE);
296 // insert entries into treectrl
298 // insert_tree_entries(hwndTV, entry, 0);
301 // calculate column widths
304 // init_output(hwndTV);