Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

262 lines
9.3 KiB

  1. #include "precomp.h"
  2. #include <admparse.h>
  3. #include "rsop.h"
  4. #define NUM_ICONS 3
  5. int g_ADMOpen, g_ADMClose, g_ADMCategory;
  6. extern HINSTANCE g_hUIInstance;
  7. // Creates image list, adds 3 icons to it, and associates the image
  8. // list with the treeview control.
  9. LRESULT InitImageList(HWND hTreeView)
  10. {
  11. HIMAGELIST hWndImageList;
  12. HICON hIcon;
  13. hWndImageList = ImageList_Create(GetSystemMetrics (SM_CXSMICON),
  14. GetSystemMetrics (SM_CYSMICON),
  15. TRUE, NUM_ICONS, 3);
  16. if(!hWndImageList)
  17. {
  18. return FALSE;
  19. }
  20. hIcon = LoadIcon(g_hUIInstance, MAKEINTRESOURCE(IDI_ICON2));
  21. g_ADMOpen = ImageList_AddIcon(hWndImageList, hIcon);
  22. DestroyIcon(hIcon);
  23. hIcon = LoadIcon(g_hUIInstance, MAKEINTRESOURCE(IDI_ICON3));
  24. g_ADMClose = ImageList_AddIcon(hWndImageList, hIcon);
  25. DestroyIcon(hIcon);
  26. hIcon = LoadIcon(g_hUIInstance, MAKEINTRESOURCE(IDI_ICON4));
  27. g_ADMCategory = ImageList_AddIcon(hWndImageList, hIcon);
  28. DestroyIcon(hIcon);
  29. // Fail if not all images were added.
  30. if (ImageList_GetImageCount(hWndImageList) < NUM_ICONS)
  31. {
  32. // ERROR: Unable to add all images to image list.
  33. return FALSE;
  34. }
  35. // Associate image list with treeView control.
  36. TreeView_SetImageList(hTreeView, hWndImageList, TVSIL_NORMAL);
  37. return TRUE;
  38. }
  39. static void AddIconsToNodes(HWND hTreeView, HTREEITEM hParentItem)
  40. {
  41. TV_ITEM tvItem;
  42. HTREEITEM hItem;
  43. hItem = TreeView_GetChild(hTreeView, hParentItem);
  44. while(hItem != NULL)
  45. {
  46. tvItem.hItem = hItem;
  47. tvItem.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  48. tvItem.iImage = g_ADMCategory;
  49. tvItem.iSelectedImage = g_ADMCategory;
  50. TreeView_SetItem(hTreeView, &tvItem);
  51. hItem = TreeView_GetNextSibling(hTreeView, hItem); // get next item
  52. }
  53. }
  54. /////////////////////////////////////////////////////////////////////
  55. INT_PTR CALLBACK AdmDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  56. {
  57. // Retrieve Property Sheet Page info for each call into dlg proc.
  58. LPPROPSHEETCOOKIE psCookie = (LPPROPSHEETCOOKIE)GetWindowLongPtr(hDlg, DWLP_USER);
  59. TV_ITEM tvItem, tvItem1;
  60. HTREEITEM hItem, hParentItem;
  61. RECT rectDlg, rectInstr, rectDscr;
  62. RECT rectButton, rectTreeView;
  63. static TCHAR szWorkDir[MAX_PATH];
  64. HWND hTreeView = GetDlgItem(hDlg, IDC_ADMTREE);
  65. LPNM_TREEVIEW lpNMTreeView = (LPNM_TREEVIEW)lParam;
  66. UNREFERENCED_PARAMETER(wParam);
  67. switch (message)
  68. {
  69. case WM_INITDIALOG:
  70. SetPropSheetCookie(hDlg, lParam);
  71. EnableDBCSChars(hDlg, IDC_ADMTREE);
  72. InitImageList(hTreeView);
  73. #ifdef UNICODE
  74. TreeView_SetUnicodeFormat(hTreeView, TRUE);
  75. #else
  76. TreeView_SetUnicodeFormat(hTreeView, FALSE);
  77. #endif
  78. HideDlgItem(hDlg, IDC_ADMIMPORT);
  79. HideDlgItem(hDlg, IDC_ADMDELETE);
  80. // strech the treeview to cover the area of the buttons
  81. GetWindowRect(GetDlgItem(hDlg, IDC_ADMIMPORT), &rectButton);
  82. GetWindowRect(hTreeView, &rectTreeView);
  83. SetWindowPos(hTreeView, HWND_TOP, 0, 0, rectTreeView.right - rectTreeView.left,
  84. (rectTreeView.bottom - rectTreeView.top) + (rectButton.bottom - rectTreeView.bottom),
  85. SWP_NOMOVE | SWP_NOZORDER | SWP_SHOWWINDOW);
  86. break;
  87. case WM_DESTROY:
  88. //TODO: UNCOMMENT
  89. // if (psCookie->pCS->IsRSoP())
  90. // DestroyDlgRSoPData(hDlg);
  91. break;
  92. case WM_HELP: // F1
  93. ShowHelpTopic(hDlg);
  94. break;
  95. case WM_NOTIFY:
  96. switch (((LPNMHDR)lParam)->code)
  97. {
  98. case PSN_HELP:
  99. ShowHelpTopic(hDlg);
  100. break;
  101. case PSN_SETACTIVE:
  102. CreateWorkDir(GetInsFile(hDlg), IEAK_GPE_BRANDING_SUBDIR TEXT("\\ADM"), szWorkDir);
  103. GetWindowRect(hDlg, &rectDlg);
  104. GetWindowRect(GetDlgItem(hDlg, IDC_ADMINSTR), &rectInstr);
  105. rectDscr.left = rectInstr.left - rectDlg.left + 1;
  106. rectDscr.top = rectInstr.top - rectDlg.top + 1;
  107. rectDscr.right = rectDscr.left + (rectInstr.right - rectInstr.left) - 2;
  108. rectDscr.bottom = rectDscr.top + (rectInstr.bottom - rectInstr.top) - 2;
  109. CreateADMWindow(hTreeView, GetDlgItem(hDlg, IDC_ADMINSTR), rectDscr.left,
  110. rectDscr.top, rectDscr.right - rectDscr.left,
  111. rectDscr.bottom - rectDscr.top);
  112. {
  113. TCHAR szAdmFilePath[MAX_PATH];
  114. TCHAR szAdmFileName[MAX_PATH];
  115. CNewCursor cur(IDC_WAIT);
  116. StrCpy(szAdmFilePath, GetCurrentAdmFile(hDlg));
  117. StrCpy(szAdmFileName, PathFindFileName(szAdmFilePath));
  118. PathRemoveFileSpec(szAdmFilePath);
  119. BSTR bstrNamespace = NULL;
  120. if (psCookie->pCS->IsRSoP())
  121. bstrNamespace = psCookie->pCS->GetRSoPNamespace();
  122. hItem = AddADMItem(hTreeView, szAdmFilePath, szAdmFileName,
  123. szWorkDir, ROLE_CORP, bstrNamespace);
  124. if (hItem != NULL)
  125. {
  126. AddIconsToNodes(hTreeView, hItem);
  127. TreeView_Expand(hTreeView, hItem, TVE_EXPAND);
  128. TreeView_SelectItem(hTreeView, hItem);
  129. }
  130. }
  131. break;
  132. case PSN_APPLY:
  133. if (psCookie->pCS->IsRSoP())
  134. return FALSE;
  135. else
  136. {
  137. if (!AcquireWriteCriticalSection(hDlg))
  138. {
  139. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  140. break;
  141. }
  142. // save the contents and delete the tree item
  143. DeleteADMItems(hTreeView, szWorkDir, GetInsFile(hDlg), TRUE);
  144. TreeView_DeleteAllItems(hTreeView);
  145. DestroyADMWindow(hTreeView);
  146. if (PathIsDirectoryEmpty(szWorkDir))
  147. PathRemovePath(szWorkDir);
  148. // Copy this ADM file to the same dir as the INF files so we can
  149. // use the two files to display results from RSoP.
  150. CopyFileToDirEx(GetCurrentAdmFile(hDlg), szWorkDir);
  151. SignalPolicyChanged(hDlg, FALSE, TRUE, &g_guidClientExt, &g_guidSnapinExt, TRUE);
  152. }
  153. break;
  154. case PSN_QUERYCANCEL:
  155. DeleteADMItems(hTreeView, szWorkDir, GetInsFile(hDlg), FALSE);
  156. TreeView_DeleteAllItems(hTreeView);
  157. DestroyADMWindow(hTreeView);
  158. if (PathIsDirectoryEmpty(szWorkDir))
  159. PathRemovePath(szWorkDir);
  160. break;
  161. case TVN_SELCHANGED:
  162. hParentItem = TreeView_GetParent(hTreeView, lpNMTreeView->itemNew.hItem);
  163. // save and remove the previous item
  164. SelectADMItem(hDlg, hTreeView, &lpNMTreeView->itemOld, FALSE, FALSE);
  165. // display the information for the newly selected item
  166. DisplayADMItem(hDlg, hTreeView, &lpNMTreeView->itemNew, FALSE);
  167. break;
  168. case TVN_ITEMEXPANDED:
  169. tvItem.mask = TVIF_IMAGE;
  170. tvItem.hItem = lpNMTreeView->itemNew.hItem;
  171. TreeView_GetItem(hTreeView, &tvItem);
  172. // If tree item is EXPANDING (opening up) and
  173. // current icon == CloseFolder, change icon to OpenFolder
  174. if((lpNMTreeView->action == TVE_EXPAND) &&
  175. (tvItem.iImage == g_ADMClose))
  176. {
  177. tvItem1.hItem = lpNMTreeView->itemNew.hItem;
  178. tvItem1.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  179. tvItem1.iImage = g_ADMOpen;
  180. tvItem1.iSelectedImage = g_ADMOpen;
  181. TreeView_SetItem(hTreeView, &tvItem1);
  182. }
  183. // If tree item is COLLAPSING (closing up) and
  184. // current icon == OpenFolder, change icon to CloseFolder
  185. else if((lpNMTreeView->action == TVE_COLLAPSE) &&
  186. (tvItem.iImage == g_ADMOpen))
  187. {
  188. tvItem1.hItem = lpNMTreeView->itemNew.hItem;
  189. tvItem1.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  190. tvItem1.iImage = g_ADMClose;
  191. tvItem1.iSelectedImage = g_ADMClose;
  192. TreeView_SetItem(hTreeView, &tvItem1);
  193. }
  194. break;
  195. default:
  196. return FALSE;
  197. }
  198. break;
  199. default:
  200. return FALSE;
  201. }
  202. return TRUE;
  203. }