-
Notifications
You must be signed in to change notification settings - Fork 15
/
VarTreeGui.ahk
110 lines (95 loc) · 3.34 KB
/
VarTreeGui.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
#Include TreeListView.ahk
/*
VarTreeGui
Public interface:
vtg := VarTreeGui(RootNode)
vtg.TLV
vtg.Show()
vtg.Hide()
vtg.OnContextMenu := Func(vtg, node, isRightClick, x, y)
vtg.OnDoubleClick := Func(vtg, node)
*/
class VarTreeGui extends Gui
{
__New(RootNode) {
super.__New("+Resize -DPIScale",, this)
this.OnEvent("Escape", "Hide")
this.OnEvent("Size", "Resized")
this.OnEvent("ContextMenu", "ContextMenu")
this.MarginX := 0
this.MarginY := 0
this.TLV := this.AddVarTree(RootNode
, "w" 500*(A_ScreenDPI/96) " h" 300*(A_ScreenDPI/96) " LV0x10000 -LV0x10 -Multi", ["Name","Value"]) ; LV0x10 = LVS_EX_HEADERDRAGDROP
}
AddVarTree(p*) => VarTreeGui.Control(this, p*)
class Control extends TreeListView
{
static prototype.COL_NAME := 1, prototype.COL_VALUE := 2
MinEditColumn := 2
MaxEditColumn := 2
AutoSizeValueColumn() {
this.ModifyCol(this.COL_VALUE, "AutoHdr")
}
AfterPopulate() {
this.ModifyCol(this.COL_NAME, 150*(A_ScreenDPI/96))
this.AutoSizeValueColumn()
if !this.getNext(,"F")
this.modify(1, "Focus")
}
ExpandContract(r) {
super.ExpandContract(r)
this.AutoSizeValueColumn() ; Adjust for +/-scrollbars
}
RegisterEvents() {
super.RegisterEvents()
this.OnNotify(-326, (this, lParam) => ( ; HDN_BEGINTRACKW
this.BeforeHeaderResize(NumGet(lParam + A_PtrSize*3, "int") + 1)
))
this.OnNotify(-327, (this, lParam) => ( ; HDN_ENDTRACKW
this.AfterHeaderResize(NumGet(lParam + A_PtrSize*3, "int") + 1)
))
}
BeforeHeaderResize(column) {
if (column != this.COL_NAME)
return true
; Collapse to fit just the value so that scrollbars will be
; visible only when needed.
this.modifyCol(this.COL_VALUE, "Auto")
}
AfterHeaderResize(column) {
this.AutoSizeValueColumn()
}
SetNodeValue(node, column, value) {
if (column != this.COL_VALUE)
return
if (node.SetValue(value) = 0)
return
if !(r := this.RowFromNode(node))
return
this.modify(r, "Col" column, value)
if (!node.expandable && node.children) {
; Since value is a string, node can't be expanded
this.modify(r, "Icon1")
this.RemoveChildren(r+1, node)
node.children := ""
node.expanded := false
}
}
OnDoubleClick(node) {
g := this.Gui
if g && g.HasMethod('OnDoubleClick')
g.OnDoubleClick(node)
}
}
ContextMenu(ctrl, eventInfo, isRightClick, x, y) {
if (ctrl != this.TLV || !this.HasMethod('OnContextMenu'))
return
node := eventInfo ? this.TLV.NodeFromRow(eventInfo) : ""
this.OnContextMenu(node, isRightClick, x, y)
}
Resized(e, w, h) {
this["SysListView321"].Move(,, w, h)
this.TLV.AutoSizeValueColumn()
}
}