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.

253 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. datalist.c
  5. Abstract:
  6. functions handling the operation of the listview
  7. that displays key data in memdbe.exe
  8. Author:
  9. Matthew Vanderzee (mvander) 13-Aug-1999
  10. Revision History:
  11. --*/
  12. #include "pch.h"
  13. #include "dbeditp.h"
  14. #include <commdlg.h>
  15. HWND g_hListData;
  16. #define LISTITEMTEXT_MAX 1024
  17. #define LINEHEADER_VALUE "VALUE"
  18. #define LINEHEADER_FLAGS "FLAGS"
  19. #define LINEHEADER_BINARY "BINARY"
  20. #define LINEHEADER_SINGLE_LINKAGE "SINGLE LINKAGE"
  21. #define LINEHEADER_DOUBLE_LINKAGE "DOUBLE LINKAGE"
  22. BOOL
  23. IsDataList (
  24. HWND hwnd
  25. )
  26. {
  27. return (hwnd == g_hListData);
  28. }
  29. BOOL
  30. pIsDataLine (
  31. BYTE DataFlag,
  32. PSTR Line
  33. )
  34. {
  35. CHAR LineCmp[16];
  36. switch (DataFlag) {
  37. case DATAFLAG_VALUE:
  38. StringCopyA (LineCmp, LINEHEADER_VALUE);
  39. break;
  40. case DATAFLAG_FLAGS:
  41. StringCopyA (LineCmp, LINEHEADER_FLAGS);
  42. break;
  43. case DATAFLAG_UNORDERED:
  44. StringCopyA (LineCmp, LINEHEADER_BINARY);
  45. break;
  46. case DATAFLAG_SINGLELINK:
  47. StringCopyA (LineCmp, LINEHEADER_SINGLE_LINKAGE);
  48. break;
  49. case DATAFLAG_DOUBLELINK:
  50. StringCopyA (LineCmp, LINEHEADER_DOUBLE_LINKAGE);
  51. break;
  52. default:
  53. return FALSE;
  54. }
  55. return StringMatchCharCountA (LineCmp, Line, CharCountA (LineCmp));
  56. }
  57. BOOL
  58. DataListInit (
  59. HWND hdlg
  60. )
  61. {
  62. g_hListData = GetDlgItem (hdlg, IDC_LIST_DATA);
  63. return TRUE;
  64. }
  65. BOOL
  66. DataListClear (
  67. VOID
  68. )
  69. {
  70. if (!ListView_DeleteAllItems (g_hListData)) {
  71. DEBUGMSG ((DBG_ERROR, "Could not clear List View!"));
  72. return FALSE;
  73. }
  74. return TRUE;
  75. }
  76. BOOL
  77. DataListRefresh (
  78. VOID
  79. )
  80. {
  81. if (!DataListClear ()) {
  82. return FALSE;
  83. }
  84. return TRUE;
  85. }
  86. INT
  87. pDataListAddString (
  88. PSTR Str,
  89. LPARAM lParam
  90. )
  91. {
  92. INT Index;
  93. LVITEM ListItem;
  94. ListItem.mask = LVIF_TEXT | LVIF_PARAM ;
  95. ListItem.pszText = Str;
  96. ListItem.iSubItem = 0;
  97. ListItem.lParam = lParam;
  98. ListItem.iItem = ListView_GetItemCount (g_hListData);
  99. Index = ListView_InsertItem (g_hListData, &ListItem);
  100. if (Index < 0) {
  101. DEBUGMSG ((DBG_ERROR, "Could not add list item!"));
  102. }
  103. return Index;
  104. }
  105. INT
  106. DataListAddData (
  107. BYTE DataFlag,
  108. UINT DataValue,
  109. PBYTE DataPtr
  110. )
  111. {
  112. INT i;
  113. PSTR Ptr;
  114. LPARAM lParam = 0;
  115. CHAR ListItemText[LISTITEMTEXT_MAX];
  116. switch (DataFlag) {
  117. case DATAFLAG_VALUE:
  118. sprintf (ListItemText, "%s: 0x%08lX", LINEHEADER_VALUE, DataValue);
  119. break;
  120. case DATAFLAG_FLAGS:
  121. sprintf (ListItemText, "%s: 0x%08lX", LINEHEADER_FLAGS, DataValue);
  122. break;
  123. case DATAFLAG_UNORDERED:
  124. sprintf (ListItemText, "%s: \"", LINEHEADER_BINARY);
  125. Ptr = GetEndOfStringA (ListItemText);
  126. for (i=0;i<(INT)(DataValue) && i<LISTITEMTEXT_MAX-2;i++) {
  127. *(Ptr++) = isprint(DataPtr[i]) ? DataPtr[i] : '.';
  128. }
  129. *(Ptr++) = '\"';
  130. *Ptr = 0;
  131. ListItemText[LISTITEMTEXT_MAX] = 0;
  132. break;
  133. case DATAFLAG_SINGLELINK:
  134. sprintf (ListItemText, "%s: %s", LINEHEADER_SINGLE_LINKAGE, (PSTR)DataPtr);
  135. lParam = DataValue;
  136. break;
  137. case DATAFLAG_DOUBLELINK:
  138. sprintf (ListItemText, "%s: %s", LINEHEADER_DOUBLE_LINKAGE, (PSTR)DataPtr);
  139. lParam = DataValue;
  140. break;
  141. }
  142. return pDataListAddString (ListItemText, lParam);
  143. }
  144. BOOL
  145. DataListRightClick (
  146. HWND hdlg,
  147. POINT pt
  148. )
  149. {
  150. HMENU hMenu;
  151. RECT rect;
  152. if (!(hMenu = LoadMenu (g_hInst, MAKEINTRESOURCE(IDR_MENU_POPUP))) ||
  153. (!(hMenu = GetSubMenu (hMenu, MENUINDEX_POPUP_KEY))) ||
  154. (!(hMenu = GetSubMenu (hMenu, MENUINDEX_POPUP_KEY_ADDDATA)))
  155. ) {
  156. return FALSE;
  157. }
  158. if (!GetWindowRect (g_hListData, &rect)) {
  159. return FALSE;
  160. }
  161. if (!TrackPopupMenu (hMenu, TPM_LEFTALIGN, pt.x+rect.left, pt.y+rect.top, 0, hdlg, NULL)) {
  162. return FALSE;
  163. }
  164. return TRUE;
  165. }
  166. BOOL
  167. DataListDblClick (
  168. HWND hdlg,
  169. INT iItem,
  170. INT iSubItem
  171. )
  172. {
  173. CHAR ListItemText[LISTITEMTEXT_MAX];
  174. LVITEM Item;
  175. if (iItem<0) {
  176. return FALSE;
  177. }
  178. Item.mask = LVIF_TEXT | LVIF_PARAM;
  179. Item.iItem = iItem;
  180. Item.iSubItem = iSubItem;
  181. Item.pszText = ListItemText;
  182. Item.cchTextMax = LISTITEMTEXT_MAX;
  183. if (!ListView_GetItem (g_hListData, &Item)) {
  184. return FALSE;
  185. }
  186. if (pIsDataLine (DATAFLAG_SINGLELINK, ListItemText)) {
  187. SendMessage (hdlg, WM_SELECT_KEY, Item.lParam, 0);
  188. return TRUE;
  189. }
  190. if (pIsDataLine (DATAFLAG_DOUBLELINK, ListItemText)) {
  191. SendMessage (hdlg, WM_SELECT_KEY, Item.lParam, 0);
  192. return TRUE;
  193. }
  194. return FALSE;
  195. }