wobin@20: local MAJOR = "LibQTipClick-1.1" wobin@20: local MINOR = 3 wobin@20: assert(LibStub, MAJOR.." requires LibStub") wobin@20: wobin@20: local lib, oldminor = LibStub:NewLibrary(MAJOR, MINOR) wobin@20: wobin@20: if not lib then return end -- No upgrade needed wobin@20: wobin@20: local QTip = LibStub:GetLibrary("LibQTip-1.0") wobin@20: assert(QTip, MAJOR.." requires LibQTip-1.0") wobin@20: wobin@20: local CBH = LibStub:GetLibrary("CallbackHandler-1.0") wobin@20: assert(CBH, MAJOR.." requires CallbackHandler-1.0") wobin@20: wobin@20: ------------------------------------------------------------------------------- wobin@20: -- Local variables wobin@20: ------------------------------------------------------------------------------- wobin@20: lib.LabelProvider, lib.LabelPrototype, lib.BaseProvider = QTip:CreateCellProvider(QTip.LabelProvider) wobin@20: local cell_provider, cell_prototype, cell_base = lib.LabelProvider, lib.LabelPrototype, lib.BaseProvider wobin@20: wobin@20: ------------------------------------------------------------------------------- wobin@20: -- Public library API wobin@20: ------------------------------------------------------------------------------- wobin@20: local highlighter = CreateFrame("Frame", nil, UIParent) wobin@20: highlighter:SetFrameStrata("TOOLTIP") wobin@20: highlighter:Hide() wobin@20: wobin@20: local cell_highlight = highlighter:CreateTexture(nil, "BACKGROUND") wobin@20: cell_highlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight") wobin@20: cell_highlight:SetBlendMode("ADD") wobin@20: cell_highlight:SetAllPoints(highlighter) wobin@20: wobin@20: function lib.OnEnter(event, cell, arg) wobin@20: highlighter:SetAllPoints(cell) wobin@20: highlighter:SetFrameLevel(cell:GetFrameLevel()) wobin@20: highlighter:Show() wobin@20: end wobin@20: wobin@20: function lib.OnLeave(event, cell, arg) wobin@20: highlighter:ClearAllPoints() wobin@20: highlighter:Hide() wobin@20: end wobin@20: wobin@20: function lib.OnMouseDown(event, cell, arg, button) PlaySound("igMainMenuOpen") end wobin@20: function lib.OnMouseUp(event, cell, arg, button) end wobin@20: wobin@20: local function Cell_OnEnter(cell) cell.callbacks:Fire("OnEnter", cell, cell.arg) end wobin@20: local function Cell_OnLeave(cell) cell.callbacks:Fire("OnLeave", cell, cell.arg) end wobin@20: local function Cell_OnMouseDown(cell, button) cell.callbacks:Fire("OnMouseDown", cell, cell.arg, button) end wobin@20: local function Cell_OnMouseUp(cell, button) cell.callbacks:Fire("OnMouseUp", cell, cell.arg, button) end wobin@20: wobin@20: function cell_prototype:InitializeCell() cell_base.InitializeCell(self) end wobin@20: wobin@20: function cell_prototype:SetupCell(tooltip, value, justification, font, arg, ...) wobin@20: local width, height = cell_base.SetupCell(self, tooltip, value, justification, font, ...) wobin@20: self:EnableMouse(true) wobin@20: self.arg = arg wobin@20: self.callbacks = tooltip.callbacks wobin@20: self:SetScript("OnEnter", Cell_OnEnter) wobin@20: self:SetScript("OnLeave", Cell_OnLeave) wobin@20: self:SetScript("OnMouseDown", Cell_OnMouseDown) wobin@20: self:SetScript("OnMouseUp", Cell_OnMouseUp) wobin@20: wobin@20: return width, height wobin@20: end wobin@20: wobin@20: function cell_prototype:ReleaseCell() wobin@20: self:EnableMouse(false) wobin@20: self:SetScript("OnEnter", nil) wobin@20: self:SetScript("OnLeave", nil) wobin@20: self:SetScript("OnMouseDown", nil) wobin@20: self:SetScript("OnMouseUp", nil) wobin@20: self.arg = nil wobin@20: self.callbacks = nil wobin@20: end wobin@20: wobin@20: ------------------------------------------------------------------------------- wobin@20: -- LibQTip wrapper API wobin@20: ------------------------------------------------------------------------------- wobin@20: local function AddNormalLine(tooltip, ...) wobin@20: local oldProvider = tooltip:GetDefaultProvider() wobin@20: tooltip:SetDefaultProvider(QTip.LabelProvider) wobin@20: local lineNum, colNum = tooltip:AddLine(...) wobin@20: tooltip:SetDefaultProvider(oldProvider) wobin@20: return lineNum, colNum wobin@20: end wobin@20: wobin@20: local function AddNormalHeader(tooltip, ...) wobin@20: local oldProvider = tooltip:GetDefaultProvider() wobin@20: tooltip:SetDefaultProvider(QTip.LabelProvider) wobin@20: local lineNum, colNum = tooltip:AddHeader(...) wobin@20: tooltip:SetDefaultProvider(oldProvider) wobin@20: return lineNum, colNum wobin@20: end wobin@20: wobin@20: local function SetNormalCell(tooltip, ...) wobin@20: local oldProvider = tooltip:GetDefaultProvider() wobin@20: tooltip:SetDefaultProvider(QTip.LabelProvider) wobin@20: local lineNum, colNum = tooltip:SetCell(...) wobin@20: tooltip:SetDefaultProvider(oldProvider) wobin@20: return lineNum, colNum wobin@20: end wobin@20: wobin@20: function lib:Acquire(key, ...) wobin@20: local tooltip = QTip:Acquire(key, ...) wobin@20: tooltip:EnableMouse(true) wobin@20: wobin@20: tooltip.callbacks = CBH:New(tooltip, "SetCallback", "UnSetCallback", "UnSetAllCallbacks" or false) wobin@20: tooltip:SetCallback("OnEnter", self.OnEnter) wobin@20: tooltip:SetCallback("OnLeave", self.OnLeave) wobin@20: tooltip:SetCallback("OnMouseDown", self.OnMouseDown) wobin@20: tooltip:SetCallback("OnMouseUp", self.OnMouseUp) wobin@20: wobin@20: tooltip.AddNormalLine = AddNormalLine wobin@20: tooltip.AddNormalHeader = AddNormalHeader wobin@20: tooltip.SetNormalCell = SetNormalCell wobin@20: tooltip:SetDefaultProvider(cell_provider) wobin@20: return tooltip wobin@20: end wobin@20: wobin@20: function lib:IsAcquired(key) return QTip:IsAcquired(key) end wobin@20: wobin@20: function lib:Release(tooltip) wobin@20: if not tooltip then return end wobin@20: tooltip:EnableMouse(false) wobin@20: tooltip:UnSetAllCallbacks(tooltip) wobin@20: tooltip.callbacks = nil wobin@20: tooltip["SetCallback"] = nil wobin@20: tooltip["UnSetCallback"] = nil wobin@20: tooltip["UnSetAllCallbacks"] = nil wobin@20: QTip:Release(tooltip) wobin@20: end wobin@20: wobin@20: function lib:IterateTooltips() return QTip:IterateTooltips() end wobin@20: function lib:CreateCellProvider(baseProvider) return QTip:CreateCellProvider(baseProvider) end