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>
52 extern HINSTANCE hInst
;
55 // Global variables and constants
56 // Image_Open, Image_Closed, and Image_Root - integer variables for
57 // indexes of the images.
58 // CX_BITMAP and CY_BITMAP - width and height of an icon.
59 // NUM_BITMAPS - number of bitmaps to add to the image list.
69 // AddItemToTree - adds items to a tree view control.
70 // Returns the handle to the newly added item.
71 // hwndTV - handle to the tree view control.
72 // lpszItem - text of the item to add.
73 // nLevel - level at which to add the item.
75 HTREEITEM
AddItemToTree(HWND hwndTV
, LPSTR lpszItem
, int nLevel
)
79 static HTREEITEM hPrev
= (HTREEITEM
)TVI_FIRST
;
80 static HTREEITEM hPrevRootItem
= NULL
;
81 static HTREEITEM hPrevLev2Item
= NULL
;
84 tvi
.mask
= TVIF_TEXT
| TVIF_IMAGE
| TVIF_SELECTEDIMAGE
| TVIF_PARAM
;
86 // Set the text of the item.
87 tvi
.pszText
= lpszItem
;
88 tvi
.cchTextMax
= lstrlen(lpszItem
);
90 // Assume the item is not a parent item, so give it an image.
91 tvi
.iImage
= Image_Root
;
92 tvi
.iSelectedImage
= Image_Root
;
97 // Save the heading level in the item's application-defined data area.
98 tvi
.lParam
= (LPARAM
)nLevel
;
101 tvins
.hInsertAfter
= hPrev
;
103 // Set the parent item based on the specified level.
105 tvins
.hParent
= TVI_ROOT
;
106 else if (nLevel
== 2)
107 tvins
.hParent
= hPrevRootItem
;
109 tvins
.hParent
= hPrevLev2Item
;
111 // Add the item to the tree view control.
112 hPrev
= (HTREEITEM
)SendMessage(hwndTV
, TVM_INSERTITEM
, 0, (LPARAM
)(LPTVINSERTSTRUCT
)&tvins
);
114 // Save the handle to the item.
116 hPrevRootItem
= hPrev
;
117 else if (nLevel
== 2)
118 hPrevLev2Item
= hPrev
;
120 // The new item is a child item. Give the parent item a
121 // closed folder bitmap to indicate it now has child items.
123 hti
= TreeView_GetParent(hwndTV
, hPrev
);
124 tvi
.mask
= TVIF_IMAGE
| TVIF_SELECTEDIMAGE
;
126 tvi
.iImage
= Image_Closed
;
127 tvi
.iSelectedImage
= Image_Closed
;
128 TreeView_SetItem(hwndTV
, &tvi
);
134 // InitTreeViewItems - extracts headings from the specified file and
135 // passes them to a function that adds them to a tree view control.
136 // Returns TRUE if successful, or FALSE otherwise.
137 // hwndTV - handle to the tree view control.
138 // lpszFileName - name of file with headings.
140 BOOL
InitTreeViewItems(HWND hwndTV
, LPSTR lpszFileName
)
144 hItem
= AddItemToTree(hwndTV
, "C:\\ - FAT32", 1);
145 AddItemToTree(hwndTV
, "reactos", 2);
146 AddItemToTree(hwndTV
, "bin", 3);
147 AddItemToTree(hwndTV
, "media", 3);
148 // AddItemToTree(hwndTV, "fonts", 4);
149 AddItemToTree(hwndTV
, "symbols", 3);
150 AddItemToTree(hwndTV
, "system32", 3);
151 // AddItemToTree(hwndTV, "config", 4);
152 // AddItemToTree(hwndTV, "drivers", 4);
154 TreeView_Expand(hwndTV
, hItem
, TVE_EXPAND
);
158 // InitTreeViewImageLists - creates an image list, adds three bitmaps
159 // to it, and associates the image list with a tree view control.
160 // Returns TRUE if successful, or FALSE otherwise.
161 // hwndTV - handle to the tree view control.
163 BOOL
InitTreeViewImageLists(HWND hwndTV
)
165 HIMAGELIST himl
; // handle to image list
166 HBITMAP hbmp
; // handle to bitmap
168 // Create the image list.
169 if ((himl
= ImageList_Create(CX_BITMAP
, CY_BITMAP
,
170 FALSE
, NUM_BITMAPS
, 0)) == NULL
)
173 // Add the open file, closed file, and document bitmaps.
174 hbmp
= LoadBitmap(hInst
, MAKEINTRESOURCE(IDB_OPEN_FILE
));
175 Image_Open
= ImageList_Add(himl
, hbmp
, (HBITMAP
) NULL
);
178 hbmp
= LoadBitmap(hInst
, MAKEINTRESOURCE(IDB_CLOSED_FILE
));
179 Image_Closed
= ImageList_Add(himl
, hbmp
, (HBITMAP
) NULL
);
182 hbmp
= LoadBitmap(hInst
, MAKEINTRESOURCE(IDB_ROOT
));
183 Image_Root
= ImageList_Add(himl
, hbmp
, (HBITMAP
) NULL
);
186 // Fail if not all of the images were added.
187 if (ImageList_GetImageCount(himl
) < 3)
190 // Associate the image list with the tree view control.
191 TreeView_SetImageList(hwndTV
, himl
, TVSIL_NORMAL
);
196 // CreateTreeView - creates a tree view control.
197 // Returns the handle to the new control if successful,
198 // or NULL otherwise.
199 // hwndParent - handle to the control's parent window.
200 // lpszFileName - name of the file to parse for tree view items.
202 HWND
CreateTreeView(HWND hwndParent
, LPSTR lpszFileName
)
204 RECT rcClient
; // dimensions of client area
205 HWND hwndTV
; // handle to tree view control
207 // Get the dimensions of the parent window's client area, and create
208 // the tree view control.
209 GetClientRect(hwndParent
, &rcClient
);
210 hwndTV
= CreateWindowEx(0, WC_TREEVIEW
, "Tree View",
211 WS_VISIBLE
| WS_CHILD
| WS_BORDER
| TVS_HASLINES
| TVS_HASBUTTONS
| TVS_LINESATROOT
,
212 0, 0, rcClient
.right
, rcClient
.bottom
,
213 hwndParent
, (HMENU
)TREE_WINDOW
, hInst
, NULL
);
215 hwndTV = CreateWindow(_T("ListBox"), _T(""), WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
216 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
217 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
219 // Initialize the image list, and add items to the control.
220 if (!InitTreeViewImageLists(hwndTV
) || !InitTreeViewItems(hwndTV
, lpszFileName
)) {
221 DestroyWindow(hwndTV
);
227 ////////////////////////////////////////////////////////////////////////////////
228 static WNDPROC g_orgTreeWndProc
;
230 LRESULT CALLBACK
TreeWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
232 ChildWnd
* child
= (ChildWnd
*)GetWindowLong(GetParent(hwnd
), GWL_USERDATA
);
233 Pane
* pane
= (Pane
*)GetWindowLong(hwnd
, GWL_USERDATA
);
237 #ifndef _NO_EXTENSIONS
244 child
->focus_pane
= pane
==&child
->right
? 1: 0;
245 ListBox_SetSel(hwnd
, TRUE
, 1);
246 //TODO: check menu items
250 if (wparam
== VK_TAB
) {
251 //TODO: SetFocus(Globals.hDriveBar)
252 SetFocus(child
->focus_pane
? child
->left
.hwnd
: child
->right
.hwnd
);
256 return CallWindowProc(g_orgTreeWndProc
, hwnd
, nmsg
, wparam
, lparam
);
260 static void init_output(HWND hwnd
)
264 HDC hdc
= GetDC(hwnd
);
266 if (GetNumberFormat(LOCALE_USER_DEFAULT
, 0, _T("1000"), 0, b
, 16) > 4)
267 Globals
.num_sep
= b
[1];
269 Globals
.num_sep
= _T('.');
271 old_font
= SelectFont(hdc
, Globals
.hFont
);
272 GetTextExtentPoint32(hdc
, _T(" "), 1, &Globals
.spaceSize
);
273 SelectFont(hdc
, old_font
);
274 ReleaseDC(hwnd
, hdc
);
278 void create_tree_window(HWND parent
, Pane
* pane
, int id
, int id_header
, LPSTR lpszFileName
)
280 static int s_init
= 0;
281 Entry
* entry
= pane
->root
;
283 pane
->hwnd
= CreateTreeView(parent
, lpszFileName
);
285 pane
->hwnd
= CreateWindow(_T("ListBox"), _T(""), WS_CHILD
|WS_VISIBLE
|WS_HSCROLL
|WS_VSCROLL
|
286 // LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
287 LBS_DISABLENOSCROLL
|LBS_NOINTEGRALHEIGHT
|LBS_NOTIFY
,
288 0, 0, 0, 0, parent
, (HMENU
)id
, Globals
.hInstance
, 0);
290 SetWindowLong(pane
->hwnd
, GWL_USERDATA
, (LPARAM
)pane
);
291 g_orgTreeWndProc
= SubclassWindow(pane
->hwnd
, TreeWndProc
);
293 SendMessage(pane
->hwnd
, WM_SETFONT
, (WPARAM
)Globals
.hFont
, FALSE
);
295 // insert entries into listbox
297 insert_entries(pane
, entry
, -1);
299 // calculate column widths
302 init_output(pane
->hwnd
);
305 calc_widths(pane
, TRUE
);
307 #ifndef _NO_EXTENSIONS
308 pane
->hwndHeader
= create_header(parent
, pane
, id_header
);