wobin@20
|
1 local MAJOR = "LibQTipClick-1.1"
|
wobin@20
|
2 local MINOR = 3
|
wobin@20
|
3 assert(LibStub, MAJOR.." requires LibStub")
|
wobin@20
|
4
|
wobin@20
|
5 local lib, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
|
wobin@20
|
6
|
wobin@20
|
7 if not lib then return end -- No upgrade needed
|
wobin@20
|
8
|
wobin@20
|
9 local QTip = LibStub:GetLibrary("LibQTip-1.0")
|
wobin@20
|
10 assert(QTip, MAJOR.." requires LibQTip-1.0")
|
wobin@20
|
11
|
wobin@20
|
12 local CBH = LibStub:GetLibrary("CallbackHandler-1.0")
|
wobin@20
|
13 assert(CBH, MAJOR.." requires CallbackHandler-1.0")
|
wobin@20
|
14
|
wobin@20
|
15 -------------------------------------------------------------------------------
|
wobin@20
|
16 -- Local variables
|
wobin@20
|
17 -------------------------------------------------------------------------------
|
wobin@20
|
18 lib.LabelProvider, lib.LabelPrototype, lib.BaseProvider = QTip:CreateCellProvider(QTip.LabelProvider)
|
wobin@20
|
19 local cell_provider, cell_prototype, cell_base = lib.LabelProvider, lib.LabelPrototype, lib.BaseProvider
|
wobin@20
|
20
|
wobin@20
|
21 -------------------------------------------------------------------------------
|
wobin@20
|
22 -- Public library API
|
wobin@20
|
23 -------------------------------------------------------------------------------
|
wobin@20
|
24 local highlighter = CreateFrame("Frame", nil, UIParent)
|
wobin@20
|
25 highlighter:SetFrameStrata("TOOLTIP")
|
wobin@20
|
26 highlighter:Hide()
|
wobin@20
|
27
|
wobin@20
|
28 local cell_highlight = highlighter:CreateTexture(nil, "BACKGROUND")
|
wobin@20
|
29 cell_highlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
|
wobin@20
|
30 cell_highlight:SetBlendMode("ADD")
|
wobin@20
|
31 cell_highlight:SetAllPoints(highlighter)
|
wobin@20
|
32
|
wobin@20
|
33 function lib.OnEnter(event, cell, arg)
|
wobin@20
|
34 highlighter:SetAllPoints(cell)
|
wobin@20
|
35 highlighter:SetFrameLevel(cell:GetFrameLevel())
|
wobin@20
|
36 highlighter:Show()
|
wobin@20
|
37 end
|
wobin@20
|
38
|
wobin@20
|
39 function lib.OnLeave(event, cell, arg)
|
wobin@20
|
40 highlighter:ClearAllPoints()
|
wobin@20
|
41 highlighter:Hide()
|
wobin@20
|
42 end
|
wobin@20
|
43
|
wobin@20
|
44 function lib.OnMouseDown(event, cell, arg, button) PlaySound("igMainMenuOpen") end
|
wobin@20
|
45 function lib.OnMouseUp(event, cell, arg, button) end
|
wobin@20
|
46
|
wobin@20
|
47 local function Cell_OnEnter(cell) cell.callbacks:Fire("OnEnter", cell, cell.arg) end
|
wobin@20
|
48 local function Cell_OnLeave(cell) cell.callbacks:Fire("OnLeave", cell, cell.arg) end
|
wobin@20
|
49 local function Cell_OnMouseDown(cell, button) cell.callbacks:Fire("OnMouseDown", cell, cell.arg, button) end
|
wobin@20
|
50 local function Cell_OnMouseUp(cell, button) cell.callbacks:Fire("OnMouseUp", cell, cell.arg, button) end
|
wobin@20
|
51
|
wobin@20
|
52 function cell_prototype:InitializeCell() cell_base.InitializeCell(self) end
|
wobin@20
|
53
|
wobin@20
|
54 function cell_prototype:SetupCell(tooltip, value, justification, font, arg, ...)
|
wobin@20
|
55 local width, height = cell_base.SetupCell(self, tooltip, value, justification, font, ...)
|
wobin@20
|
56 self:EnableMouse(true)
|
wobin@20
|
57 self.arg = arg
|
wobin@20
|
58 self.callbacks = tooltip.callbacks
|
wobin@20
|
59 self:SetScript("OnEnter", Cell_OnEnter)
|
wobin@20
|
60 self:SetScript("OnLeave", Cell_OnLeave)
|
wobin@20
|
61 self:SetScript("OnMouseDown", Cell_OnMouseDown)
|
wobin@20
|
62 self:SetScript("OnMouseUp", Cell_OnMouseUp)
|
wobin@20
|
63
|
wobin@20
|
64 return width, height
|
wobin@20
|
65 end
|
wobin@20
|
66
|
wobin@20
|
67 function cell_prototype:ReleaseCell()
|
wobin@20
|
68 self:EnableMouse(false)
|
wobin@20
|
69 self:SetScript("OnEnter", nil)
|
wobin@20
|
70 self:SetScript("OnLeave", nil)
|
wobin@20
|
71 self:SetScript("OnMouseDown", nil)
|
wobin@20
|
72 self:SetScript("OnMouseUp", nil)
|
wobin@20
|
73 self.arg = nil
|
wobin@20
|
74 self.callbacks = nil
|
wobin@20
|
75 end
|
wobin@20
|
76
|
wobin@20
|
77 -------------------------------------------------------------------------------
|
wobin@20
|
78 -- LibQTip wrapper API
|
wobin@20
|
79 -------------------------------------------------------------------------------
|
wobin@20
|
80 local function AddNormalLine(tooltip, ...)
|
wobin@20
|
81 local oldProvider = tooltip:GetDefaultProvider()
|
wobin@20
|
82 tooltip:SetDefaultProvider(QTip.LabelProvider)
|
wobin@20
|
83 local lineNum, colNum = tooltip:AddLine(...)
|
wobin@20
|
84 tooltip:SetDefaultProvider(oldProvider)
|
wobin@20
|
85 return lineNum, colNum
|
wobin@20
|
86 end
|
wobin@20
|
87
|
wobin@20
|
88 local function AddNormalHeader(tooltip, ...)
|
wobin@20
|
89 local oldProvider = tooltip:GetDefaultProvider()
|
wobin@20
|
90 tooltip:SetDefaultProvider(QTip.LabelProvider)
|
wobin@20
|
91 local lineNum, colNum = tooltip:AddHeader(...)
|
wobin@20
|
92 tooltip:SetDefaultProvider(oldProvider)
|
wobin@20
|
93 return lineNum, colNum
|
wobin@20
|
94 end
|
wobin@20
|
95
|
wobin@20
|
96 local function SetNormalCell(tooltip, ...)
|
wobin@20
|
97 local oldProvider = tooltip:GetDefaultProvider()
|
wobin@20
|
98 tooltip:SetDefaultProvider(QTip.LabelProvider)
|
wobin@20
|
99 local lineNum, colNum = tooltip:SetCell(...)
|
wobin@20
|
100 tooltip:SetDefaultProvider(oldProvider)
|
wobin@20
|
101 return lineNum, colNum
|
wobin@20
|
102 end
|
wobin@20
|
103
|
wobin@20
|
104 function lib:Acquire(key, ...)
|
wobin@20
|
105 local tooltip = QTip:Acquire(key, ...)
|
wobin@20
|
106 tooltip:EnableMouse(true)
|
wobin@20
|
107
|
wobin@20
|
108 tooltip.callbacks = CBH:New(tooltip, "SetCallback", "UnSetCallback", "UnSetAllCallbacks" or false)
|
wobin@20
|
109 tooltip:SetCallback("OnEnter", self.OnEnter)
|
wobin@20
|
110 tooltip:SetCallback("OnLeave", self.OnLeave)
|
wobin@20
|
111 tooltip:SetCallback("OnMouseDown", self.OnMouseDown)
|
wobin@20
|
112 tooltip:SetCallback("OnMouseUp", self.OnMouseUp)
|
wobin@20
|
113
|
wobin@20
|
114 tooltip.AddNormalLine = AddNormalLine
|
wobin@20
|
115 tooltip.AddNormalHeader = AddNormalHeader
|
wobin@20
|
116 tooltip.SetNormalCell = SetNormalCell
|
wobin@20
|
117 tooltip:SetDefaultProvider(cell_provider)
|
wobin@20
|
118 return tooltip
|
wobin@20
|
119 end
|
wobin@20
|
120
|
wobin@20
|
121 function lib:IsAcquired(key) return QTip:IsAcquired(key) end
|
wobin@20
|
122
|
wobin@20
|
123 function lib:Release(tooltip)
|
wobin@20
|
124 if not tooltip then return end
|
wobin@20
|
125 tooltip:EnableMouse(false)
|
wobin@20
|
126 tooltip:UnSetAllCallbacks(tooltip)
|
wobin@20
|
127 tooltip.callbacks = nil
|
wobin@20
|
128 tooltip["SetCallback"] = nil
|
wobin@20
|
129 tooltip["UnSetCallback"] = nil
|
wobin@20
|
130 tooltip["UnSetAllCallbacks"] = nil
|
wobin@20
|
131 QTip:Release(tooltip)
|
wobin@20
|
132 end
|
wobin@20
|
133
|
wobin@20
|
134 function lib:IterateTooltips() return QTip:IterateTooltips() end
|
wobin@20
|
135 function lib:CreateCellProvider(baseProvider) return QTip:CreateCellProvider(baseProvider) end
|