-
Notifications
You must be signed in to change notification settings - Fork 3
/
_Menu.ListBox.ahk
180 lines (180 loc) · 4.46 KB
/
_Menu.ListBox.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
Class ListBox extends eAutocomplete._Menu.BasicControlList {
__New(_GUIID, _x, _y) {
local
base.__New(_GUIID)
GUI % this._hHost . ":Add", ListBox, % "-Sort -Multi -HScroll +VScroll hwnd_hListBox x" _x . " y" . _y,
this.HWND := _hListBox
this.selection := new this.SelectionWrapper(this.HWND)
_font := this._font := new this.FontWrapper(this.HWND)
_font.name := "Segoe UI", _font.size := 12, _font.color := "000000"
}
font {
set {
return this.font
}
get {
return this._font
}
}
_onItemClick := ""
onItemClick {
set {
if (IsFunc(value)) {
this._onItemClick := StrLen(value) ? Func(value) : value
} else if (IsObject(value)) {
this._onItemClick := value
} else this._onItemClick := ""
return this._onItemClick
}
get {
return this._onItemClick
}
}
_dispose() {
sleep, 1
base._dispose()
this._font := ""
this.onItemClick := ""
this.selection._dispose()
}
__Delete() {
; MsgBox % A_ThisFunc
}
resize(_w, _h) {
GuiControl, Move, % this.HWND, % Format("w{} h{}", _w, _h)
}
getPos(ByRef _x:="", ByRef _y:="") {
WinGetPos, _x, _y,,, % "ahk_id " . this.HWND
}
setlist(_list) {
local
_delimiter := this.delimiter
_list := Trim(_list, _delimiter), _count := 0
if (_list <> "") {
_threshold := this._MAXITEMS
StrReplace(_list, _delimiter,, _count)
if (++_count > _threshold) {
_count := _threshold, _list := SubStr(_list, 1, InStr(_list, _delimiter,,, ++_threshold) - 1)
}
}
this.itemCount := _count
GuiControl, -Redraw, % this.HWND
GuiControl,, % this.HWND, % _delimiter . this._list:=_list
GuiControl, +Redraw, % this.HWND
; ((this.itemCount := _count) && this.selection.index:=1) ; <<<<
}
getItemFromPointer() {
local
static LB_ITEMFROMPOINT := 0x01A9
; if not (DllCall("IsWindowVisible", "Ptr", this.HWND))
; return -1
VarSetCapacity(_POINT_, 8, 0)
DllCall("GetCursorPos", "Ptr", &_POINT_)
DllCall("ScreenToClient", "Ptr", this.HWND, "Ptr", &_POINT_)
_x := NumGet(_POINT_, 0, "UShort"), _y := NumGet(_POINT_, 4, "UShort") << 16
SendMessage % LB_ITEMFROMPOINT, 0, % (_x + _y),, % "ahk_id " . this.HWND
return (ErrorLevel & 0xFFFF0000) ? -1 : (ErrorLevel & 0xFFFF)
}
_itemClickHandler() {
local
KeyWait, LButton, T0.65
_e := ErrorLevel
if (DllCall("IsWindowVisible", "Ptr", this.HWND))
((_onItemClick:=this.onItemClick) && _onItemClick.call(this.selection.text, _e))
}
__itemClick(_itemIndex:="") {
local
(this.selection.index:=_itemIndex)
_fn := this._itemClickHandler.bind(this)
SetTimer % _fn, -1
}
itemHeight {
get {
static LB_GETITEMHEIGHT := 0x1A1
SendMessage % LB_GETITEMHEIGHT, 0, 0,, % "ahk_id " . this.HWND
return ErrorLevel
}
set {
return this.itemHeight
}
}
selectPrevious() {
this.selection.previousItem()
}
selectNext() {
this.selection.nextItem()
}
Class SelectionWrapper {
__New(_parent) {
local
this._parent := _parent
; _fn := this.__index.bind(this)
; GuiControl, +g, % _parent, % _fn
}
_dispose() {
; GuiControl, -g, % this._parent,
}
__index(_hControl, _GUIEvent, _eventInfo, _errorLevel:="") {
; ...
}
itemCount {
get {
static LB_GETCOUNT := 0x18B
SendMessage % LB_GETCOUNT, 0, 0,, % "ahk_id " . this._parent
return ErrorLevel
}
set {
return this.itemCount
}
}
previousItem() {
local
_index := this.index - 1
this.index := (_index < 1) ? this.itemCount : _index
}
nextItem() {
local
_index := this.index + 1
this.index := (_index > this.itemCount) ? 1 : _index
}
isVisible() {
return DllCall("IsWindowVisible", "Ptr", this._parent)
}
index {
set {
static LB_SETCURSEL := 0x0186
if ((value+0 <> "") && value <> this.index)
SendMessage % LB_SETCURSEL, % --value, 0,, % "ahk_id " . this._parent
return this.index
}
get {
local
static LB_GETCURSEL := 0x188
SendMessage, 0x188, 0, 0,, % "ahk_id " . this._parent
_pos := ErrorLevel << 32 >> 32
return ++_pos
}
}
text {
get {
local
ControlGet, _item, Choice,,, % "ahk_id " . this._parent
return _item
}
set {
return this.text
}
}
offsetTop {
get {
static LB_GETTOPINDEX := 0x018E
SendMessage % LB_GETTOPINDEX, 0, 0,, % "ahk_id " . this._parent
_e := ErrorLevel
return this.index - _e
}
set {
return this.offsetTop
}
}
}
}