local p,K="\069\100\105\116\066\111\120",29 local a=LibStub and LibStub("\065\099\101\071\085\073-\051\046\048",true)if not a or(a:GetWidgetVersion(p)or 0)>=K then return end local w,R=tostring,pairs local H=PlaySound local C,c=GetCursorInfo,ClearCursor local f,U=CreateFrame,UIParent local W=_G if not AceGUIEditBoxInsertLink then hooksecurefunc("\067\104\097\116\069\100\105\116\095\073\110\115\101\114\116\076\105\110\107",function(...)return W.AceGUIEditBoxInsertLink(...)end)end function W.AceGUIEditBoxInsertLink(K)for p=1,a:GetWidgetCount(p),1 do local a=W["\065\099\101\071\085\073-\051\046\048\069\100\105\116\066\111\120"..p]if a and(a:IsVisible()and a:HasFocus())then a:Insert(K)return true end end end local function G(p)if not p.disablebutton then p.button:Show()p.editbox:SetTextInsets(0,20,3,3)end end local function M(p)p.button:Hide()p.editbox:SetTextInsets(0,0,3,3)end local function b(p)p.obj:Fire("\079\110\069\110\116\101\114")end local function k(p)p.obj:Fire("\079\110\076\101\097\118\101")end local function e(p)p.obj.editbox:SetFocus()p:SetScript("\079\110\083\104\111\119",nil)end local function D(p)a:ClearFocus()end local function h(p)local K=p.obj local a=p:GetText()local w=K:Fire("\079\110\069\110\116\101\114\080\114\101\115\115\101\100",a)if not w then H(856)M(K)end end local function F(p)local K=p.obj local w,R,H,f=C()local U if w=="\105\116\101\109"then U=H elseif w=="\115\112\101\108\108"then if C_Spell and C_Spell.GetSpellName then U=C_Spell.GetSpellName(f)else U=GetSpellInfo(R,H)end elseif w=="\109\097\099\114\111"then U=GetMacroInfo(R)end if U then K:SetText(U)K:Fire("\079\110\069\110\116\101\114\080\114\101\115\115\101\100",U)c()M(K)a:ClearFocus()end end local function I(p)local K=p.obj local a=p:GetText()if w(a)~=w(K.lasttext)then K:Fire("\079\110\084\101\120\116\067\104\097\110\103\101\100",a)K.lasttext=a G(K)end end local function u(p)a:SetFocus(p.obj)end local function z(p)local K=p.obj.editbox K:ClearFocus()h(K)end local N={OnAcquire=function(p)p:SetWidth(200)p:SetDisabled(false)p:SetLabel()p:SetText()p:DisableButton(false)p:SetMaxLetters(0)end,OnRelease=function(p)p:ClearFocus()end,SetDisabled=function(p,K)p.disabled=K if K then p.editbox:EnableMouse(false)p.editbox:ClearFocus()p.editbox:SetTextColor(.5,.5,.5)p.label:SetTextColor(.5,.5,.5)else p.editbox:EnableMouse(true)p.editbox:SetTextColor(1,1,1)p.label:SetTextColor(1,.82,0)end end,SetText=function(p,K)p.lasttext=K or""p.editbox:SetText(K or"")p.editbox:SetCursorPosition(0)M(p)end,GetText=function(p,K)return p.editbox:GetText()end;SetLabel=function(p,K)if K and K~=""then p.label:SetText(K)p.label:Show()p.editbox:SetPoint("\084\079\080\076\069\070\084",p.frame,"\084\079\080\076\069\070\084",7,-18)p:SetHeight(44)p.alignoffset=30 else p.label:SetText("")p.label:Hide()p.editbox:SetPoint("\084\079\080\076\069\070\084",p.frame,"\084\079\080\076\069\070\084",7,0)p:SetHeight(26)p.alignoffset=12 end end;DisableButton=function(p,K)p.disablebutton=K if K then M(p)end end;SetMaxLetters=function(p,K)p.editbox:SetMaxLetters(K or 0)end;ClearFocus=function(p)p.editbox:ClearFocus()p.frame:SetScript("\079\110\083\104\111\119",nil)end,SetFocus=function(p)p.editbox:SetFocus()if not p.frame:IsShown()then p.frame:SetScript("\079\110\083\104\111\119",e)end end,HighlightText=function(p,K,a)p.editbox:HighlightText(K,a)end}local function d()local K=a:GetNextWidgetNum(p)local w=f("\070\114\097\109\101",nil,U)w:Hide()local H=f("\069\100\105\116\066\111\120","\065\099\101\071\085\073-\051\046\048\069\100\105\116\066\111\120"..K,w,"\073\110\112\117\116\066\111\120\084\101\109\112\108\097\116\101")H:SetAutoFocus(false)H:SetFontObject(ChatFontNormal)H:SetScript("\079\110\069\110\116\101\114",b)H:SetScript("\079\110\076\101\097\118\101",k)H:SetScript("\079\110\069\115\099\097\112\101\080\114\101\115\115\101\100",D)H:SetScript("\079\110\069\110\116\101\114\080\114\101\115\115\101\100",h)H:SetScript("\079\110\084\101\120\116\067\104\097\110\103\101\100",I)H:SetScript("\079\110\082\101\099\101\105\118\101\068\114\097\103",F)H:SetScript("\079\110\077\111\117\115\101\068\111\119\110",F)H:SetScript("\079\110\069\100\105\116\070\111\099\117\115\071\097\105\110\101\100",u)H:SetTextInsets(0,0,3,3)H:SetMaxLetters(256)H:SetPoint("\066\079\084\084\079\077\076\069\070\084",6,0)H:SetPoint("\066\079\084\084\079\077\082\073\071\072\084")H:SetHeight(19)local C=w:CreateFontString(nil,"\079\086\069\082\076\065\089","\071\097\109\101\070\111\110\116\078\111\114\109\097\108\083\109\097\108\108")C:SetPoint("\084\079\080\076\069\070\084",0,-2)C:SetPoint("\084\079\080\082\073\071\072\084",0,-2)C:SetJustifyH("\076\069\070\084")C:SetHeight(18)local c=f("\066\117\116\116\111\110",nil,H,"\085\073\080\097\110\101\108\066\117\116\116\111\110\084\101\109\112\108\097\116\101")c:SetWidth(40)c:SetHeight(20)c:SetPoint("\082\073\071\072\084",-2,0)c:SetText(OKAY)c:SetScript("\079\110\067\108\105\099\107",z)c:Hide()local W={alignoffset=30;editbox=H,label=C,button=c,frame=w,type=p}for p,K in R(N)do W[p]=K end H.obj,c.obj=W,W return a:RegisterAsWidget(W)end a:RegisterWidgetType(p,d,K)
--[[-----------------------------------------------------------------------------
EditBox Widget
-------------------------------------------------------------------------------]]
local Type, Version = "EditBox", 29
local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end

-- Lua APIs
local tostring, pairs = tostring, pairs

-- WoW APIs
local PlaySound = PlaySound
local GetCursorInfo, ClearCursor = GetCursorInfo, ClearCursor
local CreateFrame, UIParent = CreateFrame, UIParent
local _G = _G

--[[-----------------------------------------------------------------------------
Support functions
-------------------------------------------------------------------------------]]
if not AceGUIEditBoxInsertLink then
	-- upgradeable hook
	hooksecurefunc("ChatEdit_InsertLink", function(...) return _G.AceGUIEditBoxInsertLink(...) end)
end

function _G.AceGUIEditBoxInsertLink(text)
	for i = 1, AceGUI:GetWidgetCount(Type) do
		local editbox = _G["AceGUI-3.0EditBox"..i]
		if editbox and editbox:IsVisible() and editbox:HasFocus() then
			editbox:Insert(text)
			return true
		end
	end
end

local function ShowButton(self)
	if not self.disablebutton then
		self.button:Show()
		self.editbox:SetTextInsets(0, 20, 3, 3)
	end
end

local function HideButton(self)
	self.button:Hide()
	self.editbox:SetTextInsets(0, 0, 3, 3)
end

--[[-----------------------------------------------------------------------------
Scripts
-------------------------------------------------------------------------------]]
local function Control_OnEnter(frame)
	frame.obj:Fire("OnEnter")
end

local function Control_OnLeave(frame)
	frame.obj:Fire("OnLeave")
end

local function Frame_OnShowFocus(frame)
	frame.obj.editbox:SetFocus()
	frame:SetScript("OnShow", nil)
end

local function EditBox_OnEscapePressed(frame)
	AceGUI:ClearFocus()
end

local function EditBox_OnEnterPressed(frame)
	local self = frame.obj
	local value = frame:GetText()
	local cancel = self:Fire("OnEnterPressed", value)
	if not cancel then
		PlaySound(856) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON
		HideButton(self)
	end
end

local function EditBox_OnReceiveDrag(frame)
	local self = frame.obj
	local type, id, info, extra = GetCursorInfo()
	local name
	if type == "item" then
		name = info
	elseif type == "spell" then
		if C_Spell and C_Spell.GetSpellName then
			name = C_Spell.GetSpellName(extra)
		else
			name = GetSpellInfo(id, info)
		end
	elseif type == "macro" then
		name = GetMacroInfo(id)
	end
	if name then
		self:SetText(name)
		self:Fire("OnEnterPressed", name)
		ClearCursor()
		HideButton(self)
		AceGUI:ClearFocus()
	end
end

local function EditBox_OnTextChanged(frame)
	local self = frame.obj
	local value = frame:GetText()
	if tostring(value) ~= tostring(self.lasttext) then
		self:Fire("OnTextChanged", value)
		self.lasttext = value
		ShowButton(self)
	end
end

local function EditBox_OnFocusGained(frame)
	AceGUI:SetFocus(frame.obj)
end

local function Button_OnClick(frame)
	local editbox = frame.obj.editbox
	editbox:ClearFocus()
	EditBox_OnEnterPressed(editbox)
end

--[[-----------------------------------------------------------------------------
Methods
-------------------------------------------------------------------------------]]
local methods = {
	["OnAcquire"] = function(self)
		-- height is controlled by SetLabel
		self:SetWidth(200)
		self:SetDisabled(false)
		self:SetLabel()
		self:SetText()
		self:DisableButton(false)
		self:SetMaxLetters(0)
	end,

	["OnRelease"] = function(self)
		self:ClearFocus()
	end,

	["SetDisabled"] = function(self, disabled)
		self.disabled = disabled
		if disabled then
			self.editbox:EnableMouse(false)
			self.editbox:ClearFocus()
			self.editbox:SetTextColor(0.5,0.5,0.5)
			self.label:SetTextColor(0.5,0.5,0.5)
		else
			self.editbox:EnableMouse(true)
			self.editbox:SetTextColor(1,1,1)
			self.label:SetTextColor(1,.82,0)
		end
	end,

	["SetText"] = function(self, text)
		self.lasttext = text or ""
		self.editbox:SetText(text or "")
		self.editbox:SetCursorPosition(0)
		HideButton(self)
	end,

	["GetText"] = function(self, text)
		return self.editbox:GetText()
	end,

	["SetLabel"] = function(self, text)
		if text and text ~= "" then
			self.label:SetText(text)
			self.label:Show()
			self.editbox:SetPoint("TOPLEFT",self.frame,"TOPLEFT",7,-18)
			self:SetHeight(44)
			self.alignoffset = 30
		else
			self.label:SetText("")
			self.label:Hide()
			self.editbox:SetPoint("TOPLEFT",self.frame,"TOPLEFT",7,0)
			self:SetHeight(26)
			self.alignoffset = 12
		end
	end,

	["DisableButton"] = function(self, disabled)
		self.disablebutton = disabled
		if disabled then
			HideButton(self)
		end
	end,

	["SetMaxLetters"] = function (self, num)
		self.editbox:SetMaxLetters(num or 0)
	end,

	["ClearFocus"] = function(self)
		self.editbox:ClearFocus()
		self.frame:SetScript("OnShow", nil)
	end,

	["SetFocus"] = function(self)
		self.editbox:SetFocus()
		if not self.frame:IsShown() then
			self.frame:SetScript("OnShow", Frame_OnShowFocus)
		end
	end,

	["HighlightText"] = function(self, from, to)
		self.editbox:HighlightText(from, to)
	end
}

--[[-----------------------------------------------------------------------------
Constructor
-------------------------------------------------------------------------------]]
local function Constructor()
	local num  = AceGUI:GetNextWidgetNum(Type)
	local frame = CreateFrame("Frame", nil, UIParent)
	frame:Hide()

	local editbox = CreateFrame("EditBox", "AceGUI-3.0EditBox"..num, frame, "InputBoxTemplate")
	editbox:SetAutoFocus(false)
	editbox:SetFontObject(ChatFontNormal)
	editbox:SetScript("OnEnter", Control_OnEnter)
	editbox:SetScript("OnLeave", Control_OnLeave)
	editbox:SetScript("OnEscapePressed", EditBox_OnEscapePressed)
	editbox:SetScript("OnEnterPressed", EditBox_OnEnterPressed)
	editbox:SetScript("OnTextChanged", EditBox_OnTextChanged)
	editbox:SetScript("OnReceiveDrag", EditBox_OnReceiveDrag)
	editbox:SetScript("OnMouseDown", EditBox_OnReceiveDrag)
	editbox:SetScript("OnEditFocusGained", EditBox_OnFocusGained)
	editbox:SetTextInsets(0, 0, 3, 3)
	editbox:SetMaxLetters(256)
	editbox:SetPoint("BOTTOMLEFT", 6, 0)
	editbox:SetPoint("BOTTOMRIGHT")
	editbox:SetHeight(19)

	local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
	label:SetPoint("TOPLEFT", 0, -2)
	label:SetPoint("TOPRIGHT", 0, -2)
	label:SetJustifyH("LEFT")
	label:SetHeight(18)

	local button = CreateFrame("Button", nil, editbox, "UIPanelButtonTemplate")
	button:SetWidth(40)
	button:SetHeight(20)
	button:SetPoint("RIGHT", -2, 0)
	button:SetText(OKAY)
	button:SetScript("OnClick", Button_OnClick)
	button:Hide()

	local widget = {
		alignoffset = 30,
		editbox     = editbox,
		label       = label,
		button      = button,
		frame       = frame,
		type        = Type
	}
	for method, func in pairs(methods) do
		widget[method] = func
	end
	editbox.obj, button.obj = widget, widget

	return AceGUI:RegisterAsWidget(widget)
end

AceGUI:RegisterWidgetType(Type, Constructor, Version)
