annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-MultiLineEditBox.lua @ 8:1b2d819b4fa8

Now using the global MailAddonBusy to indicate MailOpener is busy, read comments in Core.lua for more info. Default status is now ?enabled without automatic mail opening? to let first time users look around before MailOpener messes up their heads. A StaticPopupDialog will be added later to ask if they want to auto-enable. When ?enabled without automatic mail opening? is on and you toggle the mail opening checkbox on, mail opening will automatically start.
author Zerotorescue
date Thu, 09 Sep 2010 10:53:19 +0200
parents 823e33465b6e
children
rev   line source
Zerotorescue@0 1 local Type, Version = "MultiLineEditBox", 22
Zerotorescue@0 2 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
Zerotorescue@0 3 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
Zerotorescue@0 4
Zerotorescue@0 5 -- Lua APIs
Zerotorescue@0 6 local pairs = pairs
Zerotorescue@0 7
Zerotorescue@0 8 -- WoW APIs
Zerotorescue@0 9 local GetCursorInfo, GetSpellName, ClearCursor = GetCursorInfo, GetSpellName, ClearCursor
Zerotorescue@0 10 local CreateFrame, UIParent = CreateFrame, UIParent
Zerotorescue@0 11 local _G = _G
Zerotorescue@0 12
Zerotorescue@0 13 -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
Zerotorescue@0 14 -- List them here for Mikk's FindGlobals script
Zerotorescue@0 15 -- GLOBALS: ACCEPT, ChatFontNormal
Zerotorescue@0 16
Zerotorescue@0 17 --[[-----------------------------------------------------------------------------
Zerotorescue@0 18 Scripts
Zerotorescue@0 19 -------------------------------------------------------------------------------]]
Zerotorescue@0 20 local function OnClick(self) -- Button
Zerotorescue@0 21 self = self.obj
Zerotorescue@0 22 self.editBox:ClearFocus()
Zerotorescue@0 23 if not self:Fire("OnEnterPressed", self.editBox:GetText()) then
Zerotorescue@0 24 self.button:Disable()
Zerotorescue@0 25 end
Zerotorescue@0 26 end
Zerotorescue@0 27
Zerotorescue@0 28 local function OnCursorChanged(self, _, y, _, cursorHeight) -- EditBox
Zerotorescue@0 29 self, y = self.obj.scrollFrame, -y
Zerotorescue@0 30 local offset = self:GetVerticalScroll()
Zerotorescue@0 31 if y < offset then
Zerotorescue@0 32 self:SetVerticalScroll(y)
Zerotorescue@0 33 else
Zerotorescue@0 34 y = y + cursorHeight - self:GetHeight()
Zerotorescue@0 35 if y > offset then
Zerotorescue@0 36 self:SetVerticalScroll(y)
Zerotorescue@0 37 end
Zerotorescue@0 38 end
Zerotorescue@0 39 end
Zerotorescue@0 40
Zerotorescue@0 41 local function OnEditFocusLost(self) -- EditBox
Zerotorescue@0 42 self:HighlightText(0, 0)
Zerotorescue@0 43 end
Zerotorescue@0 44
Zerotorescue@0 45 local function OnEnter(self) -- EditBox / ScrollFrame
Zerotorescue@0 46 self = self.obj
Zerotorescue@0 47 if not self.entered then
Zerotorescue@0 48 self.entered = true
Zerotorescue@0 49 self:Fire("OnEnter")
Zerotorescue@0 50 end
Zerotorescue@0 51 end
Zerotorescue@0 52
Zerotorescue@0 53 local function OnLeave(self) -- EditBox / ScrollFrame
Zerotorescue@0 54 self = self.obj
Zerotorescue@0 55 if self.entered then
Zerotorescue@0 56 self.entered = nil
Zerotorescue@0 57 self:Fire("OnLeave")
Zerotorescue@0 58 end
Zerotorescue@0 59 end
Zerotorescue@0 60
Zerotorescue@0 61 local function OnMouseUp(self) -- ScrollFrame
Zerotorescue@0 62 self = self.obj.editBox
Zerotorescue@0 63 self:SetFocus()
Zerotorescue@0 64 self:SetCursorPosition(self:GetNumLetters())
Zerotorescue@0 65 end
Zerotorescue@0 66
Zerotorescue@0 67 local function OnReceiveDrag(self) -- EditBox / ScrollFrame
Zerotorescue@0 68 local type, id, info = GetCursorInfo()
Zerotorescue@0 69 if type == "spell" then
Zerotorescue@0 70 info, id = GetSpellName(id, info)
Zerotorescue@0 71 if id and id:match("%d") then
Zerotorescue@0 72 info = info .. "(" .. id .. ")"
Zerotorescue@0 73 end
Zerotorescue@0 74 elseif type ~= "item" then
Zerotorescue@0 75 return
Zerotorescue@0 76 end
Zerotorescue@0 77 ClearCursor()
Zerotorescue@0 78 self = self.obj
Zerotorescue@0 79 local editBox = self.editBox
Zerotorescue@0 80 if not editBox:HasFocus() then
Zerotorescue@0 81 editBox:SetFocus()
Zerotorescue@0 82 editBox:SetCursorPosition(editBox:GetNumLetters())
Zerotorescue@0 83 end
Zerotorescue@0 84 editBox:Insert(info)
Zerotorescue@0 85 self.button:Enable()
Zerotorescue@0 86 end
Zerotorescue@0 87
Zerotorescue@0 88 local function OnSizeChanged(self, width, height) -- ScrollFrame
Zerotorescue@0 89 self.obj.editBox:SetWidth(width)
Zerotorescue@0 90 end
Zerotorescue@0 91
Zerotorescue@0 92 local function OnTextChanged(self, userInput) -- EditBox
Zerotorescue@0 93 if userInput then
Zerotorescue@0 94 self = self.obj
Zerotorescue@0 95 self:Fire("OnTextChanged", self.editBox:GetText())
Zerotorescue@0 96 self.button:Enable()
Zerotorescue@0 97 end
Zerotorescue@0 98 end
Zerotorescue@0 99
Zerotorescue@0 100 local function OnTextSet(self) -- EditBox
Zerotorescue@0 101 self:HighlightText(0, 0)
Zerotorescue@0 102 self:SetCursorPosition(self:GetNumLetters())
Zerotorescue@0 103 self:SetCursorPosition(0)
Zerotorescue@0 104 self.obj.button:Disable()
Zerotorescue@0 105 end
Zerotorescue@0 106
Zerotorescue@0 107 local function OnVerticalScroll(self, offset) -- ScrollFrame
Zerotorescue@0 108 local editBox = self.obj.editBox
Zerotorescue@0 109 editBox:SetHitRectInsets(0, 0, offset, editBox:GetHeight() - offset - self:GetHeight())
Zerotorescue@0 110 end
Zerotorescue@0 111
Zerotorescue@0 112 --[[-----------------------------------------------------------------------------
Zerotorescue@0 113 Methods
Zerotorescue@0 114 -------------------------------------------------------------------------------]]
Zerotorescue@0 115 local methods = {
Zerotorescue@0 116 ["GetText"] = function(self)
Zerotorescue@0 117 return self.editBox:GetText()
Zerotorescue@0 118 end,
Zerotorescue@0 119
Zerotorescue@0 120 ["OnAcquire"] = function(self)
Zerotorescue@0 121 self.editBox:SetText("")
Zerotorescue@0 122 self:SetDisabled(false)
Zerotorescue@0 123 self:SetWidth(200)
Zerotorescue@0 124 self:SetNumLines()
Zerotorescue@0 125 self.entered = nil
Zerotorescue@0 126 self:SetMaxLetters(0)
Zerotorescue@0 127 end,
Zerotorescue@0 128
Zerotorescue@0 129 ["OnRelease"] = function(self)
Zerotorescue@0 130 self.frame:ClearAllPoints()
Zerotorescue@0 131 self.frame:Hide()
Zerotorescue@0 132 end,
Zerotorescue@0 133
Zerotorescue@0 134 ["SetDisabled"] = function(self, disabled)
Zerotorescue@0 135 local editBox = self.editBox
Zerotorescue@0 136 if disabled then
Zerotorescue@0 137 editBox:ClearFocus()
Zerotorescue@0 138 editBox:EnableMouse(false)
Zerotorescue@0 139 editBox:SetTextColor(0.5, 0.5, 0.5)
Zerotorescue@0 140 self.label:SetTextColor(0.5, 0.5, 0.5)
Zerotorescue@0 141 self.scrollFrame:EnableMouse(false)
Zerotorescue@0 142 self.button:Disable()
Zerotorescue@0 143 else
Zerotorescue@0 144 editBox:EnableMouse(true)
Zerotorescue@0 145 editBox:SetTextColor(1, 1, 1)
Zerotorescue@0 146 self.label:SetTextColor(1, 0.82, 0)
Zerotorescue@0 147 self.scrollFrame:EnableMouse(true)
Zerotorescue@0 148 end
Zerotorescue@0 149 end,
Zerotorescue@0 150
Zerotorescue@0 151 ["SetLabel"] = function(self, text)
Zerotorescue@0 152 if text and text ~= "" then
Zerotorescue@0 153 self.label:SetText(text)
Zerotorescue@0 154 if self.labelHeight ~= 10 then
Zerotorescue@0 155 self.labelHeight = 10
Zerotorescue@0 156 self.scrollBar:SetPoint("TOP", self.label, "BOTTOM", 0, -19)
Zerotorescue@0 157 self:SetHeight(self.frame.height + 10)
Zerotorescue@0 158 self.label:Show()
Zerotorescue@0 159 end
Zerotorescue@0 160 elseif self.labelHeight ~= 0 then
Zerotorescue@0 161 self.labelHeight = 0
Zerotorescue@0 162 self.label:Hide()
Zerotorescue@0 163 self.scrollBar:SetPoint("TOP", self.frame, "TOP", 0, -23)
Zerotorescue@0 164 self:SetHeight(self.frame.height - 10)
Zerotorescue@0 165 end
Zerotorescue@0 166 end,
Zerotorescue@0 167
Zerotorescue@0 168 ["SetNumLines"] = function(self, value)
Zerotorescue@0 169 if not value or value < 4 then
Zerotorescue@0 170 value = 4
Zerotorescue@0 171 end
Zerotorescue@0 172 self:SetHeight(value * 14 + 41 + self.labelHeight)
Zerotorescue@0 173 end,
Zerotorescue@0 174
Zerotorescue@0 175 ["SetText"] = function(self, text)
Zerotorescue@0 176 self.editBox:SetText(text)
Zerotorescue@0 177 end,
Zerotorescue@0 178
Zerotorescue@0 179 ["SetMaxLetters"] = function (self, num)
Zerotorescue@0 180 self.editBox:SetMaxLetters(num or 0)
Zerotorescue@0 181 end
Zerotorescue@0 182 }
Zerotorescue@0 183
Zerotorescue@0 184 --[[-----------------------------------------------------------------------------
Zerotorescue@0 185 Constructor
Zerotorescue@0 186 -------------------------------------------------------------------------------]]
Zerotorescue@0 187 local backdrop = {
Zerotorescue@0 188 bgFile = [[Interface\Tooltips\UI-Tooltip-Background]],
Zerotorescue@0 189 edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]], edgeSize = 16,
Zerotorescue@0 190 insets = { left = 4, right = 3, top = 4, bottom = 3 }
Zerotorescue@0 191 }
Zerotorescue@0 192
Zerotorescue@0 193 local function Constructor()
Zerotorescue@0 194 local frame = CreateFrame("Frame", nil, UIParent)
Zerotorescue@0 195 frame:Hide()
Zerotorescue@0 196
Zerotorescue@0 197 local widgetNum = AceGUI:GetNextWidgetNum(Type)
Zerotorescue@0 198
Zerotorescue@0 199 local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
Zerotorescue@0 200 label:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, -4)
Zerotorescue@0 201 label:SetPoint("TOPRIGHT", frame, "TOPRIGHT", 0, -4)
Zerotorescue@0 202 label:SetJustifyH("LEFT")
Zerotorescue@0 203 label:SetText(ACCEPT)
Zerotorescue@0 204 label:SetHeight(10)
Zerotorescue@0 205
Zerotorescue@0 206 local button = CreateFrame("Button", ("%s%dButton"):format(Type, widgetNum), frame, "UIPanelButtonTemplate2")
Zerotorescue@0 207 button:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 0, 4)
Zerotorescue@0 208 button:SetHeight(22)
Zerotorescue@0 209 button:SetWidth(label:GetStringWidth() + 24)
Zerotorescue@0 210 button:SetText(ACCEPT)
Zerotorescue@0 211 button:SetScript("OnClick", OnClick)
Zerotorescue@0 212 button:Disable()
Zerotorescue@0 213
Zerotorescue@0 214 local text = button:GetFontString()
Zerotorescue@0 215 text:ClearAllPoints()
Zerotorescue@0 216 text:SetPoint("TOPLEFT", button, "TOPLEFT", 5, -5)
Zerotorescue@0 217 text:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", -5, 1)
Zerotorescue@0 218 text:SetJustifyV("MIDDLE")
Zerotorescue@0 219
Zerotorescue@0 220 local scrollBG = CreateFrame("Frame", nil, frame)
Zerotorescue@0 221 scrollBG:SetBackdrop(backdrop)
Zerotorescue@0 222 scrollBG:SetBackdropColor(0, 0, 0)
Zerotorescue@0 223 scrollBG:SetBackdropBorderColor(0.4, 0.4, 0.4)
Zerotorescue@0 224
Zerotorescue@0 225 local scrollFrame = CreateFrame("ScrollFrame", ("%s%dScrollFrame"):format(Type, widgetNum), frame, "UIPanelScrollFrameTemplate")
Zerotorescue@0 226
Zerotorescue@0 227 local scrollBar = _G[scrollFrame:GetName() .. "ScrollBar"]
Zerotorescue@0 228 scrollBar:ClearAllPoints()
Zerotorescue@0 229 scrollBar:SetPoint("TOP", label, "BOTTOM", 0, -19)
Zerotorescue@0 230 scrollBar:SetPoint("BOTTOM", button, "TOP", 0, 18)
Zerotorescue@0 231 scrollBar:SetPoint("RIGHT", frame, "RIGHT")
Zerotorescue@0 232
Zerotorescue@0 233 scrollBG:SetPoint("TOPRIGHT", scrollBar, "TOPLEFT", 0, 19)
Zerotorescue@0 234 scrollBG:SetPoint("BOTTOMLEFT", button, "TOPLEFT")
Zerotorescue@0 235
Zerotorescue@0 236 scrollFrame:SetPoint("TOPLEFT", scrollBG, "TOPLEFT", 5, -6)
Zerotorescue@0 237 scrollFrame:SetPoint("BOTTOMRIGHT", scrollBG, "BOTTOMRIGHT", -4, 4)
Zerotorescue@0 238 scrollFrame:SetScript("OnEnter", OnEnter)
Zerotorescue@0 239 scrollFrame:SetScript("OnLeave", OnLeave)
Zerotorescue@0 240 scrollFrame:SetScript("OnMouseUp", OnMouseUp)
Zerotorescue@0 241 scrollFrame:SetScript("OnReceiveDrag", OnReceiveDrag)
Zerotorescue@0 242 scrollFrame:SetScript("OnSizeChanged", OnSizeChanged)
Zerotorescue@0 243 scrollFrame:HookScript("OnVerticalScroll", OnVerticalScroll)
Zerotorescue@0 244
Zerotorescue@0 245 local editBox = CreateFrame("EditBox", nil, scrollFrame)
Zerotorescue@0 246 editBox:SetAllPoints()
Zerotorescue@0 247 editBox:SetFontObject(ChatFontNormal)
Zerotorescue@0 248 editBox:SetMultiLine(true)
Zerotorescue@0 249 editBox:EnableMouse(true)
Zerotorescue@0 250 editBox:SetAutoFocus(false)
Zerotorescue@0 251 editBox:SetCountInvisibleLetters(false)
Zerotorescue@0 252 editBox:SetScript("OnCursorChanged", OnCursorChanged)
Zerotorescue@0 253 editBox:SetScript("OnEditFocusLost", OnEditFocusLost)
Zerotorescue@0 254 editBox:SetScript("OnEnter", OnEnter)
Zerotorescue@0 255 editBox:SetScript("OnEscapePressed", editBox.ClearFocus)
Zerotorescue@0 256 editBox:SetScript("OnLeave", OnLeave)
Zerotorescue@0 257 editBox:SetScript("OnMouseDown", OnReceiveDrag)
Zerotorescue@0 258 editBox:SetScript("OnReceiveDrag", OnReceiveDrag)
Zerotorescue@0 259 editBox:SetScript("OnTextChanged", OnTextChanged)
Zerotorescue@0 260 editBox:SetScript("OnTextSet", OnTextSet)
Zerotorescue@0 261
Zerotorescue@0 262 scrollFrame:SetScrollChild(editBox)
Zerotorescue@0 263
Zerotorescue@0 264 local widget = {
Zerotorescue@0 265 button = button,
Zerotorescue@0 266 editBox = editBox,
Zerotorescue@0 267 frame = frame,
Zerotorescue@0 268 label = label,
Zerotorescue@0 269 labelHeight = 10,
Zerotorescue@0 270 scrollBar = scrollBar,
Zerotorescue@0 271 scrollFrame = scrollFrame,
Zerotorescue@0 272 type = Type
Zerotorescue@0 273 }
Zerotorescue@0 274 for method, func in pairs(methods) do
Zerotorescue@0 275 widget[method] = func
Zerotorescue@0 276 end
Zerotorescue@0 277 button.obj, editBox.obj, scrollFrame.obj = widget, widget, widget
Zerotorescue@0 278
Zerotorescue@0 279 AceGUI:RegisterAsWidget(widget)
Zerotorescue@0 280 return widget
Zerotorescue@0 281 end
Zerotorescue@0 282
Zerotorescue@0 283 AceGUI:RegisterWidgetType(Type, Constructor, Version)