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.

244 lines
9.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: listview.h
  7. //
  8. // Contents: Implements Mobsync Custom Listview/TreeView control
  9. //
  10. // Classes: CListView
  11. //
  12. // Notes:
  13. //
  14. // History: 23-Jul-98 rogerg Created.
  15. //
  16. //--------------------------------------------------------------------------
  17. #ifndef _MOBSYNCLISTVIEW_
  18. #define _MOBSYNCLISTVIEW_
  19. /*
  20. wraps standard ListView control so can do TreeView like operations.
  21. ItemdId still refers to linear location in the ListView independent
  22. of who many levels deep the item is
  23. Item itemID
  24. toplevel1 0
  25. child1 1
  26. child2 2
  27. toplevel2 3
  28. This works fine except causes some confusion on insert. On an insert
  29. if the LVIFEX_PARENT flag isn't set the item is inserted as it always was
  30. and indent is the same as the item is is inserted after. For example, if
  31. if was inserted after toplevel1 it would be a toplevel item. If it was inserted
  32. after child1 is would be another child of toplevel1
  33. if the LVIFEX_PARENT flag is set the item is inserted as a child of iParent.
  34. if the client specified LVI_FIRST, LVI_LAST the item is inserted a first or
  35. last child. if a normal itemId is specified then it must fall within a valid
  36. range to be the specified parents child or the inser fails.
  37. For example, if I specified a parent of TopLevel1 an itemID of 1,2 or 3 would be valid.
  38. a vlue of 4 would not be since it would fall outside the child range for toplevel1
  39. */
  40. #define LVI_ROOT -1 // itemID to pass in for ParenItemID for root
  41. #define LVI_FIRST -0x0FFFE
  42. #define LVI_LAST -0x0FFFF
  43. // The blob field is for perf so a user of the listview doesn't have to
  44. // enumerate, getting the lParam or storing its own lookup for an item.
  45. // when a blob is added the listview makes its own copy and automatically
  46. // frees it when the item is deleted. The blob field is not allowed on subitems.
  47. // define blob structure that app can set and listview
  48. typedef struct _tagLVBLOB
  49. {
  50. ULONG cbSize; // size of the blob struture. !!!Include cbSize itself.
  51. BYTE data[1];
  52. } LVBLOB;
  53. typedef LVBLOB* LPLVBLOB;
  54. // state flags for ListView Item check,uncheck conform to real ListView others are our own defines.
  55. // #define LVIS_STATEIMAGEMASK_UNCHECK (0x1000)
  56. // #define LVIS_STATEIMAGEMASK_CHECK (0x2000)
  57. typedef enum _tagLVITEMEXSTATE
  58. {
  59. // mutually exclusive
  60. LVITEMEXSTATE_UNCHECKED = 0x0000,
  61. LVITEMEXSTATE_CHECKED = 0x0001,
  62. LVITEMEXSTATE_INDETERMINATE = 0x0002,
  63. } LVITEMSTATE;
  64. // extended flags
  65. #define LVIFEX_PARENT 0x0001
  66. #define LVIFEX_BLOB 0x0002
  67. #define LVIFEX_VALIDFLAGMASK 0x0003
  68. // make private LVITEM structure,
  69. // Blob is only allowed on a insert and set.
  70. // parent is only allowed on insert
  71. typedef struct _tagLVITEMEX
  72. {
  73. // original listviewItem Structure
  74. UINT mask;
  75. int iItem;
  76. int iSubItem;
  77. UINT state;
  78. UINT stateMask;
  79. LPWSTR pszText;
  80. int cchTextMax;
  81. int iImage;
  82. LPARAM lParam;
  83. int iIndent; // need to add indent to depth
  84. // new item methods that we need.
  85. UINT maskEx;
  86. int iParent; // set LVIFEX_PARENT maskEx when this field valid. If not LVI_ROOT is assumed.
  87. LPLVBLOB pBlob; // set LVIFEX_BLOB maskEx when this field is valid. Currently not returned on a GetItem.
  88. } LVITEMEX, *LPLVITEMEX;
  89. // notification structures for this listview First fields are identical to real listView
  90. typedef struct tagNMLISTVIEWEX{
  91. NMLISTVIEW nmListView;
  92. // specific notification items
  93. int iParent;
  94. LPLVBLOB pBlob;
  95. } NMLISTVIEWEX, *LPNMLISTVIEWEX;
  96. typedef struct tagNMLISTVIEWEXITEMCHECKCOUNT{
  97. NMHDR hdr;;
  98. // specific notification items
  99. int iCheckCount; // new checkCount
  100. int iItemId; // ItemIds who checkCount was changed.
  101. LVITEMSTATE dwItemState; // new state of the item whose checkcount has changed.
  102. } NMLISTVIEWEXITEMCHECKCOUNT, *LPNMLISTVIEWEXITEMCHECKCOUNT;
  103. // notification codes we wrap
  104. #define LVNEX_ITEMCHANGED LVN_ITEMCHANGED
  105. #define LVNEX_DBLCLK NM_DBLCLK
  106. #define LVNEX_CLICK NM_CLICK
  107. // notificaiton codes we send
  108. #define LVNEX_ITEMCHECKCOUNT (LVN_LAST + 1) // lparam contains number of items selected in the ListView.
  109. // #define INDEXTOSTATEIMAGEMASK(i) ((i) << 12) (Macro from commctrl.h usefull for setting state)
  110. // itemID is just how far into the list an item is. We keep a flat list of
  111. // of items in the same order they are displayed in the ListView.
  112. // have parent, children pointers just for optimization, Review if really need when done implimenting.
  113. typedef struct _tagListViewItem
  114. {
  115. // vars for keeping track of tree view status
  116. struct _tagListViewItem *pSubItems; // ptr to array of subItems for ListView Row.
  117. // internal vars
  118. BOOL fExpanded; // true if children are expanded
  119. int iChildren; // Number of children this node has.
  120. // native ListView structure and Item
  121. int iNativeListViewItemId; // id of Item in acutal listView - If not shown it is set to -1
  122. LVITEMEX lvItemEx; // current lvItemEx state for this item
  123. } LISTVIEWITEM;
  124. typedef LISTVIEWITEM* LPLISTVIEWITEM;
  125. class CListView
  126. {
  127. public:
  128. CListView(HWND hwnd,HWND hwndParent,int idCtrl,UINT MsgNotify); // contructor gives in ptr to the listView.
  129. ~CListView();
  130. // wrappers for top-level ListView calls
  131. BOOL DeleteAllItems();
  132. int GetItemCount(); // returns total number of items in the listview.
  133. UINT GetSelectedCount();
  134. int GetSelectionMark();
  135. HIMAGELIST GetImageList(int iImageList);
  136. HIMAGELIST SetImageList(HIMAGELIST himage,int iImageList);
  137. void SetExtendedListViewStyle(DWORD dwExStyle); // !!Handle checkboxes ourselves.
  138. // wrappers for basic listviewItem calls that we support
  139. // ids are given from our list, not the true ListView id.
  140. BOOL InsertItem(LPLVITEMEX pitem);
  141. BOOL DeleteItem(int iItem);
  142. BOOL DeleteChildren(int iItem);
  143. BOOL SetItem(LPLVITEMEX pitem);
  144. BOOL SetItemlParam(int iItem,LPARAM lParam);
  145. BOOL SetItemState(int iItem,UINT state,UINT mask);
  146. BOOL SetItemText(int iItem,int iSubItem,LPWSTR pszText);
  147. BOOL GetItem(LPLVITEMEX pitem);
  148. BOOL GetItemText(int iItem,int iSubItem,LPWSTR pszText,int cchTextMax);
  149. BOOL GetItemlParam(int iItem,LPARAM *plParam);
  150. HWND GetHwnd();
  151. HWND GetParent();
  152. // really helper function for generic set/getitem calls.
  153. int GetCheckState(int iItem); // return state from LVITEMEXSTATE enum.
  154. int GetCheckedItemsCount(); // returns the number of checked items.
  155. // wrapper for ListView Column Calls
  156. BOOL SetColumn(int iCol,LV_COLUMN * pColumn);
  157. int InsertColumn(int iCol,LV_COLUMN * pColumn);
  158. BOOL SetColumnWidth(int iCol,int cx);
  159. // TreeView like calls
  160. BOOL Expand(int iItemId); // expand children of this item,
  161. BOOL Collapse(int iItemId); // collapse children of this item,
  162. // helper functions not impl in either standard ListView or TreeView control
  163. int FindItemFromBlob(LPLVBLOB pBlob); // returns first toplevel item in list that matches blob
  164. LPLVBLOB GetItemBlob(int ItemId,LPLVBLOB pBlob,ULONG cbBlobSize);
  165. // notification method client must call when receives native listview notification
  166. LRESULT OnNotify(LPNMHDR pnmv);
  167. private:
  168. HWND m_hwnd;
  169. HWND m_hwndParent;
  170. int m_idCtrl;
  171. UINT m_MsgNotify;
  172. LPLISTVIEWITEM m_pListViewItems; // ptr to the array of listview Items.
  173. int m_iListViewNodeCount; // total number of nodes in the listView (Doesn't include SubItems
  174. int m_iListViewArraySize; // number of elements allocated in listViewItems array
  175. int m_iNumColumns; // number of columns for this listView
  176. int m_iCheckCount; // not of checked items in the ListView (Does not include indeterminate
  177. DWORD m_dwExStyle; // Extendend Style for this ListView
  178. private:
  179. LPLISTVIEWITEM ListViewItemFromNativeListViewItemId(int iNativeListViewItemId); // returns ptr to ListViewItem from native ListView ID.
  180. LPLISTVIEWITEM ListViewItemFromNativeListViewItemId(int iNativeListViewItemId,int iSubItem); // returns ptr to ListViewItem from native ListView ID.
  181. LPLISTVIEWITEM ListViewItemFromIndex(int iItemID); // returns ptr to ListViewItem from internal list.
  182. LPLISTVIEWITEM ListViewItemFromIndex(int iItemID,int iSubitem,int *piNativeListViewItemId);
  183. void DeleteListViewItemSubItems(LPLISTVIEWITEM pListItem);
  184. BOOL ExpandCollapse(LPLISTVIEWITEM pListViewItem,BOOL fExpand);
  185. BOOL IsEqualBlob(LPLVBLOB pBlob1,LPLVBLOB pBlob2);
  186. void OnGetDisplayInfo(UINT code,LV_DISPINFO *plvdi);
  187. BOOL OnHandleUIEvent(UINT code,UINT flags,WORD wVKey,int iItemNative);
  188. };
  189. #endif // _MOBSYNCLISTVIEW_