ReactOS  0.4.12-dev-51-ge94618b
propsheet_depends.c
Go to the documentation of this file.
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 
16  LPWSTR lpServiceName,
17  ULONG ServiceType,
18  BOOL bHasChildren)
19 {
20  TV_ITEM tvi;
21  TV_INSERTSTRUCT tvins;
22  LPWSTR lpName;
23  DWORD dwSize;
24 
25  ZeroMemory(&tvi, sizeof(tvi));
26  ZeroMemory(&tvins, sizeof(tvins));
27 
29  tvi.pszText = lpDisplayName;
30  tvi.cchTextMax = wcslen(lpDisplayName);
31  tvi.cChildren = bHasChildren;
32 
33  /* Select the image for this service */
34  switch (ServiceType)
35  {
38  tvi.iImage = IMAGE_SERVICE;
39  tvi.iSelectedImage = IMAGE_SERVICE;
40  break;
41 
44  tvi.iImage = IMAGE_DRIVER;
45  tvi.iSelectedImage = IMAGE_DRIVER;
46  break;
47 
48  default:
49  tvi.iImage = IMAGE_UNKNOWN;
50  tvi.iSelectedImage = IMAGE_UNKNOWN;
51  break;
52  }
53 
54  if (lpServiceName)
55  {
56  dwSize = wcslen(lpServiceName) + 1;
57  /* Attach the service name */
58  lpName = (LPWSTR)HeapAlloc(GetProcessHeap(),
59  0,
60  dwSize * sizeof(WCHAR));
61  if (lpName)
62  {
63  StringCchCopyW(lpName, dwSize, lpServiceName);
64  tvi.lParam = (LPARAM)lpName;
65  }
66  }
67 
68  tvins.item = tvi;
69  tvins.hParent = hParent;
70 
71  return TreeView_InsertItem(hTreeView, &tvins);
72 }
73 
74 static LPARAM
77 {
78  LPARAM lParam = 0;
79  TVITEMW tv = {0};
80 
82  tv.hItem = hItem;
83 
84  if (TreeView_GetItem(hTreeView, &tv))
85  {
86  lParam = tv.lParam;
87  }
88 
89  return lParam;
90 }
91 
92 static VOID
93 DestroyItem(HWND hTreeView,
95 {
96  HTREEITEM hChildItem;
97  LPWSTR lpServiceName;
98 
99  /* Does this item have any children */
100  hChildItem = TreeView_GetChild(hTreeView, hItem);
101  if (hChildItem)
102  {
103  /* It does, recurse to that one */
104  DestroyItem(hTreeView, hChildItem);
105  }
106 
107  /* Get the string and free it */
108  lpServiceName = (LPWSTR)TreeView_GetItemParam(hTreeView, hItem);
109  if (lpServiceName)
110  {
112  0,
113  lpServiceName);
114  }
115 }
116 
117 static VOID
119 {
121 
122  /* Get the first item in the top level */
123  hItem = TreeView_GetFirstVisible(hTreeView);
124  if (hItem)
125  {
126  /* Kill it and all children */
127  DestroyItem(hTreeView, hItem);
128 
129  /* Kill all remaining top level items */
130  while (hItem)
131  {
132  /* Are there any more items at the top level */
133  hItem = TreeView_GetNextSibling(hTreeView, hItem);
134  if (hItem)
135  {
136  /* Kill it and all children */
137  DestroyItem(hTreeView, hItem);
138  }
139  }
140  }
141 }
142 
143 /*
144 static BOOL
145 TreeView_GetItemText(HWND hTreeView,
146  HTREEITEM hItem,
147  LPTSTR lpBuffer,
148  DWORD cbBuffer)
149 {
150  TVITEM tv = {0};
151 
152  tv.mask = TVIF_TEXT | TVIF_HANDLE;
153  tv.hItem = hItem;
154  tv.pszText = lpBuffer;
155  tv.cchTextMax = (int)cbBuffer;
156 
157  return TreeView_GetItem(hTreeView, &tv);
158 }
159 */
160 
161 static VOID
163 {
164  /* Initialize the image list */
166  IDI_DRIVER,
169  IMAGE_ICON);
170 
171  /* Set the first tree view */
172  TV1_Initialize(pDependData, pDependData->pDlgInfo->pService->lpServiceName);
173 
174  /* Set the second tree view */
175  TV2_Initialize(pDependData, pDependData->pDlgInfo->pService->lpServiceName);
176 }
177 
178 /*
179  * Dependancies Property dialog callback.
180  * Controls messages to the Dependancies dialog
181  */
184  UINT uMsg,
185  WPARAM wParam,
186  LPARAM lParam)
187 {
188 
189  PDEPENDDATA pDependData;
190 
191  /* Get the window context */
192  pDependData = (PDEPENDDATA)GetWindowLongPtr(hwndDlg,
193  GWLP_USERDATA);
194  if (pDependData == NULL && uMsg != WM_INITDIALOG)
195  {
196  return FALSE;
197  }
198 
199  switch (uMsg)
200  {
201  case WM_INITDIALOG:
202  {
203  pDependData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DEPENDDATA));
204  if (pDependData != NULL)
205  {
206  SetWindowLongPtr(hwndDlg,
208  (LONG_PTR)pDependData);
209 
210  pDependData->pDlgInfo = (PSERVICEPROPSHEET)(((LPPROPSHEETPAGE)lParam)->lParam);
211  pDependData->hDependsWnd = hwndDlg;
212 
213  InitDependPage(pDependData);
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(pDependData->hDependsTreeView1, lpnmtv->itemNew.hItem))
232  {
233  /* It's not, add the children */
234  TV1_AddDependantsToTree(pDependData, lpnmtv->itemNew.hItem, (LPWSTR)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(pDependData->hDependsTreeView2, lpnmtv->itemNew.hItem))
241  {
242  /* It's not, add the children */
243  TV2_AddDependantsToTree(pDependData, lpnmtv->itemNew.hItem, (LPWSTR)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(pDependData->hDependsTreeView1);
262  DestroyTreeView(pDependData->hDependsTreeView2);
263 
264  if (pDependData->hDependsImageList)
265  ImageList_Destroy(pDependData->hDependsImageList);
266 
267  HeapFree(GetProcessHeap(), 0, pDependData);
268  }
269 
270  return FALSE;
271 }
INT_PTR CALLBACK DependenciesPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
VOID TV2_AddDependantsToTree(PDEPENDDATA pDependData, HTREEITEM hParent, LPWSTR lpServiceName)
#define IMAGE_ICON
Definition: winuser.h:212
#define TreeView_GetChild(hwnd, hitem)
Definition: commctrl.h:3433
#define CALLBACK
Definition: compat.h:27
_In_ LPCSTR lpName
Definition: winbase.h:2729
LPARAM lParam
Definition: commctrl.h:3292
#define LPNMTREEVIEW
Definition: commctrl.h:3610
#define IDC_DEPEND_TREE1
Definition: resource.h:177
#define ZeroMemory
Definition: winbase.h:1635
#define IDI_NODEPENDS
Definition: resource.h:68
#define TreeView_GetFirstVisible(hwnd)
Definition: commctrl.h:3437
#define TreeView_GetNextSibling(hwnd, hitem)
Definition: commctrl.h:3434
#define TVIF_SELECTEDIMAGE
Definition: commctrl.h:3238
HIMAGELIST hDependsImageList
Definition: precomp.h:137
UINT mask
Definition: commctrl.h:3283
int32_t INT_PTR
Definition: typedefs.h:62
#define WCHAR
Definition: msvc.h:43
#define SetWindowLongPtr
Definition: treelist.c:70
WPARAM wParam
Definition: combotst.c:138
UINT_PTR WPARAM
Definition: windef.h:207
BOOL WINAPI ImageList_Destroy(HIMAGELIST himl)
Definition: imagelist.c:893
#define IMAGE_SERVICE
Definition: precomp.h:34
#define TreeView_InsertItem(hwnd, lpis)
Definition: commctrl.h:3379
static LPARAM TreeView_GetItemParam(HWND hTreeView, HTREEITEM hItem)
#define TVIF_CHILDREN
Definition: commctrl.h:3239
LONG_PTR LPARAM
Definition: windef.h:208
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
PSERVICEPROPSHEET pDlgInfo
Definition: precomp.h:136
#define GWLP_USERDATA
Definition: treelist.c:63
HTREEITEM hItem
Definition: treelist.h:37
#define LPPROPSHEETPAGE
Definition: prsht.h:372
smooth NULL
Definition: ftsmooth.c:416
HWND hDependsTreeView2
Definition: precomp.h:140
#define SERVICE_FILE_SYSTEM_DRIVER
Definition: cmtypes.h:952
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:960
#define WM_DESTROY
Definition: winuser.h:1591
static VOID DestroyTreeView(HWND hTreeView)
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned int UINT
Definition: ndis.h:50
int WINAPI GetSystemMetrics(_In_ int)
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IDC_DEPEND_TREE2
Definition: resource.h:178
#define TVE_EXPAND
Definition: commctrl.h:3390
#define SM_CXSMICON
Definition: winuser.h:1002
#define SERVICE_WIN32_SHARE_PROCESS
Definition: cmtypes.h:961
HWND hDependsTreeView1
Definition: precomp.h:139
HIMAGELIST InitImageList(UINT StartResource, UINT EndResource, UINT Width, UINT Height, ULONG type)
Definition: misc.c:219
const DOCKBAR PVOID HWND hParent
Definition: tooldock.h:22
#define WM_COMMAND
Definition: winuser.h:1716
VOID TV1_AddDependantsToTree(PDEPENDDATA pDependData, HTREEITEM hParent, LPWSTR lpServiceName)
#define IMAGE_UNKNOWN
Definition: precomp.h:33
#define TVIF_HANDLE
Definition: commctrl.h:3237
HTREEITEM AddItemToTreeView(HWND hTreeView, HTREEITEM hParent, LPWSTR lpDisplayName, LPWSTR lpServiceName, ULONG ServiceType, BOOL bHasChildren)
static VOID DestroyItem(HWND hTreeView, HTREEITEM hItem)
#define TVN_ITEMEXPANDING
Definition: commctrl.h:3705
#define TV_ITEM
Definition: commctrl.h:3267
struct _DEPENDDATA * PDEPENDDATA
ENUM_SERVICE_STATUS_PROCESS * pService
Definition: precomp.h:130
#define TVIF_TEXT
Definition: commctrl.h:3233
BOOL TV1_Initialize(PDEPENDDATA pDependData, LPWSTR lpServiceName)
#define TVIF_IMAGE
Definition: commctrl.h:3234
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
HTREEITEM hItem
Definition: commctrl.h:3284
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define IMAGE_DRIVER
Definition: precomp.h:35
unsigned int ULONG
Definition: retypes.h:1
BOOL TV2_Initialize(PDEPENDDATA pDependData, LPWSTR lpServiceName)
#define IDI_DRIVER
Definition: resource.h:70
#define TVIF_PARAM
Definition: commctrl.h:3235
#define GetWindowLongPtr
Definition: treelist.c:73
WCHAR * LPWSTR
Definition: xmlstorage.h:184
static VOID InitDependPage(PDEPENDDATA pDependData)
struct _SERVICEPROPSHEET * PSERVICEPROPSHEET
#define TV_INSERTSTRUCT
Definition: commctrl.h:3344
_In_ LPCSTR _Out_writes_to_opt_ cchDisplayName LPSTR lpDisplayName
Definition: winbase.h:2730
#define WM_INITDIALOG
Definition: winuser.h:1715
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:394
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define TreeView_GetItem(hwnd, pitem)
Definition: commctrl.h:3457
#define WM_NOTIFY
Definition: richedit.h:61
#define LPARAM
Definition: msvc.h:38
#define SERVICE_KERNEL_DRIVER
Definition: cmtypes.h:951