/trunk/FuBar_RecapFu/libs/Tablet-2.0
--[[ |
Name: Tablet-2.0 |
Revision: $Rev: 30695 $ |
Revision: $Rev: 216 $ |
Author(s): ckknight (ckknight@gmail.com) |
Website: http://ckknight.wowinterface.com/ |
Documentation: http://www.wowace.com/index.php/Tablet-2.0 |
]] |
local MAJOR_VERSION = "Tablet-2.0" |
local MINOR_VERSION = tonumber(("$Revision: 30695 $"):sub(12, -3)) |
local MINOR_VERSION = 90000 + tonumber(("$Revision: 216 $"):match("(%d+)")) |
if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary") end |
if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end |
LOCK = "éå®" |
LOCK_DESC = "éå®èåå½åä½ç½®. alt+å³é® å°æ¾ç¤ºé项, alt+æå¨ å¯ä»¥ç§»å¨å·²éå®çèå." |
elseif GetLocale() == "zhTW" then |
SCROLL_UP = "åä¸ç¿»è½" |
SCROLL_DOWN = "åä¸ç¿»è½" |
SCROLL_UP = "åä¸ç¿»æ²" |
SCROLL_DOWN = "åä¸ç¿»æ²" |
HINT = "æ示" |
DETACH = "åé¢" |
DETACH_DESC = "åé¢é¸å®çºç¨ç«æ示ã" |
SIZE = "尺寸" |
SIZE_DESC = "縮æ¾é¸å®é¡¯ç¤ºå°ºå¯¸ã" |
CLOSE_MENU = "ééé¸å®" |
CLOSE_MENU_DESC = "ééé¸å®" |
CLOSE_MENU_DESC = "ééé¸å®ã" |
COLOR = "èæ¯é¡è²" |
COLOR_DESC = "è¨ç½®é¸å®èæ¯é¡è²ã" |
COLOR_DESC = "è¨å®é¸å®èæ¯é¡è²ã" |
LOCK = "éå®" |
LOCK_DESC = "éå®é¸å®ç®åä½ç½®. Alt+å³éµ å°é¡¯ç¤ºé¸é ï¼Alt+æå å¯ä»¥ç§»åå·²éå®çé¸å®ã" |
LOCK_DESC = "éå®é¸å®ç®åä½ç½®è¨å®ãAlt-å³éµå°é¡¯ç¤ºé¸é ï¼Alt-æåå¯ä»¥ç§»åå·²éå®çé¸å®ã" |
elseif GetLocale() == "frFR" then |
SCROLL_UP = "Parcourir vers le haut" |
SCROLL_DOWN = "Parcourir vers le bas" |
COLOR_DESC = "Establece el color de fondo" |
LOCK = "Bloquear" |
LOCK_DESC = "Bloquea el tooltip en su posici\195\179n actual. Clic+Alt para el men\195\186 y arrastra+Alt para arrastrarlo cuando est\195\161 bloqueado" |
elseif GetLocale() == "ruRU" then |
SCROLL_UP = "ÐÑокÑÑÑка ввеÑÑ " |
SCROLL_DOWN = "ÐÑокÑÑÑка вниз" |
HINT = "СовеÑ" |
DETACH = "ÐÑделиÑÑ" |
DETACH_DESC = "ÐÑделиÑÑ Ð¿Ð»Ð°Ð½ÑÐµÑ Ð¾Ñ ÐµÐ³Ð¾ иÑÑоÑника." |
SIZE = "РазмеÑ" |
SIZE_DESC = "ÐаÑÑÑаб планÑеÑа." |
CLOSE_MENU = "ÐакÑÑÑÑ Ð¼ÐµÐ½Ñ" |
CLOSE_MENU_DESC = "ÐакÑÑÑÑ Ð¼ÐµÐ½Ñ." |
COLOR = "Ð¦Ð²ÐµÑ Ñона" |
COLOR_DESC = "УÑÑановиÑÑ ÑÐ²ÐµÑ Ñона." |
LOCK = "ÐаÑикÑиÑоваÑÑ" |
LOCK_DESC = "ÐаÑикÑиÑоваÑÑ Ð¿Ð»Ð°Ð½ÑÐµÑ Ð² его ÑекÑÑем позиÑии. Alt+ÐÐÐ Ð´Ð»Ñ Ð¼ÐµÐ½Ñ Ð¸Ð»Ð¸ Alt+пеÑеÑаÑкивание Ð´Ð»Ñ Ð¿ÐµÑеÑаÑÐºÐ¸Ð²Ð°Ð½Ð¸Ñ ÐºÐ¾Ð³Ð´Ð° планÑÐµÑ Ð·Ð°ÑикÑиÑован." |
end |
local start = GetTime() |
if UIParent:IsShown() then |
return UIParent |
end |
local f = GetFullScreenFrame() |
local f = GetUIPanel("fullscreen") |
if f and f:IsShown() then |
return f |
end |
return nil |
end |
GetMainFrame = wrap(GetMainFrame, "GetMainFrame") |
local MIN_TOOLTIP_SIZE = 200 |
local TESTSTRING_EXTRA_WIDTH = 8 |
local pool = {} |
local function del(t) |
if t then |
for k in pairs(t) do |
t[k] = nil |
end |
setmetatable(t, nil) |
pool[t] = true |
setmetatable(t, nil) |
for k in pairs(t) do |
t[k] = nil |
end |
t[''] = true |
t[''] = nil |
pool[t] = true |
return nil |
end |
local new |
local function copy(parent) |
local t = next(pool) or {} |
pool[t] = nil |
local t = next(pool) |
if not t then |
t = {} |
else |
pool[t] = nil |
end |
if parent then |
for k,v in pairs(parent) do |
t[k] = v |
return t |
end |
function new(...) |
local t = next(pool) or {} |
pool[t] = nil |
local function new(...) |
local t = next(pool) |
if not t then |
t = {} |
else |
pool[t] = nil |
end |
for i = 1, select('#', ...), 2 do |
local k = select(i, ...) |
local headerSize, normalSize |
if GameTooltipHeaderText then |
_,headerSize = GameTooltipHeaderText:GetFont() |
headerSize = select(2,GameTooltipHeaderText:GetFont()) |
else |
headerSize = 14 |
end |
if GameTooltipText then |
_,normalSize = GameTooltipText:GetFont() |
normalSize = select(2,GameTooltipText:GetFont()) |
else |
normalSize = 12 |
end |
testString:SetText(text) |
return testString:GetStringWidth()-- + TESTSTRING_EXTRA_WIDTH |
end |
getTestWidth = wrap(getTestWidth, "getTestWidth") |
do |
local TabletData_mt = { __index = TabletData } |
function TabletData:new(tablet) |
setmetatable(self, TabletData_mt) |
return self |
end |
TabletData.new = wrap(TabletData.new, "TabletData:new") |
function TabletData:checkMinWidth() |
local min = self.minWidth or MIN_TOOLTIP_SIZE |
self.width = width |
end |
end |
TabletData.checkMinWidth = wrap(TabletData.checkMinWidth, "TabletData:checkMinWidth") |
function TabletData:del() |
for k, v in ipairs(self.categories) do |
del(self.categories) |
del(self) |
end |
TabletData.del = wrap(TabletData.del, "TabletData:del") |
function TabletData:Display() |
if self.title and (self.tablet == tooltip or self.tablet.registration.showTitleWhenDetached) then |
self.tablet.tmpHidden = nil |
end |
end |
TabletData.Display = wrap(TabletData.Display, "TabletData:Display") |
function TabletData:AddCategory(info, index) |
local made = false |
end |
return cat |
end |
TabletData.AddCategory = wrap(TabletData.AddCategory, "TabletData:AddCategory") |
function TabletData:SetHint(hint) |
self.hint = hint |
end |
TabletData.SetHint = wrap(TabletData.SetHint, "TabletData:SetHint") |
function TabletData:SetTitle(title) |
self.title = title or "Title" |
end |
TabletData.SetTitle = wrap(TabletData.SetTitle, "TabletData:SetTitle") |
function TabletData:SetTitleColor(r, g, b) |
self.titleR = r |
self.titleG = g |
self.titleB = b |
end |
TabletData.SetTitleColor = wrap(TabletData.SetTitleColor, "TabletData:SetTitleColor") |
end |
do |
local Category_mt = { __index = Category } |
if superCategory and not self.noInherit then |
self.superCategory = superCategory.superCategory |
for k, v in pairs(superCategory) do |
if string.find(k, "^child_") then |
if k:find("^child_") then |
local k = strsub(k, 7) |
if self[k] == nil then |
self[k] = v |
x['size' .. i] = self['size' .. i] |
x['justify' .. i] = self['justify' .. i] |
end |
if self.checkIcon and string.find(self.checkIcon, "^Interface\\Icons\\") then |
if self.checkIcon and self.checkIcon:find("^Interface\\Icons\\") then |
x.checkCoordLeft = self.checkCoordLeft or 0.05 |
x.checkCoordRight = self.checkCoordRight or 0.95 |
x.checkCoordTop = self.checkCoordTop or 0.05 |
end |
return self |
end |
Category.new = wrap(Category.new, "Category:new") |
function Category:del() |
local prev = garbageLine |
del(self.lines) |
del(self) |
end |
Category.del = wrap(Category.del, "Category:del") |
function Category:AddLine(...) |
self.lastWasTitle = nil |
info = del(info) |
end |
end |
Category.AddLine = wrap(Category.AddLine, "Category:AddLine") |
function Category:AddCategory(...) |
local lastWasTitle = self.lastWasTitle |
end |
return cat |
end |
Category.AddCategory = wrap(Category.AddCategory, "Category:AddCategory") |
function Category:HasChildren() |
local hasChildren = false |
end |
return false |
end |
Category.HasChildren = wrap(Category.HasChildren, "Category:HasChildren") |
local lastWasTitle = false |
function Category:Display(tablet) |
if not self.hideBlankLine and not lastWasTitle then |
local info = new( |
'blank', true, |
'fakeChild', true |
'fakeChild', true, |
'noInherit', true |
) |
self:AddLine(info, 1) |
del(info) |
lastWasTitle = self.isTitle |
return good |
end |
Category.Display = wrap(Category.Display, "Category:Display") |
end |
do |
local Line_mt = { __index = Line } |
local self = copy(info) |
if not info.noInherit then |
for k, v in pairs(category) do |
if string.find(k, "^child_") then |
if k:find("^child_") then |
local k = strsub(k, 7) |
if self[k] == nil then |
self[k] = v |
end |
end |
if not self.size then |
_,self.size = self.font:GetFont() |
self.size = select(2,self.font:GetFont()) |
end |
for i = 2, columns do |
if not self['size' .. i] then |
_,self['size' .. i] = self['font' .. i]:GetFont() |
self['size' .. i] = select(2,self['font' .. i]:GetFont()) |
end |
end |
if self.checkIcon and string.find(self.checkIcon, "^Interface\\Icons\\") then |
if self.checkIcon and self.checkIcon:find("^Interface\\Icons\\") then |
if not self.checkCoordLeft then |
self.checkCoordLeft = 0.05 |
end |
end |
return self |
end |
Line.new = wrap(Line.new, "Line:new") |
function Line:del() |
del(self) |
end |
Line.del = wrap(Line.del, "Line:del") |
function Line:Display(tablet) |
tablet:AddLine(self) |
return true |
end |
Line.Display = wrap(Line.Display, "Line:Display") |
end |
local fake_ipairs |
end |
return iter, tmp, 0 |
end |
fake_ipairs = wrap(fake_ipairs, "fake_ipairs") |
end |
local function argunpack(t, key, i) |
if v then |
return v, argunpack(t, key, i+1) |
end |
end |
end |
argunpack = wrap(argunpack, "argunpack") |
local delstring, newstring |
t:SetParent(UIParent) |
return nil |
end |
delstring = wrap(delstring, "delstring") |
function newstring(parent) |
if #cache ~= 0 then |
local t = cache[#cache] |
local t = parent:CreateFontString(nil, "ARTWORK") |
return t |
end |
newstring = wrap(newstring, "newstring") |
end |
local function button_OnEnter(this, ...) |
geterrorhandler()(ret) |
end |
end |
end |
end |
button_OnEnter = wrap(button_OnEnter, "button_OnEnter") |
local function button_OnLeave(this, ...) |
if type(this.self:GetScript("OnLeave")) == "function" then |
end |
end |
end |
button_OnLeave = wrap(button_OnLeave, "button_OnLeave") |
local lastMouseDown |
local function button_OnClick(this, arg1, ...) |
if this.self:HasScript("OnClick") and type(this.self:GetScript("OnClick")) == "function" then |
end |
end |
end |
button_OnClick = wrap(button_OnClick, "button_OnClick") |
local function button_OnMouseUp(this, arg1, ...) |
if this.self:HasScript("OnMouseUp") and type(this.self:GetScript("OnMouseUp")) == "function" then |
this.self:GetScript("OnMouseUp")(this.self, arg1, ...) |
end |
end |
end |
button_OnMouseUp = wrap(button_OnMouseUp, "button_OnMouseUp") |
local function button_OnMouseDown(this, arg1, ...) |
if this.self:HasScript("OnMouseDown") and type(this.self:GetScript("OnMouseDown")) == "function" then |
this.self:GetScript("OnMouseDown")(this.self, arg1, ...) |
this.clicked = true |
end |
end |
button_OnMouseDown = wrap(button_OnMouseDown, "button_OnMouseDown") |
local function button_OnDragStart(this, ...) |
local parent = this:GetParent() and this:GetParent().tablet |
if parent:GetScript("OnDragStart") then |
return parent:GetScript("OnDragStart")(parent, ...) |
end |
end |
button_OnDragStart = wrap(button_OnDragStart, "button_OnDragStart") |
local function button_OnDragStop(this, ...) |
local parent = this:GetParent() and this:GetParent().tablet |
if parent:GetScript("OnDragStop") then |
return parent:GetScript("OnDragStop")(parent, ...) |
end |
end |
button_OnDragStop = wrap(button_OnDragStop, "button_OnDragStop") |
local num_buttons = 0 |
local function NewLine(self) |
check.shown = false |
check:SetPoint("TOPLEFT", button, "TOPLEFT") |
col1:SetPoint("TOPLEFT", check, "TOPLEFT") |
local _,size = GameTooltipText:GetFont() |
local size = select(2,GameTooltipText:GetFont()) |
check:SetHeight(size * 1.5) |
check:SetWidth(size * 1.5) |
check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check") |
elseif c:find("^BOTTOM") then |
top = b:GetBottom() |
else |
_,top = b:GetCenter() |
top = select(2,b:GetCenter()) |
end |
if top then |
top = top + e |
elseif c:find("^BOTTOM") then |
bottom = b:GetBottom() |
else |
_,bottom = b:GetCenter() |
bottom = select(2,b:GetCenter()) |
end |
if bottom then |
bottom = bottom + e |
end |
end |
end |
RecalculateTabletHeight = wrap(RecalculateTabletHeight, "RecalculateTabletHeight") |
local function GetTooltipHeight(self) |
RecalculateTabletHeight(self) |
info.font = GameTooltipText |
end |
if not info.size then |
_,info.size = info.font:GetFont() |
info.size = select(2,info.font:GetFont()) |
end |
local catStart = false |
local columns = category and category.columns or 1 |
button.func = nil |
button.onEnterFunc = nil |
button.onLeaveFunc = nil |
button:SetFrameLevel(12) -- hack suggested on forum. Added 06/17/2007. (hC) |
if not self.locked or IsAltKeyDown() then |
local func = info.func |
if func then |
if not frame then |
frame = CreateFrame("Frame") |
frame:SetScript("OnEvent", function(this, _, modifier) |
if modifier == "ALT" then |
if modifier == "LALT" or modifier == "RALT" then |
this.func() |
end |
end) |
frame:RegisterEvent("MODIFIER_STATE_CHANGED") |
frame.func = func |
end |
StartCheckingAlt = wrap(StartCheckingAlt, "StartCheckingAlt") |
function StopCheckingAlt() |
if frame then |
frame:UnregisterEvent("MODIFIER_STATE_CHANGED") |
end |
end |
StopCheckingAlt = wrap(StopCheckingAlt, "StopCheckingAlt") |
end |
function AcquireDetachedFrame(self, registration, data, detachedData) |
detached.r = 0 |
detached.g = 0 |
detached.b = 0 |
detached:SetFrameStrata(registration.strata or "BACKGROUND") |
detached:SetFrameStrata(registration and registration.strata or "BACKGROUND") |
detached:SetBackdrop(tmp.a( |
'bgFile', "Interface\\Buttons\\WHITE8X8", |
'edgeFile', "Interface\\Tooltips\\UI-Tooltip-Border", |
local width = GetScreenWidth() |
local height = GetScreenHeight() |
if registration.movable == false then |
if registration and registration.movable == false then |
detached:RegisterForDrag() |
else |
detached:RegisterForDrag("LeftButton") |
detached:SetScript("OnDragStop", function(this) |
detached:StopMovingOrSizing() |
detached.moving = nil |
detached:SetClampedToScreen(1) |
detached:SetClampedToScreen(nil) |
local anchor |
local offsetx |
local offsety |
return |
end |
if detached.menu then |
detached.menu(level, value) |
if type(detached.menu) == "function" then |
detached.menu(level, value) |
else |
Dewdrop:FeedAceOptionsTable(detached.menu) |
end |
if level == 1 then |
Dewdrop:AddLine() |
end |
function detached:Lock() |
self:EnableMouse(self.locked) |
self.locked = not self.locked |
self.detachedData.locked = self.locked or nil |
if self.detachedData then |
self.detachedData.locked = self.locked or nil |
end |
self:children() |
end |
local detachedData = info.detachedData |
if detachedData and detachedData.detached then |
ReleaseDetachedFrame(self, data, detachedData) |
elseif tooltip.data == data then |
elseif tooltip and tooltip.data == data then |
tooltip:Hide() |
if tooltip.registration then |
tooltip.registration.tooltip = nil |
tooltip.registration = nil |
end |
end |
tooltip.enteredFrame = false |
if tooltip then tooltip.enteredFrame = false end |
end |
Tablet.Close = wrap(Tablet.Close, "Tablet:Close") |
local function frame_children(self) |
if not self.preventRefresh and self:GetParent() and self:GetParent():IsShown() then |
Tablet.currentFrame = self |
Tablet.currentTabletData = TabletData:new(self) |
Tablet.currentTabletData.minWidth = self.minWidth |
self:ClearLines() |
if self.runChildren then |
self.runChildren() |
end |
Tablet.currentTabletData:Display(Tablet.currentFrame) |
self:Show(Tablet.currentTabletData) |
Tablet.currentTabletData:del() |
Tablet.currentTabletData = nil |
Tablet.currentFrame = nil |
end |
end |
frame_children = wrap(frame_children, "frame_children") |
function Tablet:Open(fakeParent, parent) |
self:argCheck(fakeParent, 2, "table", "string") |
self:argCheck(parent, 3, "nil", "table", "string") |
frame.minWidth = info.minWidth |
if not frame.children or not frame.childrenVer or frame.childrenVer < MINOR_VERSION then |
frame.childrenVer = MINOR_VERSION |
function frame:children() |
if not self.preventRefresh and self:GetParent():IsShown() then |
Tablet.currentFrame = self |
Tablet.currentTabletData = TabletData:new(self) |
Tablet.currentTabletData.minWidth = self.minWidth |
self:ClearLines() |
if self.runChildren then |
self.runChildren() |
end |
Tablet.currentTabletData:Display(Tablet.currentFrame) |
self:Show(Tablet.currentTabletData) |
Tablet.currentTabletData:del() |
Tablet.currentTabletData = nil |
Tablet.currentFrame = nil |
end |
end |
frame.children = frame_children |
end |
frame:SetOwner(fakeParent) |
frame:children() |
end |
local offsetx = 0 |
local offsety = 0 |
frame:SetClampedToScreen(1) |
frame:SetClampedToScreen(nil) |
if frame:GetBottom() and frame:GetLeft() then |
if frame:GetRight() > GetScreenWidth() then |
offsetx = frame:GetRight() - GetScreenWidth() |
info = new(...) |
end |
self.registry[parent] = info |
info.data = info.data or info.detachedData or {} |
info.data = info.data or info.detachedData or new() |
info.detachedData = info.detachedData or info.data |
local data = info.data |
local detachedData = info.detachedData |
end |
_id = 0 |
end |
CleanCategoryPool = wrap(CleanCategoryPool, "CleanCategoryPool") |
function Tablet:AddCategory(...) |
if not self.currentFrame then |
function Tablet:GetNormalFontSize() |
return normalSize |
end |
Tablet.GetNormalFontSize = wrap(Tablet.GetNormalFontSize, "Tablet:GetNormalFontSize") |
function Tablet:GetHeaderFontSize() |
return headerSize |
end |
Tablet.GetHeaderFontSize = wrap(Tablet.GetHeaderFontSize, "Tablet:GetHeaderFontSize") |
function Tablet:GetNormalFontObject() |
return GameTooltipText |
end |
Tablet.GetNormalFontObject = wrap(Tablet.GetNormalFontObject, "Tablet:GetNormalFontObject") |
function Tablet:GetHeaderFontObject() |
return GameTooltipHeaderText |
end |
Tablet.GetHeaderFontObject = wrap(Tablet.GetHeaderFontObject, "Tablet:GetHeaderFontObject") |
function Tablet:SetFontSizePercent(parent, percent) |
self:argCheck(parent, 2, "table", "string") |
if not info.detachedData then |
self:error("You cannot detach tablet without a data field.") |
end |
if info.tooltip and info.tooltip == tooltip then |
if info.tooltip and info.tooltip == tooltip and tooltip.registration then |
tooltip:Detach() |
else |
info.detachedData.detached = true |
detached.minWidth = info.minWidth |
if not detached.children or not detached.childrenVer or detached.childrenVer < MINOR_VERSION then |
detached.childrenVer = MINOR_VERSION |
function detached:children() |
if not self.preventRefresh then |
Tablet.currentFrame = self |
Tablet.currentTabletData = TabletData:new(self) |
Tablet.currentTabletData.minWidth = self.minWidth |
self:ClearLines() |
if self.runChildren then |
self.runChildren() |
end |
Tablet.currentTabletData:Display(Tablet.currentFrame) |
self:Show(Tablet.currentTabletData) |
Tablet.currentTabletData:del() |
Tablet.currentTabletData = nil |
Tablet.currentFrame = nil |
end |
end |
detached.children = frame_children |
end |
detached:SetOwner(parent) |
detached:children() |
SLASH_TABLET1 = "/tablet" |
SLASH_TABLET2 = "/tabletlib" |
SlashCmdList["TABLET"] = function(msg) |
TabletLib:GetInstance(MAJOR_VERSION):ListProfileInfo() |
AceLibrary(MAJOR_VERSION):ListProfileInfo() |
end |
end |