1 // Windows/Control/ListView.h 2 3 #ifndef __WINDOWS_CONTROL_LISTVIEW_H 4 #define __WINDOWS_CONTROL_LISTVIEW_H 5 6 #include "../Window.h" 7 8 #include <commctrl.h> 9 10 namespace NWindows { 11 namespace NControl { 12 13 class CListView: public NWindows::CWindow 14 { 15 public: 16 bool CreateEx(DWORD exStyle, DWORD style, 17 int x, int y, int width, int height, 18 HWND parentWindow, HMENU idOrHMenu, 19 HINSTANCE instance, LPVOID createParam); 20 21 void SetUnicodeFormat() 22 { 23 #ifndef UNDER_CE 24 ListView_SetUnicodeFormat(_window, TRUE); 25 #endif 26 } 27 28 bool DeleteAllItems() { return BOOLToBool(ListView_DeleteAllItems(_window)); } 29 bool DeleteColumn(int columnIndex) { return BOOLToBool(ListView_DeleteColumn(_window, columnIndex)); } 30 31 int InsertColumn(int columnIndex, const LVCOLUMN *columnInfo) { return ListView_InsertColumn(_window, columnIndex, columnInfo); } 32 int InsertColumn(int columnIndex, LPCTSTR text, int width); 33 int InsertItem(const LVITEM* item) { return ListView_InsertItem(_window, item); } 34 int InsertItem(int index, LPCTSTR text); 35 bool SetItem(const LVITEM* item) { return BOOLToBool(ListView_SetItem(_window, item)); } 36 int SetSubItem(int index, int subIndex, LPCTSTR text); 37 38 #ifndef _UNICODE 39 40 int InsertColumn(int columnIndex, const LVCOLUMNW *columnInfo) { return (int)SendMessage(LVM_INSERTCOLUMNW, (WPARAM)columnIndex, (LPARAM)columnInfo); } 41 int InsertColumn(int columnIndex, LPCWSTR text, int width); 42 int InsertItem(const LV_ITEMW* item) { return (int)SendMessage(LVM_INSERTITEMW, 0, (LPARAM)item); } 43 int InsertItem(int index, LPCWSTR text); 44 bool SetItem(const LV_ITEMW* item) { return BOOLToBool((BOOL)SendMessage(LVM_SETITEMW, 0, (LPARAM)item)); } 45 int SetSubItem(int index, int subIndex, LPCWSTR text); 46 47 #endif 48 49 bool DeleteItem(int itemIndex) { return BOOLToBool(ListView_DeleteItem(_window, itemIndex)); } 50 51 UINT GetSelectedCount() const { return ListView_GetSelectedCount(_window); } 52 int GetItemCount() const { return ListView_GetItemCount(_window); } 53 54 INT GetSelectionMark() const { return ListView_GetSelectionMark(_window); } 55 56 void SetItemCount(int numItems) { ListView_SetItemCount(_window, numItems); } 57 void SetItemCountEx(int numItems, DWORD flags) { ListView_SetItemCountEx(_window, numItems, flags); } 58 59 int GetNextItem(int startIndex, UINT flags) const { return ListView_GetNextItem(_window, startIndex, flags); } 60 int GetNextSelectedItem(int startIndex) const { return GetNextItem(startIndex, LVNI_SELECTED); } 61 int GetFocusedItem() const { return GetNextItem(-1, LVNI_FOCUSED); } 62 63 bool GetItem(LVITEM* item) const { return BOOLToBool(ListView_GetItem(_window, item)); } 64 bool GetItemParam(int itemIndex, LPARAM ¶m) const; 65 void GetItemText(int itemIndex, int subItemIndex, LPTSTR text, int textSizeMax) const 66 { ListView_GetItemText(_window, itemIndex, subItemIndex, text, textSizeMax); } 67 bool SortItems(PFNLVCOMPARE compareFunction, LPARAM dataParam) 68 { return BOOLToBool(ListView_SortItems(_window, compareFunction, dataParam)); } 69 70 void SetItemState(int index, UINT state, UINT mask) { ListView_SetItemState(_window, index, state, mask); } 71 void SetItemState_Selected(int index, bool select) { SetItemState(index, select ? LVIS_SELECTED : 0, LVIS_SELECTED); } 72 void SetItemState_Selected(int index) { SetItemState(index, LVIS_SELECTED, LVIS_SELECTED); } 73 void SelectAll() { SetItemState_Selected(-1); } 74 void SetItemState_FocusedSelected(int index) { SetItemState(index, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); } 75 UINT GetItemState(int index, UINT mask) const { return ListView_GetItemState(_window, index, mask); } 76 bool IsItemSelected(int index) const { return GetItemState(index, LVIS_SELECTED) == LVIS_SELECTED; } 77 78 bool GetColumn(int columnIndex, LVCOLUMN* columnInfo) const 79 { return BOOLToBool(ListView_GetColumn(_window, columnIndex, columnInfo)); } 80 81 HIMAGELIST SetImageList(HIMAGELIST imageList, int imageListType) 82 { return ListView_SetImageList(_window, imageList, imageListType); } 83 84 // version 4.70: NT5 | (NT4 + ie3) | w98 | (w95 + ie3) 85 DWORD GetExtendedListViewStyle() { return ListView_GetExtendedListViewStyle(_window); } 86 void SetExtendedListViewStyle(DWORD exStyle) { ListView_SetExtendedListViewStyle(_window, exStyle); } 87 void SetExtendedListViewStyle(DWORD exMask, DWORD exStyle) { ListView_SetExtendedListViewStyleEx(_window, exMask, exStyle); } 88 89 void SetCheckState(UINT index, bool checkState) { ListView_SetCheckState(_window, index, BoolToBOOL(checkState)); } 90 bool GetCheckState(UINT index) { return BOOLToBool(ListView_GetCheckState(_window, index)); } 91 92 bool EnsureVisible(int index, bool partialOK) { return BOOLToBool(ListView_EnsureVisible(_window, index, BoolToBOOL(partialOK))); } 93 94 bool GetItemRect(int index, RECT *rect, int code) { return BOOLToBool(ListView_GetItemRect(_window, index, rect, code)); } 95 96 HWND GetEditControl() { return ListView_GetEditControl(_window) ; } 97 HWND EditLabel(int itemIndex) { return ListView_EditLabel(_window, itemIndex) ; } 98 99 bool RedrawItems(int firstIndex, int lastIndex) { return BOOLToBool(ListView_RedrawItems(_window, firstIndex, lastIndex)); } 100 bool RedrawAllItems() 101 { 102 if (GetItemCount() > 0) 103 return RedrawItems(0, GetItemCount() - 1); 104 return true; 105 } 106 bool RedrawItem(int index) { return RedrawItems(index, index); } 107 108 int HitTest(LPLVHITTESTINFO info) { return ListView_HitTest(_window, info); } 109 COLORREF GetBkColor() { return ListView_GetBkColor(_window); } 110 bool SetColumnWidth(int iCol, int cx) { return BOOLToBool(ListView_SetColumnWidth(_window, iCol, cx)); } 111 bool SetColumnWidthAuto(int iCol) { return SetColumnWidth(iCol, LVSCW_AUTOSIZE); } 112 }; 113 114 class CListView2: public CListView 115 { 116 WNDPROC _origWindowProc; 117 public: 118 void SetWindowProc(); 119 virtual LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam); 120 }; 121 122 /* 123 class CListView3: public CListView2 124 { 125 public: 126 virtual LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam); 127 }; 128 */ 129 130 }} 131 132 #endif 133