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.

277 lines
8.3 KiB

  1. // BUGBUG: this code is not used anymore!
  2. #include "shellprv.h"
  3. #include "listview.h"
  4. // Internal STREAM entry points
  5. BOOL Stream_WriteString(STREAM FAR* pstm, LPCTSTR psz);
  6. LPTSTR Stream_ReadString(STREAM FAR* pstm);
  7. UINT Stream_ReadStringBuffer(STREAM FAR* pstm, LPTSTR psz, UINT cb);
  8. // Read or write a ListView to a stream. flags indicate what aspects /* ;Internal */
  9. // of the listview to write out. If aspects of a ListView state are /* ;Internal */
  10. // not written, default values will be used when read back in. /* ;Internal */
  11. // /* ;Internal */
  12. #define LVRW_ICONS 0x0001 /* ;Internal */
  13. #define LVRW_SMALLICONS 0x0002 /* ;Internal */
  14. #define LVRW_FONT 0x0004 /* ;Internal */
  15. #define LVRW_LPARAMS 0x0008 /* ;Internal */
  16. #define LVRW_COLINFO 0x0010 /* ;Internal */
  17. #define LVRW_ENUMORDER 0x0020 /* ;Internal */
  18. /* ;Internal */
  19. // BOOL ListView_Write(HWND hwndLV, STREAM FAR* pstm, UINT flags); /* ;Internal */
  20. #define LVM_WRITE (LVM_FIRST + 31) /* ;Internal */
  21. #define ListView_Write(hwndLV, pstm, flags) /* ;Internal */ \
  22. (BOOL)SendMessage((hwndLV), LVM_WRITE, /* ;Internal */ \
  23. (WPARAM)(BOOL)(flags), /* ;Internal */ \
  24. (LPARAM)(STREAM FAR*)(pstm)) /* ;Internal */
  25. /* ;Internal */
  26. typedef struct _LV_READINFO /* ;Internal */
  27. { /* ;Internal */
  28. UINT flags; /* ;Internal */
  29. HINSTANCE hinst; /* ;Internal */
  30. HWND hwndParent; /* ;Internal */
  31. } LV_READINFO; /* ;Internal */
  32. /* ;Internal */
  33. // HWND ListView_Read(STREAM FAR* pstm, LV_READINFO FAR* pinfo); /* ;Internal */
  34. // BUGBUG This can't be a message! How do we want this to work? /* ;Internal */
  35. #define LVM_READ (LVM_FIRST + 32) /* ;Internal */
  36. #define ListView_Read(plv, pinfo) /* ;Internal */
  37. /* ;Internal */
  38. #define LV_MAGIC (TEXT('L') | (TEXT('V') << (8 * sizeof(TCHAR))))
  39. typedef struct _LV_STREAMHDR
  40. {
  41. UINT magic;
  42. UINT flags;
  43. UINT style;
  44. UINT id;
  45. POINT ptOrigin;
  46. COLORREF clrBk;
  47. int cItem;
  48. } LV_STREAMHDR;
  49. typedef struct _LV_ITEMHDR
  50. {
  51. POINT pt;
  52. UINT state;
  53. int iImage;
  54. int iZOrder;
  55. } LV_ITEMHDR;
  56. BOOL NEAR ListView_OnWrite(LV* plv, STREAM FAR* pstm, UINT flags)
  57. {
  58. int i;
  59. LV_STREAMHDR hdr;
  60. hdr.magic = LV_MAGIC;
  61. hdr.flags = flags;
  62. hdr.style = plv->style;
  63. hdr.id = GetWindowID(plv->hwnd);
  64. hdr.ptOrigin = plv->ptOrigin;
  65. hdr.clrBk = plv->clrBk;
  66. hdr.cItem = ListView_Count(plv);
  67. if (!Stream_Write(pstm, &hdr, sizeof(hdr)))
  68. return FALSE;
  69. for (i = 0; i < hdr.cItem; i++)
  70. {
  71. LV_ITEMHDR ihdr;
  72. LISTITEM FAR* pitem = ListView_FastGetItemPtr(plv, i);
  73. ihdr.pt.x = pitem->pt.x;
  74. ihdr.pt.y = pitem->pt.y;
  75. ihdr.state = pitem->state;
  76. ihdr.iImage = pitem->iImage;
  77. ihdr.iZOrder = ListView_ZOrderIndex(plv, i);
  78. if (!Stream_Write(pstm, &ihdr, sizeof(ihdr)))
  79. return FALSE;
  80. if (flags & LVRW_LPARAMS)
  81. {
  82. if (!Stream_Write(pstm, &pitem->lParam, sizeof(pitem->lParam)))
  83. return FALSE;
  84. }
  85. if (!Stream_WriteString(pstm, pitem->pszText))
  86. return FALSE;
  87. }
  88. if (flags & LVRW_FONT)
  89. {
  90. // REVIEW: Need to optionally write out log font...
  91. }
  92. if (flags & LVRW_ICONS)
  93. {
  94. if (!ImageList_Write(plv->himl, pstm))
  95. return FALSE;
  96. }
  97. if (flags & LVRW_SMALLICONS)
  98. {
  99. if (!ImageList_Write(plv->himlSmall, pstm))
  100. return FALSE;
  101. }
  102. if (!Stream_Flush(pstm))
  103. return FALSE;
  104. return TRUE;
  105. }
  106. HWND NEAR ListView_OnRead(STREAM FAR* pstm, LV_READINFO FAR* pinfo)
  107. {
  108. HWND hwndLV;
  109. int i;
  110. LV* plv;
  111. LV_STREAMHDR hdr;
  112. BOOL fSuccess;
  113. UINT flags = pinfo->flags;
  114. fSuccess = FALSE;
  115. hwndLV = NULL;
  116. if (!Stream_Read(pstm, &hdr, sizeof(hdr)))
  117. return FALSE;
  118. if (hdr.magic != LV_MAGIC || hdr.flags != flags)
  119. return FALSE;
  120. // REVIEW: Could create window always with LVS_SHAREIMAGELISTS
  121. // so we don't have to destroy and recreate the imagelists
  122. // later. Probably only a negligible speed savings, though.
  123. //
  124. hwndLV = CreateWindowEx(
  125. 0L, // extendedStyle
  126. c_szListViewClass, // class name
  127. NULL, // text
  128. WS_CHILD | (DWORD)hdr.style,
  129. 0, 0, 0, 0, // x, y, cx, cy
  130. pinfo->hwndParent, // hwndParent
  131. (HMENU)hdr.id, // child window id
  132. pinfo->hinst, // hInstance
  133. NULL);
  134. if (!hwndLV)
  135. return FALSE;
  136. plv = ListView_GetPtr(hwndLV);
  137. if (!plv)
  138. goto Error;
  139. plv->ptOrigin = hdr.ptOrigin;
  140. plv->clrBk = hdr.clrBk;
  141. // Grow the Z-order array to cItem items...
  142. //
  143. for (i = 0; i < hdr.cItem; i++)
  144. {
  145. // Add a non-NULL item so we can test return value
  146. // of ReplaceItem() later...
  147. //
  148. if (DPA_InsertPtr(plv->hdpaZOrder, i, (void FAR*)1) == -1)
  149. goto Error;
  150. }
  151. for (i = 0; i < hdr.cItem; i++)
  152. {
  153. int i2;
  154. LV_ITEMHDR ihdr;
  155. LV_ITEM item;
  156. LISTITEM FAR* pitem;
  157. LPTSTR pszText;
  158. if (!Stream_Read(pstm, &ihdr, sizeof(ihdr)))
  159. goto Error;
  160. item.mask = LVIF_ALL;
  161. item.pszText = NULL;
  162. item.state = 0;
  163. item.iImage = ihdr.iImage;
  164. item.lParam = 0L;
  165. pitem = ListView_CreateItem(plv, &item);
  166. if (!pitem)
  167. goto Error;
  168. if (flags & LVRW_LPARAMS)
  169. {
  170. if (!Stream_Read(pstm, &pitem->lParam, sizeof(pitem->lParam)))
  171. goto Error;
  172. }
  173. pszText = Stream_ReadString(pstm);
  174. if (!pszText)
  175. {
  176. ListView_FreeItem(plv, pitem);
  177. goto Error;
  178. }
  179. pitem->pt.y = (short)ihdr.pt.y;
  180. pitem->pt.x = (short)ihdr.pt.x;
  181. pitem->state = ihdr.state;
  182. pitem->pszText = pszText;
  183. // If sorted, then insert sorted.
  184. //
  185. i2 = i;
  186. if (plv->style & (LVS_SORTASCENDING | LVS_SORTDESCENDING))
  187. i2 = ListView_LookupString(plv, pszText, LVFI_SUBSTRING | LVFI_NEARESTXY, 0);
  188. if (DPA_InsertPtr(plv->hdpa, i2, (void FAR*)pitem) == -1)
  189. {
  190. ListView_FreeItem(plv, pitem);
  191. goto Error;
  192. }
  193. // Now set the Z order.
  194. //
  195. if (!DPA_SetPtr(plv->hdpaZOrder, ihdr.iZOrder, (void FAR*)i2))
  196. goto Error;
  197. }
  198. if (flags & LVRW_FONT)
  199. {
  200. // REVIEW: Need to read & setfont
  201. }
  202. if (flags & LVRW_ICONS)
  203. {
  204. ImageList_Destroy(plv->himl);
  205. plv->himl = ImageList_Read(pstm);
  206. if (!plv->himl)
  207. goto Error;
  208. }
  209. if (flags & LVRW_SMALLICONS)
  210. {
  211. ImageList_Destroy(plv->himlSmall);
  212. plv->himlSmall = ImageList_Read(pstm);
  213. if (!plv->himlSmall)
  214. goto Error;
  215. }
  216. plv->rcView.left = RECOMPUTE;
  217. // Instead of sending out a zillion creates (one for each item we just
  218. // created), just destroy and re-create ourselves.
  219. ListView_NotifyRecreate(plv);
  220. fSuccess = TRUE;
  221. Error:
  222. if (!fSuccess && hwndLV)
  223. {
  224. DestroyWindow(hwndLV);
  225. hwndLV = NULL;
  226. }
  227. return hwndLV;
  228. }