1 --[[-----------------------------------------------------------------------------
3 -------------------------------------------------------------------------------]]
4 local Type, Version = "EditBox", 27
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(PlaySoundKitID and "igMainMenuOptionCheckBoxOn" or 856) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON
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)
93 elseif type == "macro" then
94 local name = GetMacroInfo(id)
96 self:Fire("OnEnterPressed", name)
103 local function EditBox_OnTextChanged(frame)
104 local self = frame.obj
105 local value = frame:GetText()
106 if tostring(value) ~= tostring(self.lasttext) then
107 self:Fire("OnTextChanged", value)
108 self.lasttext = value
113 local function EditBox_OnFocusGained(frame)
114 AceGUI:SetFocus(frame.obj)
117 local function Button_OnClick(frame)
118 local editbox = frame.obj.editbox
120 EditBox_OnEnterPressed(editbox)
123 --[[-----------------------------------------------------------------------------
125 -------------------------------------------------------------------------------]]
127 ["OnAcquire"] = function(self)
128 -- height is controlled by SetLabel
130 self:SetDisabled(false)
133 self:DisableButton(false)
134 self:SetMaxLetters(0)
137 ["OnRelease"] = function(self)
141 ["SetDisabled"] = function(self, disabled)
142 self.disabled = disabled
144 self.editbox:EnableMouse(false)
145 self.editbox:ClearFocus()
146 self.editbox:SetTextColor(0.5,0.5,0.5)
147 self.label:SetTextColor(0.5,0.5,0.5)
149 self.editbox:EnableMouse(true)
150 self.editbox:SetTextColor(1,1,1)
151 self.label:SetTextColor(1,.82,0)
155 ["SetText"] = function(self, text)
156 self.lasttext = text or ""
157 self.editbox:SetText(text or "")
158 self.editbox:SetCursorPosition(0)
162 ["GetText"] = function(self, text)
163 return self.editbox:GetText()
166 ["SetLabel"] = function(self, text)
167 if text and text ~= "" then
168 self.label:SetText(text)
170 self.editbox:SetPoint("TOPLEFT",self.frame,"TOPLEFT",7,-18)
172 self.alignoffset = 30
174 self.label:SetText("")
176 self.editbox:SetPoint("TOPLEFT",self.frame,"TOPLEFT",7,0)
178 self.alignoffset = 12
182 ["DisableButton"] = function(self, disabled)
183 self.disablebutton = disabled
189 ["SetMaxLetters"] = function (self, num)
190 self.editbox:SetMaxLetters(num or 0)
193 ["ClearFocus"] = function(self)
194 self.editbox:ClearFocus()
195 self.frame:SetScript("OnShow", nil)
198 ["SetFocus"] = function(self)
199 self.editbox:SetFocus()
200 if not self.frame:IsShown() then
201 self.frame:SetScript("OnShow", Frame_OnShowFocus)
205 ["HighlightText"] = function(self, from, to)
206 self.editbox:HighlightText(from, to)
210 --[[-----------------------------------------------------------------------------
212 -------------------------------------------------------------------------------]]
213 local function Constructor()
214 local num = AceGUI:GetNextWidgetNum(Type)
215 local frame = CreateFrame("Frame", nil, UIParent)
218 local editbox = CreateFrame("EditBox", "AceGUI-3.0EditBox"..num, frame, "InputBoxTemplate")
219 editbox:SetAutoFocus(false)
220 editbox:SetFontObject(ChatFontNormal)
221 editbox:SetScript("OnEnter", Control_OnEnter)
222 editbox:SetScript("OnLeave", Control_OnLeave)
223 editbox:SetScript("OnEscapePressed", EditBox_OnEscapePressed)
224 editbox:SetScript("OnEnterPressed", EditBox_OnEnterPressed)
225 editbox:SetScript("OnTextChanged", EditBox_OnTextChanged)
226 editbox:SetScript("OnReceiveDrag", EditBox_OnReceiveDrag)
227 editbox:SetScript("OnMouseDown", EditBox_OnReceiveDrag)
228 editbox:SetScript("OnEditFocusGained", EditBox_OnFocusGained)
229 editbox:SetTextInsets(0, 0, 3, 3)
230 editbox:SetMaxLetters(256)
231 editbox:SetPoint("BOTTOMLEFT", 6, 0)
232 editbox:SetPoint("BOTTOMRIGHT")
233 editbox:SetHeight(19)
235 local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
236 label:SetPoint("TOPLEFT", 0, -2)
237 label:SetPoint("TOPRIGHT", 0, -2)
238 label:SetJustifyH("LEFT")
241 local button = CreateFrame("Button", nil, editbox, "UIPanelButtonTemplate")
244 button:SetPoint("RIGHT", -2, 0)
246 button:SetScript("OnClick", Button_OnClick)
257 for method, func in pairs(methods) do
258 widget[method] = func
260 editbox.obj, button.obj = widget, widget
262 return AceGUI:RegisterAsWidget(widget)
265 AceGUI:RegisterWidgetType(Type, Constructor, Version)