1 local Type, Version = "MultiLineEditBox", 28
2 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
3 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
9 local GetCursorInfo, GetSpellInfo, ClearCursor = GetCursorInfo, GetSpellInfo, ClearCursor
10 local CreateFrame, UIParent = CreateFrame, UIParent
13 -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
14 -- List them here for Mikk's FindGlobals script
15 -- GLOBALS: ACCEPT, ChatFontNormal
17 --[[-----------------------------------------------------------------------------
19 -------------------------------------------------------------------------------]]
21 if not AceGUIMultiLineEditBoxInsertLink then
23 hooksecurefunc("ChatEdit_InsertLink", function(...) return _G.AceGUIMultiLineEditBoxInsertLink(...) end)
26 function _G.AceGUIMultiLineEditBoxInsertLink(text)
27 for i = 1, AceGUI:GetWidgetCount(Type) do
28 local editbox = _G[("MultiLineEditBox%uEdit"):format(i)]
29 if editbox and editbox:IsVisible() and editbox:HasFocus() then
37 local function Layout(self)
38 self:SetHeight(self.numlines * 14 + (self.disablebutton and 19 or 41) + self.labelHeight)
40 if self.labelHeight == 0 then
41 self.scrollBar:SetPoint("TOP", self.frame, "TOP", 0, -23)
43 self.scrollBar:SetPoint("TOP", self.label, "BOTTOM", 0, -19)
46 if self.disablebutton then
47 self.scrollBar:SetPoint("BOTTOM", self.frame, "BOTTOM", 0, 21)
48 self.scrollBG:SetPoint("BOTTOMLEFT", 0, 4)
50 self.scrollBar:SetPoint("BOTTOM", self.button, "TOP", 0, 18)
51 self.scrollBG:SetPoint("BOTTOMLEFT", self.button, "TOPLEFT")
55 --[[-----------------------------------------------------------------------------
57 -------------------------------------------------------------------------------]]
58 local function OnClick(self) -- Button
60 self.editBox:ClearFocus()
61 if not self:Fire("OnEnterPressed", self.editBox:GetText()) then
66 local function OnCursorChanged(self, _, y, _, cursorHeight) -- EditBox
67 self, y = self.obj.scrollFrame, -y
68 local offset = self:GetVerticalScroll()
70 self:SetVerticalScroll(y)
72 y = y + cursorHeight - self:GetHeight()
74 self:SetVerticalScroll(y)
79 local function OnEditFocusLost(self) -- EditBox
80 self:HighlightText(0, 0)
81 self.obj:Fire("OnEditFocusLost")
84 local function OnEnter(self) -- EditBox / ScrollFrame
86 if not self.entered then
92 local function OnLeave(self) -- EditBox / ScrollFrame
100 local function OnMouseUp(self) -- ScrollFrame
101 self = self.obj.editBox
103 self:SetCursorPosition(self:GetNumLetters())
106 local function OnReceiveDrag(self) -- EditBox / ScrollFrame
107 local type, id, info = GetCursorInfo()
108 if type == "spell" then
109 info = GetSpellInfo(id, info)
110 elseif type ~= "item" then
115 local editBox = self.editBox
116 if not editBox:HasFocus() then
118 editBox:SetCursorPosition(editBox:GetNumLetters())
124 local function OnSizeChanged(self, width, height) -- ScrollFrame
125 self.obj.editBox:SetWidth(width)
128 local function OnTextChanged(self, userInput) -- EditBox
131 self:Fire("OnTextChanged", self.editBox:GetText())
136 local function OnTextSet(self) -- EditBox
137 self:HighlightText(0, 0)
138 self:SetCursorPosition(self:GetNumLetters())
139 self:SetCursorPosition(0)
140 self.obj.button:Disable()
143 local function OnVerticalScroll(self, offset) -- ScrollFrame
144 local editBox = self.obj.editBox
145 editBox:SetHitRectInsets(0, 0, offset, editBox:GetHeight() - offset - self:GetHeight())
148 local function OnShowFocus(frame)
149 frame.obj.editBox:SetFocus()
150 frame:SetScript("OnShow", nil)
153 local function OnEditFocusGained(frame)
154 AceGUI:SetFocus(frame.obj)
155 frame.obj:Fire("OnEditFocusGained")
158 --[[-----------------------------------------------------------------------------
160 -------------------------------------------------------------------------------]]
162 ["OnAcquire"] = function(self)
163 self.editBox:SetText("")
164 self:SetDisabled(false)
166 self:DisableButton(false)
169 self:SetMaxLetters(0)
172 ["OnRelease"] = function(self)
176 ["SetDisabled"] = function(self, disabled)
177 local editBox = self.editBox
180 editBox:EnableMouse(false)
181 editBox:SetTextColor(0.5, 0.5, 0.5)
182 self.label:SetTextColor(0.5, 0.5, 0.5)
183 self.scrollFrame:EnableMouse(false)
184 self.button:Disable()
186 editBox:EnableMouse(true)
187 editBox:SetTextColor(1, 1, 1)
188 self.label:SetTextColor(1, 0.82, 0)
189 self.scrollFrame:EnableMouse(true)
193 ["SetLabel"] = function(self, text)
194 if text and text ~= "" then
195 self.label:SetText(text)
196 if self.labelHeight ~= 10 then
197 self.labelHeight = 10
200 elseif self.labelHeight ~= 0 then
207 ["SetNumLines"] = function(self, value)
208 if not value or value < 4 then
211 self.numlines = value
215 ["SetText"] = function(self, text)
216 self.editBox:SetText(text)
219 ["GetText"] = function(self)
220 return self.editBox:GetText()
223 ["SetMaxLetters"] = function (self, num)
224 self.editBox:SetMaxLetters(num or 0)
227 ["DisableButton"] = function(self, disabled)
228 self.disablebutton = disabled
237 ["ClearFocus"] = function(self)
238 self.editBox:ClearFocus()
239 self.frame:SetScript("OnShow", nil)
242 ["SetFocus"] = function(self)
243 self.editBox:SetFocus()
244 if not self.frame:IsShown() then
245 self.frame:SetScript("OnShow", OnShowFocus)
249 ["HighlightText"] = function(self, from, to)
250 self.editBox:HighlightText(from, to)
253 ["GetCursorPosition"] = function(self)
254 return self.editBox:GetCursorPosition()
257 ["SetCursorPosition"] = function(self, ...)
258 return self.editBox:SetCursorPosition(...)
264 --[[-----------------------------------------------------------------------------
266 -------------------------------------------------------------------------------]]
268 bgFile = [[Interface\Tooltips\UI-Tooltip-Background]],
269 edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]], edgeSize = 16,
270 insets = { left = 4, right = 3, top = 4, bottom = 3 }
273 local function Constructor()
274 local frame = CreateFrame("Frame", nil, UIParent)
277 local widgetNum = AceGUI:GetNextWidgetNum(Type)
279 local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
280 label:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, -4)
281 label:SetPoint("TOPRIGHT", frame, "TOPRIGHT", 0, -4)
282 label:SetJustifyH("LEFT")
283 label:SetText(ACCEPT)
286 local button = CreateFrame("Button", ("%s%dButton"):format(Type, widgetNum), frame, "UIPanelButtonTemplate")
287 button:SetPoint("BOTTOMLEFT", 0, 4)
289 button:SetWidth(label:GetStringWidth() + 24)
290 button:SetText(ACCEPT)
291 button:SetScript("OnClick", OnClick)
294 local text = button:GetFontString()
295 text:ClearAllPoints()
296 text:SetPoint("TOPLEFT", button, "TOPLEFT", 5, -5)
297 text:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", -5, 1)
298 text:SetJustifyV("MIDDLE")
300 local scrollBG = CreateFrame("Frame", nil, frame)
301 scrollBG:SetBackdrop(backdrop)
302 scrollBG:SetBackdropColor(0, 0, 0)
303 scrollBG:SetBackdropBorderColor(0.4, 0.4, 0.4)
305 local scrollFrame = CreateFrame("ScrollFrame", ("%s%dScrollFrame"):format(Type, widgetNum), frame, "UIPanelScrollFrameTemplate")
307 local scrollBar = _G[scrollFrame:GetName() .. "ScrollBar"]
308 scrollBar:ClearAllPoints()
309 scrollBar:SetPoint("TOP", label, "BOTTOM", 0, -19)
310 scrollBar:SetPoint("BOTTOM", button, "TOP", 0, 18)
311 scrollBar:SetPoint("RIGHT", frame, "RIGHT")
313 scrollBG:SetPoint("TOPRIGHT", scrollBar, "TOPLEFT", 0, 19)
314 scrollBG:SetPoint("BOTTOMLEFT", button, "TOPLEFT")
316 scrollFrame:SetPoint("TOPLEFT", scrollBG, "TOPLEFT", 5, -6)
317 scrollFrame:SetPoint("BOTTOMRIGHT", scrollBG, "BOTTOMRIGHT", -4, 4)
318 scrollFrame:SetScript("OnEnter", OnEnter)
319 scrollFrame:SetScript("OnLeave", OnLeave)
320 scrollFrame:SetScript("OnMouseUp", OnMouseUp)
321 scrollFrame:SetScript("OnReceiveDrag", OnReceiveDrag)
322 scrollFrame:SetScript("OnSizeChanged", OnSizeChanged)
323 scrollFrame:HookScript("OnVerticalScroll", OnVerticalScroll)
325 local editBox = CreateFrame("EditBox", ("%s%dEdit"):format(Type, widgetNum), scrollFrame)
326 editBox:SetAllPoints()
327 editBox:SetFontObject(ChatFontNormal)
328 editBox:SetMultiLine(true)
329 editBox:EnableMouse(true)
330 editBox:SetAutoFocus(false)
331 editBox:SetCountInvisibleLetters(false)
332 editBox:SetScript("OnCursorChanged", OnCursorChanged)
333 editBox:SetScript("OnEditFocusLost", OnEditFocusLost)
334 editBox:SetScript("OnEnter", OnEnter)
335 editBox:SetScript("OnEscapePressed", editBox.ClearFocus)
336 editBox:SetScript("OnLeave", OnLeave)
337 editBox:SetScript("OnMouseDown", OnReceiveDrag)
338 editBox:SetScript("OnReceiveDrag", OnReceiveDrag)
339 editBox:SetScript("OnTextChanged", OnTextChanged)
340 editBox:SetScript("OnTextSet", OnTextSet)
341 editBox:SetScript("OnEditFocusGained", OnEditFocusGained)
344 scrollFrame:SetScrollChild(editBox)
353 scrollBar = scrollBar,
355 scrollFrame = scrollFrame,
358 for method, func in pairs(methods) do
359 widget[method] = func
361 button.obj, editBox.obj, scrollFrame.obj = widget, widget, widget
363 return AceGUI:RegisterAsWidget(widget)
366 AceGUI:RegisterWidgetType(Type, Constructor, Version)