Zerotorescue@0: local Type, Version = "MultiLineEditBox", 22 Zerotorescue@0: local AceGUI = LibStub and LibStub("AceGUI-3.0", true) Zerotorescue@0: if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end Zerotorescue@0: Zerotorescue@0: -- Lua APIs Zerotorescue@0: local pairs = pairs Zerotorescue@0: Zerotorescue@0: -- WoW APIs Zerotorescue@0: local GetCursorInfo, GetSpellName, ClearCursor = GetCursorInfo, GetSpellName, ClearCursor Zerotorescue@0: local CreateFrame, UIParent = CreateFrame, UIParent Zerotorescue@0: local _G = _G Zerotorescue@0: Zerotorescue@0: -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded Zerotorescue@0: -- List them here for Mikk's FindGlobals script Zerotorescue@0: -- GLOBALS: ACCEPT, ChatFontNormal Zerotorescue@0: Zerotorescue@0: --[[----------------------------------------------------------------------------- Zerotorescue@0: Scripts Zerotorescue@0: -------------------------------------------------------------------------------]] Zerotorescue@0: local function OnClick(self) -- Button Zerotorescue@0: self = self.obj Zerotorescue@0: self.editBox:ClearFocus() Zerotorescue@0: if not self:Fire("OnEnterPressed", self.editBox:GetText()) then Zerotorescue@0: self.button:Disable() Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: local function OnCursorChanged(self, _, y, _, cursorHeight) -- EditBox Zerotorescue@0: self, y = self.obj.scrollFrame, -y Zerotorescue@0: local offset = self:GetVerticalScroll() Zerotorescue@0: if y < offset then Zerotorescue@0: self:SetVerticalScroll(y) Zerotorescue@0: else Zerotorescue@0: y = y + cursorHeight - self:GetHeight() Zerotorescue@0: if y > offset then Zerotorescue@0: self:SetVerticalScroll(y) Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: local function OnEditFocusLost(self) -- EditBox Zerotorescue@0: self:HighlightText(0, 0) Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: local function OnEnter(self) -- EditBox / ScrollFrame Zerotorescue@0: self = self.obj Zerotorescue@0: if not self.entered then Zerotorescue@0: self.entered = true Zerotorescue@0: self:Fire("OnEnter") Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: local function OnLeave(self) -- EditBox / ScrollFrame Zerotorescue@0: self = self.obj Zerotorescue@0: if self.entered then Zerotorescue@0: self.entered = nil Zerotorescue@0: self:Fire("OnLeave") Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: local function OnMouseUp(self) -- ScrollFrame Zerotorescue@0: self = self.obj.editBox Zerotorescue@0: self:SetFocus() Zerotorescue@0: self:SetCursorPosition(self:GetNumLetters()) Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: local function OnReceiveDrag(self) -- EditBox / ScrollFrame Zerotorescue@0: local type, id, info = GetCursorInfo() Zerotorescue@0: if type == "spell" then Zerotorescue@0: info, id = GetSpellName(id, info) Zerotorescue@0: if id and id:match("%d") then Zerotorescue@0: info = info .. "(" .. id .. ")" Zerotorescue@0: end Zerotorescue@0: elseif type ~= "item" then Zerotorescue@0: return Zerotorescue@0: end Zerotorescue@0: ClearCursor() Zerotorescue@0: self = self.obj Zerotorescue@0: local editBox = self.editBox Zerotorescue@0: if not editBox:HasFocus() then Zerotorescue@0: editBox:SetFocus() Zerotorescue@0: editBox:SetCursorPosition(editBox:GetNumLetters()) Zerotorescue@0: end Zerotorescue@0: editBox:Insert(info) Zerotorescue@0: self.button:Enable() Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: local function OnSizeChanged(self, width, height) -- ScrollFrame Zerotorescue@0: self.obj.editBox:SetWidth(width) Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: local function OnTextChanged(self, userInput) -- EditBox Zerotorescue@0: if userInput then Zerotorescue@0: self = self.obj Zerotorescue@0: self:Fire("OnTextChanged", self.editBox:GetText()) Zerotorescue@0: self.button:Enable() Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: local function OnTextSet(self) -- EditBox Zerotorescue@0: self:HighlightText(0, 0) Zerotorescue@0: self:SetCursorPosition(self:GetNumLetters()) Zerotorescue@0: self:SetCursorPosition(0) Zerotorescue@0: self.obj.button:Disable() Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: local function OnVerticalScroll(self, offset) -- ScrollFrame Zerotorescue@0: local editBox = self.obj.editBox Zerotorescue@0: editBox:SetHitRectInsets(0, 0, offset, editBox:GetHeight() - offset - self:GetHeight()) Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: --[[----------------------------------------------------------------------------- Zerotorescue@0: Methods Zerotorescue@0: -------------------------------------------------------------------------------]] Zerotorescue@0: local methods = { Zerotorescue@0: ["GetText"] = function(self) Zerotorescue@0: return self.editBox:GetText() Zerotorescue@0: end, Zerotorescue@0: Zerotorescue@0: ["OnAcquire"] = function(self) Zerotorescue@0: self.editBox:SetText("") Zerotorescue@0: self:SetDisabled(false) Zerotorescue@0: self:SetWidth(200) Zerotorescue@0: self:SetNumLines() Zerotorescue@0: self.entered = nil Zerotorescue@0: self:SetMaxLetters(0) Zerotorescue@0: end, Zerotorescue@0: Zerotorescue@0: ["OnRelease"] = function(self) Zerotorescue@0: self.frame:ClearAllPoints() Zerotorescue@0: self.frame:Hide() Zerotorescue@0: end, Zerotorescue@0: Zerotorescue@0: ["SetDisabled"] = function(self, disabled) Zerotorescue@0: local editBox = self.editBox Zerotorescue@0: if disabled then Zerotorescue@0: editBox:ClearFocus() Zerotorescue@0: editBox:EnableMouse(false) Zerotorescue@0: editBox:SetTextColor(0.5, 0.5, 0.5) Zerotorescue@0: self.label:SetTextColor(0.5, 0.5, 0.5) Zerotorescue@0: self.scrollFrame:EnableMouse(false) Zerotorescue@0: self.button:Disable() Zerotorescue@0: else Zerotorescue@0: editBox:EnableMouse(true) Zerotorescue@0: editBox:SetTextColor(1, 1, 1) Zerotorescue@0: self.label:SetTextColor(1, 0.82, 0) Zerotorescue@0: self.scrollFrame:EnableMouse(true) Zerotorescue@0: end Zerotorescue@0: end, Zerotorescue@0: Zerotorescue@0: ["SetLabel"] = function(self, text) Zerotorescue@0: if text and text ~= "" then Zerotorescue@0: self.label:SetText(text) Zerotorescue@0: if self.labelHeight ~= 10 then Zerotorescue@0: self.labelHeight = 10 Zerotorescue@0: self.scrollBar:SetPoint("TOP", self.label, "BOTTOM", 0, -19) Zerotorescue@0: self:SetHeight(self.frame.height + 10) Zerotorescue@0: self.label:Show() Zerotorescue@0: end Zerotorescue@0: elseif self.labelHeight ~= 0 then Zerotorescue@0: self.labelHeight = 0 Zerotorescue@0: self.label:Hide() Zerotorescue@0: self.scrollBar:SetPoint("TOP", self.frame, "TOP", 0, -23) Zerotorescue@0: self:SetHeight(self.frame.height - 10) Zerotorescue@0: end Zerotorescue@0: end, Zerotorescue@0: Zerotorescue@0: ["SetNumLines"] = function(self, value) Zerotorescue@0: if not value or value < 4 then Zerotorescue@0: value = 4 Zerotorescue@0: end Zerotorescue@0: self:SetHeight(value * 14 + 41 + self.labelHeight) Zerotorescue@0: end, Zerotorescue@0: Zerotorescue@0: ["SetText"] = function(self, text) Zerotorescue@0: self.editBox:SetText(text) Zerotorescue@0: end, Zerotorescue@0: Zerotorescue@0: ["SetMaxLetters"] = function (self, num) Zerotorescue@0: self.editBox:SetMaxLetters(num or 0) Zerotorescue@0: end Zerotorescue@0: } Zerotorescue@0: Zerotorescue@0: --[[----------------------------------------------------------------------------- Zerotorescue@0: Constructor Zerotorescue@0: -------------------------------------------------------------------------------]] Zerotorescue@0: local backdrop = { Zerotorescue@0: bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], Zerotorescue@0: edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]], edgeSize = 16, Zerotorescue@0: insets = { left = 4, right = 3, top = 4, bottom = 3 } Zerotorescue@0: } Zerotorescue@0: Zerotorescue@0: local function Constructor() Zerotorescue@0: local frame = CreateFrame("Frame", nil, UIParent) Zerotorescue@0: frame:Hide() Zerotorescue@0: Zerotorescue@0: local widgetNum = AceGUI:GetNextWidgetNum(Type) Zerotorescue@0: Zerotorescue@0: local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall") Zerotorescue@0: label:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, -4) Zerotorescue@0: label:SetPoint("TOPRIGHT", frame, "TOPRIGHT", 0, -4) Zerotorescue@0: label:SetJustifyH("LEFT") Zerotorescue@0: label:SetText(ACCEPT) Zerotorescue@0: label:SetHeight(10) Zerotorescue@0: Zerotorescue@0: local button = CreateFrame("Button", ("%s%dButton"):format(Type, widgetNum), frame, "UIPanelButtonTemplate2") Zerotorescue@0: button:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 0, 4) Zerotorescue@0: button:SetHeight(22) Zerotorescue@0: button:SetWidth(label:GetStringWidth() + 24) Zerotorescue@0: button:SetText(ACCEPT) Zerotorescue@0: button:SetScript("OnClick", OnClick) Zerotorescue@0: button:Disable() Zerotorescue@0: Zerotorescue@0: local text = button:GetFontString() Zerotorescue@0: text:ClearAllPoints() Zerotorescue@0: text:SetPoint("TOPLEFT", button, "TOPLEFT", 5, -5) Zerotorescue@0: text:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", -5, 1) Zerotorescue@0: text:SetJustifyV("MIDDLE") Zerotorescue@0: Zerotorescue@0: local scrollBG = CreateFrame("Frame", nil, frame) Zerotorescue@0: scrollBG:SetBackdrop(backdrop) Zerotorescue@0: scrollBG:SetBackdropColor(0, 0, 0) Zerotorescue@0: scrollBG:SetBackdropBorderColor(0.4, 0.4, 0.4) Zerotorescue@0: Zerotorescue@0: local scrollFrame = CreateFrame("ScrollFrame", ("%s%dScrollFrame"):format(Type, widgetNum), frame, "UIPanelScrollFrameTemplate") Zerotorescue@0: Zerotorescue@0: local scrollBar = _G[scrollFrame:GetName() .. "ScrollBar"] Zerotorescue@0: scrollBar:ClearAllPoints() Zerotorescue@0: scrollBar:SetPoint("TOP", label, "BOTTOM", 0, -19) Zerotorescue@0: scrollBar:SetPoint("BOTTOM", button, "TOP", 0, 18) Zerotorescue@0: scrollBar:SetPoint("RIGHT", frame, "RIGHT") Zerotorescue@0: Zerotorescue@0: scrollBG:SetPoint("TOPRIGHT", scrollBar, "TOPLEFT", 0, 19) Zerotorescue@0: scrollBG:SetPoint("BOTTOMLEFT", button, "TOPLEFT") Zerotorescue@0: Zerotorescue@0: scrollFrame:SetPoint("TOPLEFT", scrollBG, "TOPLEFT", 5, -6) Zerotorescue@0: scrollFrame:SetPoint("BOTTOMRIGHT", scrollBG, "BOTTOMRIGHT", -4, 4) Zerotorescue@0: scrollFrame:SetScript("OnEnter", OnEnter) Zerotorescue@0: scrollFrame:SetScript("OnLeave", OnLeave) Zerotorescue@0: scrollFrame:SetScript("OnMouseUp", OnMouseUp) Zerotorescue@0: scrollFrame:SetScript("OnReceiveDrag", OnReceiveDrag) Zerotorescue@0: scrollFrame:SetScript("OnSizeChanged", OnSizeChanged) Zerotorescue@0: scrollFrame:HookScript("OnVerticalScroll", OnVerticalScroll) Zerotorescue@0: Zerotorescue@0: local editBox = CreateFrame("EditBox", nil, scrollFrame) Zerotorescue@0: editBox:SetAllPoints() Zerotorescue@0: editBox:SetFontObject(ChatFontNormal) Zerotorescue@0: editBox:SetMultiLine(true) Zerotorescue@0: editBox:EnableMouse(true) Zerotorescue@0: editBox:SetAutoFocus(false) Zerotorescue@0: editBox:SetCountInvisibleLetters(false) Zerotorescue@0: editBox:SetScript("OnCursorChanged", OnCursorChanged) Zerotorescue@0: editBox:SetScript("OnEditFocusLost", OnEditFocusLost) Zerotorescue@0: editBox:SetScript("OnEnter", OnEnter) Zerotorescue@0: editBox:SetScript("OnEscapePressed", editBox.ClearFocus) Zerotorescue@0: editBox:SetScript("OnLeave", OnLeave) Zerotorescue@0: editBox:SetScript("OnMouseDown", OnReceiveDrag) Zerotorescue@0: editBox:SetScript("OnReceiveDrag", OnReceiveDrag) Zerotorescue@0: editBox:SetScript("OnTextChanged", OnTextChanged) Zerotorescue@0: editBox:SetScript("OnTextSet", OnTextSet) Zerotorescue@0: Zerotorescue@0: scrollFrame:SetScrollChild(editBox) Zerotorescue@0: Zerotorescue@0: local widget = { Zerotorescue@0: button = button, Zerotorescue@0: editBox = editBox, Zerotorescue@0: frame = frame, Zerotorescue@0: label = label, Zerotorescue@0: labelHeight = 10, Zerotorescue@0: scrollBar = scrollBar, Zerotorescue@0: scrollFrame = scrollFrame, Zerotorescue@0: type = Type Zerotorescue@0: } Zerotorescue@0: for method, func in pairs(methods) do Zerotorescue@0: widget[method] = func Zerotorescue@0: end Zerotorescue@0: button.obj, editBox.obj, scrollFrame.obj = widget, widget, widget Zerotorescue@0: Zerotorescue@0: AceGUI:RegisterAsWidget(widget) Zerotorescue@0: return widget Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: AceGUI:RegisterWidgetType(Type, Constructor, Version)