Source code of Windows XP (NT5)
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.

175 lines
4.4 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1994 **
  4. //*********************************************************************
  5. #include "admincfg.h"
  6. BOOL InsertTableToTreeView(POLICYDLGINFO * pdi,HWND hwndTree,TABLEENTRY * pTableEntry,
  7. HTREEITEM hParent,USERDATA * pUserData);
  8. UINT GetChildCount(TABLEENTRY * pTableEntry);
  9. BOOL RefreshTreeView(POLICYDLGINFO * pdi,HWND hwndTree,TABLEENTRY * pTableEntry,
  10. HGLOBAL hUser)
  11. {
  12. TV_INSERTSTRUCT tvis;
  13. USERDATA * pUserData;
  14. HTREEITEM hTreeItemTop=NULL;
  15. if (!(pUserData = (USERDATA *) GlobalLock(hUser))) return FALSE;
  16. TreeView_DeleteAllItems(hwndTree);
  17. hTreeItemTop = NULL;
  18. tvis.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_PARAM | TVIF_SELECTEDIMAGE
  19. | TVIF_CHILDREN;
  20. tvis.item.hItem = NULL;
  21. tvis.item.lParam = 0;
  22. tvis.hParent = TVI_ROOT;
  23. tvis.hInsertAfter = TVI_LAST;
  24. tvis.item.pszText = pUserData->hdr.szName;
  25. tvis.item.cchTextMax = lstrlen(tvis.item.pszText) + 1;
  26. tvis.item.iImage = tvis.item.iSelectedImage =
  27. GetUserImageIndex(pUserData->hdr.dwType);
  28. tvis.item.cChildren = GetChildCount(pTableEntry);
  29. tvis.item.lParam = (LPARAM) NULL;
  30. if (!(hTreeItemTop=TreeView_InsertItem(hwndTree,&tvis))) {
  31. GlobalUnlock(hUser);
  32. return FALSE;
  33. }
  34. if (!InsertTableToTreeView(pdi,hwndTree,pTableEntry->pChild,hTreeItemTop,pUserData)) {
  35. GlobalUnlock(hUser);
  36. return FALSE;
  37. }
  38. TreeView_Expand(hwndTree,hTreeItemTop,TVE_EXPAND);
  39. GlobalUnlock(hUser);
  40. return TRUE;
  41. }
  42. BOOL InsertTableToTreeView(POLICYDLGINFO * pdi,HWND hwndTree,TABLEENTRY * pTableEntry,
  43. HTREEITEM hParent,USERDATA * pUserData)
  44. {
  45. TV_INSERTSTRUCT tvis;
  46. HTREEITEM hTreeItem;
  47. tvis.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_PARAM | TVIF_SELECTEDIMAGE |
  48. TVIF_CHILDREN | TVIF_HANDLE | TVIF_STATE;
  49. tvis.item.hItem = NULL;
  50. tvis.item.state = 0;
  51. tvis.item.stateMask = TVIS_ALL;
  52. tvis.item.lParam = 0;
  53. tvis.hParent = hParent;
  54. tvis.hInsertAfter = TVI_LAST;
  55. while (pTableEntry) {
  56. tvis.item.pszText = GETNAMEPTR(pTableEntry);
  57. tvis.item.cchTextMax = lstrlen(tvis.item.pszText)+1;
  58. if (pTableEntry->dwType == ETYPE_CATEGORY) {
  59. tvis.item.cChildren = GetChildCount(pTableEntry);
  60. tvis.item.iImage = tvis.item.iSelectedImage = IMG_BOOKCLOSED;
  61. } else {
  62. tvis.item.cChildren = 0;
  63. tvis.item.iImage = tvis.item.iSelectedImage =
  64. pUserData->SettingData[((POLICY *) pTableEntry)->uDataIndex].uData;
  65. }
  66. tvis.item.lParam = (LPARAM) pTableEntry;
  67. if (!(hTreeItem=TreeView_InsertItem(hwndTree,&tvis))) return FALSE;
  68. if ((pTableEntry->dwType == ETYPE_CATEGORY) && pTableEntry->pChild) {
  69. if (!InsertTableToTreeView(pdi,hwndTree,pTableEntry->pChild,
  70. hTreeItem,pUserData)) return FALSE;
  71. }
  72. pTableEntry = pTableEntry->pNext;
  73. }
  74. return TRUE;
  75. }
  76. #define NUMBITMAPS 19
  77. #define NUMIMAGES 11
  78. #define MAPCOLOR 0x00FF00FF
  79. HIMAGELIST hImageListSmall = NULL,hImageListLarge = NULL;
  80. BOOL InitImageLists(VOID)
  81. {
  82. if ( !(hImageListSmall = ImageList_LoadBitmap(ghInst,MAKEINTRESOURCE(IDB_IMGSMALL),
  83. 16,5,(COLORREF) MAPCOLOR)) ||
  84. !(hImageListLarge = ImageList_LoadBitmap(ghInst,MAKEINTRESOURCE(IDB_IMGLARGE),
  85. 32,5,(COLORREF) MAPCOLOR)) ) {
  86. FreeImageLists();
  87. return FALSE;
  88. }
  89. ImageList_SetBkColor(hImageListSmall, GetSysColor(COLOR_WINDOW));
  90. ImageList_SetBkColor(hImageListLarge, GetSysColor(COLOR_WINDOW));
  91. return TRUE;
  92. }
  93. VOID FreeImageLists(VOID)
  94. {
  95. if (hImageListSmall) {
  96. ImageList_Destroy(hImageListSmall);
  97. hImageListSmall=NULL;
  98. }
  99. if (hImageListLarge) {
  100. ImageList_Destroy(hImageListLarge);
  101. hImageListLarge=NULL;
  102. }
  103. }
  104. UINT GetImageIndex(DWORD dwType,BOOL fExpanded,BOOL fEnabled)
  105. {
  106. switch (dwType) {
  107. case ETYPE_CATEGORY:
  108. return (fExpanded ? IMG_BOOKOPEN : IMG_BOOKCLOSED);
  109. break;
  110. case ETYPE_POLICY:
  111. return IMG_INDETERMINATE;
  112. break;
  113. case ETYPE_SETTING | STYPE_TEXT:
  114. case ETYPE_SETTING | STYPE_EDITTEXT:
  115. case ETYPE_SETTING | STYPE_COMBOBOX:
  116. case ETYPE_SETTING | STYPE_ENUM:
  117. case ETYPE_SETTING | STYPE_NUMERIC:
  118. return IMG_EMPTY;
  119. break;
  120. case ETYPE_SETTING | STYPE_CHECKBOX:
  121. return IMG_UNCHECKED;
  122. break;
  123. }
  124. return IMG_INDETERMINATE;
  125. }
  126. UINT GetChildCount(TABLEENTRY * pTableEntry)
  127. {
  128. TABLEENTRY * pChild = pTableEntry->pChild;
  129. UINT nCount=0;
  130. while (pChild) {
  131. nCount++;
  132. pChild = pChild->pNext;
  133. }
  134. return nCount;
  135. }