1 --[[-----------------------------------------------------------------------------
3 -------------------------------------------------------------------------------]]
4 local Type, Version = "EditBox", 24
5 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
6 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
9 local tostring, pairs = tostring, pairs
12 local PlaySound = PlaySound
13 local GetCursorInfo, ClearCursor, GetSpellInfo = GetCursorInfo, ClearCursor, GetSpellInfo
14 local CreateFrame, UIParent = CreateFrame, UIParent
17 -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
18 -- List them here for Mikk's FindGlobals script
19 -- GLOBALS: AceGUIEditBoxInsertLink, ChatFontNormal, OKAY
21 --[[-----------------------------------------------------------------------------
23 -------------------------------------------------------------------------------]]
24 if not AceGUIEditBoxInsertLink then
26 hooksecurefunc("ChatEdit_InsertLink", function(...) return _G.AceGUIEditBoxInsertLink(...) end)
29 function _G.AceGUIEditBoxInsertLink(text)
30 for i = 1, AceGUI:GetWidgetCount(Type) do
31 local editbox = _G["AceGUI-3.0EditBox"..i]
32 if editbox and editbox:IsVisible() and editbox:HasFocus() then
39 local function ShowButton(self)
40 if not self.disablebutton then
42 self.editbox:SetTextInsets(0, 20, 3, 3)
46 local function HideButton(self)
48 self.editbox:SetTextInsets(0, 0, 3, 3)
51 --[[-----------------------------------------------------------------------------
53 -------------------------------------------------------------------------------]]
54 local function Control_OnEnter(frame)
55 frame.obj:Fire("OnEnter")
58 local function Control_OnLeave(frame)
59 frame.obj:Fire("OnLeave")
62 local function Frame_OnShowFocus(frame)
63 frame.obj.editbox:SetFocus()
64 frame:SetScript("OnShow", nil)
67 local function EditBox_OnEscapePressed(frame)
71 local function EditBox_OnEnterPressed(frame)
72 local self = frame.obj
73 local value = frame:GetText()
74 local cancel = self:Fire("OnEnterPressed", value)
76 PlaySound("igMainMenuOptionCheckBoxOn")
81 local function EditBox_OnReceiveDrag(frame)
82 local self = frame.obj
83 local type, id, info = GetCursorInfo()
84 if type == "item" then
86 self:Fire("OnEnterPressed", info)
88 elseif type == "spell" then
89 local name = GetSpellInfo(id, info)
91 self:Fire("OnEnterPressed", name)
98 local function EditBox_OnTextChanged(frame)
99 local self = frame.obj
100 local value = frame:GetText()
101 if tostring(value) ~= tostring(self.lasttext) then
102 self:Fire("OnTextChanged", value)
103 self.lasttext = value
108 local function EditBox_OnFocusGained(frame)
109 AceGUI:SetFocus(frame.obj)
112 local function Button_OnClick(frame)
113 local editbox = frame.obj.editbox
115 EditBox_OnEnterPressed(editbox)
118 --[[-----------------------------------------------------------------------------
120 -------------------------------------------------------------------------------]]
122 ["OnAcquire"] = function(self)
123 -- height is controlled by SetLabel
125 self:SetDisabled(false)
128 self:DisableButton(false)
129 self:SetMaxLetters(0)
132 ["OnRelease"] = function(self)
136 ["SetDisabled"] = function(self, disabled)
137 self.disabled = disabled
139 self.editbox:EnableMouse(false)
140 self.editbox:ClearFocus()
141 self.editbox:SetTextColor(0.5,0.5,0.5)
142 self.label:SetTextColor(0.5,0.5,0.5)
144 self.editbox:EnableMouse(true)
145 self.editbox:SetTextColor(1,1,1)
146 self.label:SetTextColor(1,.82,0)
150 ["SetText"] = function(self, text)
151 self.lasttext = text or ""
152 self.editbox:SetText(text or "")
153 self.editbox:SetCursorPosition(0)
157 ["GetText"] = function(self, text)
158 return self.editbox:GetText()
161 ["SetLabel"] = function(self, text)
162 if text and text ~= "" then
163 self.label:SetText(text)
165 self.editbox:SetPoint("TOPLEFT",self.frame,"TOPLEFT",7,-18)
167 self.alignoffset = 30
169 self.label:SetText("")
171 self.editbox:SetPoint("TOPLEFT",self.frame,"TOPLEFT",7,0)
173 self.alignoffset = 12
177 ["DisableButton"] = function(self, disabled)
178 self.disablebutton = disabled
184 ["SetMaxLetters"] = function (self, num)
185 self.editbox:SetMaxLetters(num or 0)
188 ["ClearFocus"] = function(self)
189 self.editbox:ClearFocus()
190 self.frame:SetScript("OnShow", nil)
193 ["SetFocus"] = function(self)
194 self.editbox:SetFocus()
195 if not self.frame:IsShown() then
196 self.frame:SetScript("OnShow", Frame_OnShowFocus)
201 --[[-----------------------------------------------------------------------------
203 -------------------------------------------------------------------------------]]
204 local function Constructor()
205 local num = AceGUI:GetNextWidgetNum(Type)
206 local frame = CreateFrame("Frame", nil, UIParent)
209 local editbox = CreateFrame("EditBox", "AceGUI-3.0EditBox"..num, frame, "InputBoxTemplate")
210 editbox:SetAutoFocus(false)
211 editbox:SetFontObject(ChatFontNormal)
212 editbox:SetScript("OnEnter", Control_OnEnter)
213 editbox:SetScript("OnLeave", Control_OnLeave)
214 editbox:SetScript("OnEscapePressed", EditBox_OnEscapePressed)
215 editbox:SetScript("OnEnterPressed", EditBox_OnEnterPressed)
216 editbox:SetScript("OnTextChanged", EditBox_OnTextChanged)
217 editbox:SetScript("OnReceiveDrag", EditBox_OnReceiveDrag)
218 editbox:SetScript("OnMouseDown", EditBox_OnReceiveDrag)
219 editbox:SetScript("OnEditFocusGained", EditBox_OnFocusGained)
220 editbox:SetTextInsets(0, 0, 3, 3)
221 editbox:SetMaxLetters(256)
222 editbox:SetPoint("BOTTOMLEFT", 6, 0)
223 editbox:SetPoint("BOTTOMRIGHT")
224 editbox:SetHeight(19)
226 local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
227 label:SetPoint("TOPLEFT", 0, -2)
228 label:SetPoint("TOPRIGHT", 0, -2)
229 label:SetJustifyH("LEFT")
232 local button = CreateFrame("Button", nil, editbox, "UIPanelButtonTemplate")
235 button:SetPoint("RIGHT", -2, 0)
237 button:SetScript("OnClick", Button_OnClick)
248 for method, func in pairs(methods) do
249 widget[method] = func
251 editbox.obj, button.obj = widget, widget
253 return AceGUI:RegisterAsWidget(widget)
256 AceGUI:RegisterWidgetType(Type, Constructor, Version)