Synchronize up to trunk's revision r57689.
[reactos.git] / base / applications / mscutils / servman / propsheet_depends.c
1 /*
2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/mscutils/servman/propsheet_depends.c
5 * PURPOSE: Property dialog box message handler
6 * COPYRIGHT: Copyright 2006-2009 Ged Murphy <gedmurphy@reactos.org>
7 *
8 */
9
10 #include "precomp.h"
11
12
13 HTREEITEM
14 AddItemToTreeView(HWND hTreeView,
15 HTREEITEM hParent,
16 LPTSTR lpDisplayName,
17 LPTSTR lpServiceName,
18 ULONG ServiceType,
19 BOOL bHasChildren)
20 {
21 TV_ITEM tvi;
22 TV_INSERTSTRUCT tvins;
23 LPTSTR lpName;
24 DWORD dwSize;
25
26 ZeroMemory(&tvi, sizeof(tvi));
27 ZeroMemory(&tvins, sizeof(tvins));
28
29 tvi.mask = TVIF_TEXT | TVIF_PARAM | TVIF_SELECTEDIMAGE | TVIF_IMAGE | TVIF_CHILDREN;
30 tvi.pszText = lpDisplayName;
31 tvi.cchTextMax = _tcslen(lpDisplayName);
32 tvi.cChildren = bHasChildren;
33
34 /* Select the image for this service */
35 switch (ServiceType)
36 {
37 case SERVICE_WIN32_OWN_PROCESS:
38 case SERVICE_WIN32_SHARE_PROCESS:
39 tvi.iImage = IMAGE_SERVICE;
40 tvi.iSelectedImage = IMAGE_SERVICE;
41 break;
42
43 case SERVICE_KERNEL_DRIVER:
44 case SERVICE_FILE_SYSTEM_DRIVER:
45 tvi.iImage = IMAGE_DRIVER;
46 tvi.iSelectedImage = IMAGE_DRIVER;
47 break;
48
49 default:
50 tvi.iImage = IMAGE_UNKNOWN;
51 tvi.iSelectedImage = IMAGE_UNKNOWN;
52 break;
53 }
54
55 if (lpServiceName)
56 {
57 dwSize = _tcslen(lpServiceName) + 1;
58 /* Attach the service name */
59 lpName = (LPTSTR)HeapAlloc(GetProcessHeap(),
60 0,
61 dwSize * sizeof(TCHAR));
62 if (lpName)
63 {
64 _tcscpy_s(lpName, dwSize, lpServiceName);
65 tvi.lParam = (LPARAM)lpName;
66 }
67 }
68
69 tvins.item = tvi;
70 tvins.hParent = hParent;
71
72 return TreeView_InsertItem(hTreeView, &tvins);
73 }
74
75 static LPARAM
76 TreeView_GetItemParam(HWND hTreeView,
77 HTREEITEM hItem)
78 {
79 LPARAM lParam = 0;
80 TVITEM tv = {0};
81
82 tv.mask = TVIF_PARAM | TVIF_HANDLE;
83 tv.hItem = hItem;
84
85 if (TreeView_GetItem(hTreeView, &tv))
86 {
87 lParam = tv.lParam;
88 }
89
90 return lParam;
91 }
92
93 static VOID
94 DestroyItem(HWND hTreeView,
95 HTREEITEM hItem)
96 {
97 HTREEITEM hChildItem;
98 LPTSTR lpServiceName;
99
100 /* Does this item have any children */
101 hChildItem = TreeView_GetChild(hTreeView, hItem);
102 if (hChildItem)
103 {
104 /* It does, recurse to that one */
105 DestroyItem(hTreeView, hChildItem);
106 }
107
108 /* Get the string and free it */
109 lpServiceName = (LPTSTR)TreeView_GetItemParam(hTreeView, hItem);
110 if (lpServiceName)
111 {
112 HeapFree(GetProcessHeap(),
113 0,
114 lpServiceName);
115 }
116 }
117
118 static VOID
119 DestroyTreeView(HWND hTreeView)
120 {
121 HTREEITEM hItem;
122
123 /* Get the first item in the top level */
124 hItem = TreeView_GetFirstVisible(hTreeView);
125 if (hItem)
126 {
127 /* Kill it and all children */
128 DestroyItem(hTreeView, hItem);
129
130 /* Kill all remaining top level items */
131 while (hItem)
132 {
133 /* Are there any more items at the top level */
134 hItem = TreeView_GetNextSibling(hTreeView, hItem);
135 if (hItem)
136 {
137 /* Kill it and all children */
138 DestroyItem(hTreeView, hItem);
139 }
140 }
141 }
142 }
143
144 /*
145 static BOOL
146 TreeView_GetItemText(HWND hTreeView,
147 HTREEITEM hItem,
148 LPTSTR lpBuffer,
149 DWORD cbBuffer)
150 {
151 TVITEM tv = {0};
152
153 tv.mask = TVIF_TEXT | TVIF_HANDLE;
154 tv.hItem = hItem;
155 tv.pszText = lpBuffer;
156 tv.cchTextMax = (int)cbBuffer;
157
158 return TreeView_GetItem(hTreeView, &tv);
159 }
160 */
161
162 static VOID
163 InitDependPage(PSERVICEPROPSHEET pDlgInfo)
164 {
165 /* Initialize the image list */
166 pDlgInfo->hDependsImageList = InitImageList(IDI_NODEPENDS,
167 IDI_DRIVER,
168 GetSystemMetrics(SM_CXSMICON),
169 GetSystemMetrics(SM_CXSMICON),
170 IMAGE_ICON);
171
172 /* Set the first tree view */
173 TV1_Initialize(pDlgInfo, pDlgInfo->pService->lpServiceName);
174
175 /* Set the second tree view */
176 TV2_Initialize(pDlgInfo, pDlgInfo->pService->lpServiceName);
177 }
178
179
180 /*
181 * Dependancies Property dialog callback.
182 * Controls messages to the Dependancies dialog
183 */
184 INT_PTR CALLBACK
185 DependenciesPageProc(HWND hwndDlg,
186 UINT uMsg,
187 WPARAM wParam,
188 LPARAM lParam)
189 {
190 PSERVICEPROPSHEET pDlgInfo;
191
192 /* Get the window context */
193 pDlgInfo = (PSERVICEPROPSHEET)GetWindowLongPtr(hwndDlg,
194 GWLP_USERDATA);
195 if (pDlgInfo == NULL && uMsg != WM_INITDIALOG)
196 {
197 return FALSE;
198 }
199
200 switch (uMsg)
201 {
202 case WM_INITDIALOG:
203 {
204 pDlgInfo = (PSERVICEPROPSHEET)(((LPPROPSHEETPAGE)lParam)->lParam);
205 if (pDlgInfo != NULL)
206 {
207 SetWindowLongPtr(hwndDlg,
208 GWLP_USERDATA,
209 (LONG_PTR)pDlgInfo);
210
211 pDlgInfo->hDependsWnd = hwndDlg;
212
213 InitDependPage(pDlgInfo);
214 }
215 }
216 break;
217
218 case WM_NOTIFY:
219 {
220 switch (((LPNMHDR)lParam)->code)
221 {
222 case TVN_ITEMEXPANDING:
223 {
224 LPNMTREEVIEW lpnmtv = (LPNMTREEVIEW)lParam;
225
226 if (lpnmtv->action == TVE_EXPAND)
227 {
228 if (lpnmtv->hdr.idFrom == IDC_DEPEND_TREE1)
229 {
230 /* Has this node been expanded before */
231 if (!TreeView_GetChild(pDlgInfo->hDependsTreeView1, lpnmtv->itemNew.hItem))
232 {
233 /* It's not, add the children */
234 TV1_AddDependantsToTree(pDlgInfo, lpnmtv->itemNew.hItem, (LPTSTR)lpnmtv->itemNew.lParam);
235 }
236 }
237 else if (lpnmtv->hdr.idFrom == IDC_DEPEND_TREE2)
238 {
239 /* Has this node been expanded before */
240 if (!TreeView_GetChild(pDlgInfo->hDependsTreeView2, lpnmtv->itemNew.hItem))
241 {
242 /* It's not, add the children */
243 TV2_AddDependantsToTree(pDlgInfo, lpnmtv->itemNew.hItem, (LPTSTR)lpnmtv->itemNew.lParam);
244 }
245 }
246 }
247 break;
248 }
249 }
250 break;
251 }
252
253 case WM_COMMAND:
254 switch(LOWORD(wParam))
255 {
256
257 }
258 break;
259
260 case WM_DESTROY:
261 DestroyTreeView(pDlgInfo->hDependsTreeView1);
262 DestroyTreeView(pDlgInfo->hDependsTreeView2);
263
264 if (pDlgInfo->hDependsImageList)
265 ImageList_Destroy(pDlgInfo->hDependsImageList);
266 }
267
268 return FALSE;
269 }