9750c198f57098a257df169b87565d8a221ac87b
[reactos.git] / reactos / 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
24 ZeroMemory(&tvi, sizeof(tvi));
25 ZeroMemory(&tvins, sizeof(tvins));
26
27 tvi.mask = TVIF_TEXT | TVIF_PARAM | TVIF_SELECTEDIMAGE | TVIF_IMAGE | TVIF_CHILDREN;
28 tvi.pszText = lpDisplayName;
29 tvi.cchTextMax = _tcslen(lpDisplayName);
30 tvi.cChildren = bHasChildren; //I_CHILDRENCALLBACK;
31
32 switch (ServiceType)
33 {
34 case SERVICE_WIN32_OWN_PROCESS:
35 case SERVICE_WIN32_SHARE_PROCESS:
36 tvi.iImage = 1;
37 tvi.iSelectedImage = 1;
38 break;
39
40 case SERVICE_KERNEL_DRIVER:
41 case SERVICE_FILE_SYSTEM_DRIVER:
42 tvi.iImage = 2;
43 tvi.iSelectedImage = 2;
44 break;
45
46 default:
47 tvi.iImage = 0;
48 tvi.iSelectedImage = 0;
49 break;
50 }
51
52 /* Attach the service name */
53 tvi.lParam = (LPARAM)(LPTSTR)HeapAlloc(GetProcessHeap(),
54 0,
55 (_tcslen(lpServiceName) + 1) * sizeof(TCHAR));
56 if (tvi.lParam)
57 {
58 _tcscpy((LPTSTR)tvi.lParam, lpServiceName);
59 }
60
61 tvins.item = tvi;
62 tvins.hParent = hParent;
63
64 return TreeView_InsertItem(hTreeView, &tvins);
65 }
66
67 static VOID
68 DestroyTreeView(HWND hTreeView)
69 {
70 //FIXME: traverse the nodes and free the strings
71 }
72
73 /*
74 static BOOL
75 TreeView_GetItemText(HWND hTreeView,
76 HTREEITEM hItem,
77 LPTSTR lpBuffer,
78 DWORD cbBuffer)
79 {
80 TVITEM tv = {0};
81
82 tv.mask = TVIF_TEXT | TVIF_HANDLE;
83 tv.hItem = hItem;
84 tv.pszText = lpBuffer;
85 tv.cchTextMax = (int)cbBuffer;
86
87 return TreeView_GetItem(hTreeView, &tv);
88 }
89
90
91 static LPARAM
92 TreeView_GetItemParam(HWND hTreeView,
93 HTREEITEM hItem)
94 {
95 LPARAM lParam = 0;
96 TVITEM tv = {0};
97
98 tv.mask = TVIF_PARAM | TVIF_HANDLE;
99 tv.hItem = hItem;
100
101 if (TreeView_GetItem(hTreeView, &tv))
102 {
103 lParam = tv.lParam;
104 }
105
106 return lParam;
107 }
108 */
109
110 static VOID
111 InitDependPage(PSERVICEPROPSHEET pDlgInfo)
112 {
113 /* Initialize the image list */
114 pDlgInfo->hDependsImageList = InitImageList(IDI_NODEPENDS,
115 IDI_DRIVER,
116 GetSystemMetrics(SM_CXSMICON),
117 GetSystemMetrics(SM_CXSMICON),
118 IMAGE_ICON);
119
120 /* Set the first tree view */
121 TV1_Initialize(pDlgInfo, pDlgInfo->pService->lpServiceName);
122
123 /* Set the second tree view */
124 TV2_Initialize(pDlgInfo, pDlgInfo->pService->lpServiceName);
125 }
126
127
128 /*
129 * Dependancies Property dialog callback.
130 * Controls messages to the Dependancies dialog
131 */
132 INT_PTR CALLBACK
133 DependenciesPageProc(HWND hwndDlg,
134 UINT uMsg,
135 WPARAM wParam,
136 LPARAM lParam)
137 {
138 PSERVICEPROPSHEET pDlgInfo;
139
140 /* Get the window context */
141 pDlgInfo = (PSERVICEPROPSHEET)GetWindowLongPtr(hwndDlg,
142 GWLP_USERDATA);
143 if (pDlgInfo == NULL && uMsg != WM_INITDIALOG)
144 {
145 return FALSE;
146 }
147
148 switch (uMsg)
149 {
150 case WM_INITDIALOG:
151 {
152 pDlgInfo = (PSERVICEPROPSHEET)(((LPPROPSHEETPAGE)lParam)->lParam);
153 if (pDlgInfo != NULL)
154 {
155 SetWindowLongPtr(hwndDlg,
156 GWLP_USERDATA,
157 (LONG_PTR)pDlgInfo);
158
159 pDlgInfo->hDependsWnd = hwndDlg;
160
161 InitDependPage(pDlgInfo);
162 }
163 }
164 break;
165
166 case WM_NOTIFY:
167 {
168 switch (((LPNMHDR)lParam)->code)
169 {
170 case TVN_ITEMEXPANDING:
171 {
172 LPNMTREEVIEW lpnmtv = (LPNMTREEVIEW)lParam;
173
174 if (lpnmtv->action == TVE_EXPAND)
175 {
176 if (lpnmtv->hdr.idFrom == IDC_DEPEND_TREE1)
177 {
178 TV1_AddDependantsToTree(pDlgInfo, lpnmtv->itemNew.hItem, (LPTSTR)lpnmtv->itemNew.lParam);
179 }
180 else if (lpnmtv->hdr.idFrom == IDC_DEPEND_TREE2)
181 {
182 TV2_AddDependantsToTree(pDlgInfo, lpnmtv->itemNew.hItem, (LPTSTR)lpnmtv->itemNew.lParam);
183 }
184 }
185 break;
186 }
187 }
188 break;
189 }
190
191 case WM_COMMAND:
192 switch(LOWORD(wParam))
193 {
194
195 }
196 break;
197
198 case WM_DESTROY:
199 DestroyTreeView(pDlgInfo->hDependsTreeView1);
200 DestroyTreeView(pDlgInfo->hDependsTreeView2);
201
202 if (pDlgInfo->hDependsImageList)
203 ImageList_Destroy(pDlgInfo->hDependsImageList);
204 }
205
206 return FALSE;
207 }