55 "unsafe"
66
77 "github.com/lxn/win"
8- "github.com/whtiehack/wingui/winapi"
98)
109
1110// ListView is a wrapper for the Win32 SysListView32 control.
@@ -21,6 +20,8 @@ type ListView struct {
2120 OnItemChanged func (index int )
2221}
2322
23+ const lvmGetItemCount = win .LVM_FIRST + 4
24+
2425func (lv * ListView ) WndProc (msg uint32 , wParam , lParam uintptr ) uintptr {
2526 switch msg {
2627 case win .WM_NOTIFY :
@@ -48,7 +49,7 @@ func (lv *ListView) WndProc(msg uint32, wParam, lParam uintptr) uintptr {
4849
4950// SetExtendedStyle sets extended list-view styles (e.g. LVS_EX_FULLROWSELECT).
5051func (lv * ListView ) SetExtendedStyle (style uint32 ) {
51- lv .SendMessage (winapi .LVM_SETEXTENDEDLISTVIEWSTYLE , 0 , uintptr (style ))
52+ lv .SendMessage (win .LVM_SETEXTENDEDLISTVIEWSTYLE , 0 , uintptr (style ))
5253}
5354
5455// InsertColumn inserts a column at index and returns the actual inserted index (or -1).
@@ -61,7 +62,7 @@ func (lv *ListView) InsertColumn(index int, text string, width int, fmt int32) i
6162 PszText : & utf16 [0 ],
6263 ISubItem : int32 (index ),
6364 }
64- ret := lv .SendMessage (winapi . LVM_INSERTCOLUMNW , uintptr (index ), uintptr (unsafe .Pointer (& col )))
65+ ret := lv .SendMessage (win . LVM_INSERTCOLUMN , uintptr (index ), uintptr (unsafe .Pointer (& col )))
6566 return int (int32 (ret ))
6667}
6768
@@ -77,7 +78,7 @@ func (lv *ListView) InsertItem(index int, text string) int {
7778 ISubItem : 0 ,
7879 PszText : & utf16 [0 ],
7980 }
80- ret := lv .SendMessage (winapi . LVM_INSERTITEMW , 0 , uintptr (unsafe .Pointer (& item )))
81+ ret := lv .SendMessage (win . LVM_INSERTITEM , 0 , uintptr (unsafe .Pointer (& item )))
8182 return int (int32 (ret ))
8283}
8384
@@ -89,7 +90,7 @@ func (lv *ListView) SetItemText(itemIndex int, subItem int, text string) bool {
8990 ISubItem : int32 (subItem ),
9091 PszText : & utf16 [0 ],
9192 }
92- ret := lv .SendMessage (winapi . LVM_SETITEMTEXTW , uintptr (itemIndex ), uintptr (unsafe .Pointer (& item )))
93+ ret := lv .SendMessage (win . LVM_SETITEMTEXT , uintptr (itemIndex ), uintptr (unsafe .Pointer (& item )))
9394 return ret != 0
9495}
9596
@@ -102,28 +103,28 @@ func (lv *ListView) GetItemText(itemIndex int, subItem int) string {
102103 CchTextMax : int32 (len (buf )),
103104 PszText : & buf [0 ],
104105 }
105- lv .SendMessage (winapi . LVM_GETITEMTEXTW , uintptr (itemIndex ), uintptr (unsafe .Pointer (& item )))
106+ lv .SendMessage (win . LVM_GETITEMTEXT , uintptr (itemIndex ), uintptr (unsafe .Pointer (& item )))
106107 return syscall .UTF16ToString (buf )
107108}
108109
109110// ItemCount returns the number of items in the list.
110111func (lv * ListView ) ItemCount () int {
111- return int (int32 (lv .SendMessage (winapi . LVM_GETITEMCOUNT , 0 , 0 )))
112+ return int (int32 (lv .SendMessage (lvmGetItemCount , 0 , 0 )))
112113}
113114
114115// DeleteAllItems deletes all items.
115116func (lv * ListView ) DeleteAllItems () bool {
116- return lv .SendMessage (winapi .LVM_DELETEALLITEMS , 0 , 0 ) != 0
117+ return lv .SendMessage (win .LVM_DELETEALLITEMS , 0 , 0 ) != 0
117118}
118119
119120// DeleteItem deletes an item at index.
120121func (lv * ListView ) DeleteItem (index int ) bool {
121- return lv .SendMessage (winapi .LVM_DELETEITEM , uintptr (index ), 0 ) != 0
122+ return lv .SendMessage (win .LVM_DELETEITEM , uintptr (index ), 0 ) != 0
122123}
123124
124125// SelectedIndex returns the first selected item index, or -1 if none.
125126func (lv * ListView ) SelectedIndex () int {
126- ret := lv .SendMessage (winapi .LVM_GETNEXTITEM , ^ uintptr (0 ), uintptr (win .LVNI_SELECTED ))
127+ ret := lv .SendMessage (win .LVM_GETNEXTITEM , ^ uintptr (0 ), uintptr (win .LVNI_SELECTED ))
127128 return int (int32 (ret ))
128129}
129130
0 commit comments