It's doable, I started writing an example and ended up with rather more than I intended.
This isn't polished and I can't guarantee it won't have issues, but in the interest of time I'll post it here so you can paste it into
http://addon.bool.no and have it generate an addon for you.
Lua Code:
local Button = CreateFrame('Button', nil, nil, 'SecureActionButtonTemplate,SecureHandlerStateTemplate')
Button:Hide()
Button:RegisterForClicks('AnyDown')
Button:SetFrameStrata('TOOLTIP')
Button:SetNormalTexture('interface/icons/inv_mushroom_11')
local Icon = Button:GetNormalTexture()
Icon:ClearAllPoints()
Icon:SetPoint('CENTER')
Icon:SetSize(24, 24)
Button:SetAttribute('type2', 'item')
Button:RegisterForDrag('LeftButton')
Button:SetScript('OnDragStart', function(self)
self.MouseDown = false
self:Hide()
PickupItem(self.link)
end)
Button:HookScript('OnMouseDown', function(self)
self.MouseDown = true
GameTooltip:Hide()
end)
Button:HookScript('OnMouseUp', function(self, Button)
self.MouseDown = false
if not MouseIsOver(self) then
self:Hide()
elseif Button ~= 'RightButton' then
DEFAULT_CHAT_FRAME:GetScript('OnHyperlinkClick')(DEFAULT_CHAT_FRAME, self.link, self.text, Button)
end
end)
RegisterStateDriver(Button, 'combat', '[combat]combat;')
Button:SetAttribute('_onstate-combat', 'if newstate == "combat" then self:Hide() end')
Button:SetScript('OnLeave', function(self) if not InCombatLockdown() and not self.MouseDown then self:Hide() end GameTooltip:Hide() end)
DEFAULT_CHAT_FRAME:HookScript('OnHyperlinkEnter', function(self, link, text)
local HyperlinkButton = GetMouseFocus()
Button.link, Button.text, Button.button = link, text, HyperlinkButton
local linkType = strsplit(':', link, 2)
if linkType == 'item' then
GameTooltip:SetOwner(HyperlinkButton, 'ANCHOR_RIGHT')
GameTooltip:SetHyperlink(link)
GameTooltip:Show()
end
if InCombatLockdown() or not link or not HyperlinkButton then return end
if linkType == 'item' then
Icon:SetTexture(GetItemIcon(link) or 'interface/Icons/inv_mushroom_11')
local left, bottom, width, height = HyperlinkButton:GetRect()
local scale = HyperlinkButton:GetEffectiveScale()
Button:ClearAllPoints()
Button:SetPoint('BOTTOMLEFT', nil, left * scale, bottom * scale)
Button:SetSize(width * scale, height * scale)
Button:SetAttribute('item2', link)
Button:Show()
end
end)
DEFAULT_CHAT_FRAME:HookScript('OnHyperlinkLeave', function(self, link, text)
if not Button:IsShown() then
GameTooltip:Hide()
end
end)
DEFAULT_CHAT_FRAME:HookScript('OnMessageScrollChanged', function(self)
if not Button:IsShown() then return end
if not Button.button or (not (MouseIsOver(Button.button) and MouseIsOver(Button)) and not Button.MouseDown) then
Button:Hide()
end
end)