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.

180 lines
4.5 KiB

  1. //--------------------------------------------------------------------------
  2. //
  3. // treeview.cpp
  4. //
  5. //--------------------------------------------------------------------------
  6. #include <windows.h>
  7. #include <commctrl.h>
  8. #include "resource.h"
  9. #include "treeview.h"
  10. #include <stdlib.h>
  11. extern HINSTANCE g_hInst;
  12. extern int g_InsSettingsOpen, g_InsSettingsClose, g_InsLeafItem, g_PolicyOpen, g_PolicyClose;
  13. CTreeView::CTreeView()
  14. {
  15. InitCommonControls();
  16. }
  17. CTreeView::~CTreeView()
  18. {
  19. }
  20. void CTreeView::Create(HWND hwndParent, int x, int y, int nWidth, int nHeight)
  21. {
  22. hTreeView = CreateWindowEx(WS_EX_CLIENTEDGE , WC_TREEVIEW, TEXT("Tree View"),
  23. WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS | TVS_SHOWSELALWAYS,
  24. x, y, nWidth, nHeight, hwndParent, NULL, g_hInst, NULL);
  25. }
  26. HTREEITEM CTreeView::AddItem(LPTSTR lpszItem, HTREEITEM hParentItem)
  27. {
  28. TV_ITEM tvi;
  29. TV_INSERTSTRUCT tvins;
  30. char szTmp[MAX_PATH];
  31. HTREEITEM hItem;
  32. tvi.mask = TVIF_TEXT;
  33. tvi.pszText = lpszItem;
  34. tvi.cchTextMax = lstrlen(lpszItem);
  35. tvins.item = tvi;
  36. tvins.hInsertAfter = TVI_LAST;
  37. if(hParentItem == NULL)
  38. {
  39. tvins.item.mask |= TVIF_STATE | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  40. tvins.item.stateMask = tvins.item.state = TVIS_BOLD;
  41. if(lstrcmp(lpszItem, TEXT("Ins Settings")) == 0)
  42. {
  43. tvins.item.iImage = tvins.item.iSelectedImage = g_InsSettingsClose;
  44. }
  45. else
  46. {
  47. tvins.item.iImage = tvins.item.iSelectedImage = g_PolicyClose;
  48. }
  49. tvins.hParent = TVI_ROOT;
  50. }
  51. else
  52. {
  53. tvins.item.mask |= TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  54. tvins.hParent = hParentItem;
  55. tvins.item.iImage = tvins.item.iSelectedImage = g_InsLeafItem;
  56. }
  57. hItem = (HTREEITEM) SendMessage(hTreeView, TVM_INSERTITEM, 0,
  58. (LPARAM)(LPTV_INSERTSTRUCT) &tvins);
  59. return hItem;
  60. }
  61. void CTreeView::MoveWindow(int x, int y, int nWidth, int nHeight)
  62. {
  63. ::MoveWindow(hTreeView, x, y, nWidth, nHeight, TRUE);
  64. }
  65. void CTreeView::SetSel(HTREEITEM hItem)
  66. {
  67. SendMessage(hTreeView, TVM_SELECTITEM, (WPARAM) TVGN_CARET,
  68. (LPARAM) hItem);
  69. }
  70. HTREEITEM CTreeView::GetSel()
  71. {
  72. return TreeView_GetSelection(hTreeView);
  73. }
  74. void CTreeView::GetItemText(HTREEITEM hItem, LPTSTR szItemText, int nSize)
  75. {
  76. TV_ITEM item;
  77. item.mask = TVIF_TEXT;
  78. item.pszText = szItemText;
  79. item.cchTextMax = nSize;
  80. item.hItem = hItem;
  81. SendMessage(hTreeView, TVM_GETITEM, 0, (LPARAM) &item);
  82. }
  83. HWND CTreeView::GetHandle()
  84. {
  85. return hTreeView;
  86. }
  87. void CTreeView::DeleteNodes(HTREEITEM hParentItem)
  88. {
  89. HTREEITEM hItem = TreeView_GetChild(hTreeView, hParentItem);
  90. HTREEITEM hNextItem = NULL;
  91. while(hItem != NULL) // if items present
  92. {
  93. hNextItem = TreeView_GetNextSibling(hTreeView, hItem); // get next item
  94. TreeView_DeleteItem(hTreeView, hItem);
  95. hItem = hNextItem;
  96. }
  97. }
  98. void CTreeView::CollapseChildNodes(HTREEITEM hParentItem)
  99. {
  100. NMTREEVIEW NMTreeView;
  101. HTREEITEM hItem;
  102. TVITEM tvitem;
  103. ZeroMemory(&NMTreeView, sizeof(NMTreeView));
  104. NMTreeView.hdr.hwndFrom = hTreeView;
  105. NMTreeView.hdr.code = TVN_ITEMEXPANDED;
  106. NMTreeView.action = TVE_COLLAPSE;
  107. hItem = (hParentItem != NULL) ? TreeView_GetChild(hTreeView, hParentItem) :
  108. TreeView_GetRoot(hTreeView);
  109. while (hItem != NULL)
  110. {
  111. NMTreeView.itemNew.hItem = hItem;
  112. TreeView_Expand(hTreeView, hItem, TVE_COLLAPSE);
  113. SendMessage(GetParent(hTreeView), WM_NOTIFY, 0, (LPARAM)&NMTreeView);
  114. hItem = TreeView_GetNextSibling(hTreeView, hItem); // get next item
  115. }
  116. }
  117. //--------------------------------------------------------------------------
  118. // CStatusWindow member functions
  119. CStatusWindow::CStatusWindow()
  120. {
  121. hStatusWindow = NULL;
  122. nHeight = 0;
  123. }
  124. CStatusWindow::~CStatusWindow()
  125. {
  126. }
  127. void CStatusWindow::Create(HWND hwndParent, int nCtlID)
  128. {
  129. RECT r;
  130. hStatusWindow = CreateStatusWindow(WS_CHILD | WS_VISIBLE,TEXT("Ready"), hwndParent, nCtlID);
  131. GetWindowRect(hStatusWindow, &r);
  132. nHeight = r.bottom - r.top;
  133. }
  134. void CStatusWindow::Size(int nWidth)
  135. {
  136. SendMessage(hStatusWindow, WM_SIZE, 0, MAKELPARAM(nWidth, nHeight));
  137. }
  138. void CStatusWindow::SetText(LPTSTR szText)
  139. {
  140. SendMessage(hStatusWindow, WM_SETTEXT, 0, (LPARAM) szText);
  141. }
  142. int CStatusWindow::Height() const
  143. {
  144. return nHeight;
  145. }