annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-EditBox.lua @ 0:169f5211fc7f

First public revision. At this point ItemAuditor watches mail for auctions sold or purchased, watches for buy/sell (money and 1 item type change) and conversions/tradeskills. Milling isn't working yet because there is too much time between the first event and the last event.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Thu, 20 May 2010 19:22:19 -0700
parents
children
rev   line source
Asa@0 1 local AceGUI = LibStub("AceGUI-3.0")
Asa@0 2
Asa@0 3 -- Lua APIs
Asa@0 4 local tostring = tostring
Asa@0 5
Asa@0 6 -- WoW APIs
Asa@0 7 local GetCursorInfo, ClearCursor, GetSpellName = GetCursorInfo, ClearCursor, GetSpellName
Asa@0 8 local CreateFrame, UIParent = CreateFrame, UIParent
Asa@0 9 local _G = _G
Asa@0 10
Asa@0 11 -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
Asa@0 12 -- List them here for Mikk's FindGlobals script
Asa@0 13 -- GLOBALS: AceGUIEditBoxInsertLink, ChatFontNormal, OKAY
Asa@0 14
Asa@0 15 local Type = "EditBox"
Asa@0 16 local Version = 13
Asa@0 17
Asa@0 18 if not AceGUIEditBoxInsertLink then
Asa@0 19 -- upgradeable hook
Asa@0 20 hooksecurefunc("ChatEdit_InsertLink", function(...) return _G.AceGUIEditBoxInsertLink(...) end)
Asa@0 21 end
Asa@0 22
Asa@0 23 function _G.AceGUIEditBoxInsertLink(text)
Asa@0 24 for i = 1, AceGUI:GetNextWidgetNum(Type)-1 do
Asa@0 25 local editbox = _G["AceGUI-3.0EditBox"..i]
Asa@0 26 if editbox and editbox:IsVisible() and editbox:HasFocus() then
Asa@0 27 editbox:Insert(text)
Asa@0 28 return true
Asa@0 29 end
Asa@0 30 end
Asa@0 31 end
Asa@0 32
Asa@0 33
Asa@0 34 --------------------------
Asa@0 35 -- Edit box --
Asa@0 36 --------------------------
Asa@0 37 --[[
Asa@0 38 Events :
Asa@0 39 OnTextChanged
Asa@0 40 OnEnterPressed
Asa@0 41
Asa@0 42 ]]
Asa@0 43 do
Asa@0 44 local function OnAcquire(self)
Asa@0 45 self:SetHeight(26)
Asa@0 46 self:SetWidth(200)
Asa@0 47 self:SetDisabled(false)
Asa@0 48 self:SetLabel()
Asa@0 49 self.showbutton = true
Asa@0 50 end
Asa@0 51
Asa@0 52 local function OnRelease(self)
Asa@0 53 self.frame:ClearAllPoints()
Asa@0 54 self.frame:Hide()
Asa@0 55 self:SetDisabled(false)
Asa@0 56 self:SetText()
Asa@0 57 end
Asa@0 58
Asa@0 59 local function Control_OnEnter(this)
Asa@0 60 this.obj:Fire("OnEnter")
Asa@0 61 end
Asa@0 62
Asa@0 63 local function Control_OnLeave(this)
Asa@0 64 this.obj:Fire("OnLeave")
Asa@0 65 end
Asa@0 66
Asa@0 67 local function EditBox_OnEscapePressed(this)
Asa@0 68 this:ClearFocus()
Asa@0 69 end
Asa@0 70
Asa@0 71 local function ShowButton(self)
Asa@0 72 if self.showbutton then
Asa@0 73 self.button:Show()
Asa@0 74 self.editbox:SetTextInsets(0,20,3,3)
Asa@0 75 end
Asa@0 76 end
Asa@0 77
Asa@0 78 local function HideButton(self)
Asa@0 79 self.button:Hide()
Asa@0 80 self.editbox:SetTextInsets(0,0,3,3)
Asa@0 81 end
Asa@0 82
Asa@0 83 local function EditBox_OnEnterPressed(this)
Asa@0 84 local self = this.obj
Asa@0 85 local value = this:GetText()
Asa@0 86 local cancel = self:Fire("OnEnterPressed",value)
Asa@0 87 if not cancel then
Asa@0 88 HideButton(self)
Asa@0 89 end
Asa@0 90 end
Asa@0 91
Asa@0 92 local function Button_OnClick(this)
Asa@0 93 local editbox = this.obj.editbox
Asa@0 94 editbox:ClearFocus()
Asa@0 95 EditBox_OnEnterPressed(editbox)
Asa@0 96 end
Asa@0 97
Asa@0 98 local function EditBox_OnReceiveDrag(this)
Asa@0 99 local self = this.obj
Asa@0 100 local type, id, info = GetCursorInfo()
Asa@0 101 if type == "item" then
Asa@0 102 self:SetText(info)
Asa@0 103 self:Fire("OnEnterPressed",info)
Asa@0 104 ClearCursor()
Asa@0 105 elseif type == "spell" then
Asa@0 106 local name, rank = GetSpellName(id, info)
Asa@0 107 if rank and rank:match("%d") then
Asa@0 108 name = name.."("..rank..")"
Asa@0 109 end
Asa@0 110 self:SetText(name)
Asa@0 111 self:Fire("OnEnterPressed",name)
Asa@0 112 ClearCursor()
Asa@0 113 end
Asa@0 114 HideButton(self)
Asa@0 115 AceGUI:ClearFocus()
Asa@0 116 end
Asa@0 117
Asa@0 118 local function EditBox_OnTextChanged(this)
Asa@0 119 local self = this.obj
Asa@0 120 local value = this:GetText()
Asa@0 121 if tostring(value) ~= tostring(self.lasttext) then
Asa@0 122 self:Fire("OnTextChanged",value)
Asa@0 123 self.lasttext = value
Asa@0 124 ShowButton(self)
Asa@0 125 end
Asa@0 126 end
Asa@0 127
Asa@0 128 local function SetDisabled(self, disabled)
Asa@0 129 self.disabled = disabled
Asa@0 130 if disabled then
Asa@0 131 self.editbox:EnableMouse(false)
Asa@0 132 self.editbox:ClearFocus()
Asa@0 133 self.editbox:SetTextColor(0.5,0.5,0.5)
Asa@0 134 self.label:SetTextColor(0.5,0.5,0.5)
Asa@0 135 else
Asa@0 136 self.editbox:EnableMouse(true)
Asa@0 137 self.editbox:SetTextColor(1,1,1)
Asa@0 138 self.label:SetTextColor(1,.82,0)
Asa@0 139 end
Asa@0 140 end
Asa@0 141
Asa@0 142 local function SetText(self, text)
Asa@0 143 self.lasttext = text or ""
Asa@0 144 self.editbox:SetText(text or "")
Asa@0 145 self.editbox:SetCursorPosition(0)
Asa@0 146 HideButton(self)
Asa@0 147 end
Asa@0 148
Asa@0 149 local function SetLabel(self, text)
Asa@0 150 if text and text ~= "" then
Asa@0 151 self.label:SetText(text)
Asa@0 152 self.label:Show()
Asa@0 153 self.editbox:SetPoint("TOPLEFT",self.frame,"TOPLEFT",7,-18)
Asa@0 154 self:SetHeight(44)
Asa@0 155 self.alignoffset = 30
Asa@0 156 else
Asa@0 157 self.label:SetText("")
Asa@0 158 self.label:Hide()
Asa@0 159 self.editbox:SetPoint("TOPLEFT",self.frame,"TOPLEFT",7,0)
Asa@0 160 self:SetHeight(26)
Asa@0 161 self.alignoffset = 12
Asa@0 162 end
Asa@0 163 end
Asa@0 164
Asa@0 165
Asa@0 166 local function Constructor()
Asa@0 167 local num = AceGUI:GetNextWidgetNum(Type)
Asa@0 168 local frame = CreateFrame("Frame",nil,UIParent)
Asa@0 169 local editbox = CreateFrame("EditBox","AceGUI-3.0EditBox"..num,frame,"InputBoxTemplate")
Asa@0 170
Asa@0 171 local self = {}
Asa@0 172 self.type = Type
Asa@0 173 self.num = num
Asa@0 174
Asa@0 175 self.OnRelease = OnRelease
Asa@0 176 self.OnAcquire = OnAcquire
Asa@0 177
Asa@0 178 self.SetDisabled = SetDisabled
Asa@0 179 self.SetText = SetText
Asa@0 180 self.SetLabel = SetLabel
Asa@0 181
Asa@0 182 self.frame = frame
Asa@0 183 frame.obj = self
Asa@0 184 self.editbox = editbox
Asa@0 185 editbox.obj = self
Asa@0 186
Asa@0 187 self.alignoffset = 30
Asa@0 188
Asa@0 189 frame:SetHeight(44)
Asa@0 190 frame:SetWidth(200)
Asa@0 191
Asa@0 192 editbox:SetScript("OnEnter",Control_OnEnter)
Asa@0 193 editbox:SetScript("OnLeave",Control_OnLeave)
Asa@0 194
Asa@0 195 editbox:SetAutoFocus(false)
Asa@0 196 editbox:SetFontObject(ChatFontNormal)
Asa@0 197 editbox:SetScript("OnEscapePressed",EditBox_OnEscapePressed)
Asa@0 198 editbox:SetScript("OnEnterPressed",EditBox_OnEnterPressed)
Asa@0 199 editbox:SetScript("OnTextChanged",EditBox_OnTextChanged)
Asa@0 200 editbox:SetScript("OnReceiveDrag", EditBox_OnReceiveDrag)
Asa@0 201 editbox:SetScript("OnMouseDown", EditBox_OnReceiveDrag)
Asa@0 202
Asa@0 203 editbox:SetTextInsets(0,0,3,3)
Asa@0 204 editbox:SetMaxLetters(256)
Asa@0 205
Asa@0 206 editbox:SetPoint("BOTTOMLEFT",frame,"BOTTOMLEFT",6,0)
Asa@0 207 editbox:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",0,0)
Asa@0 208 editbox:SetHeight(19)
Asa@0 209
Asa@0 210 local label = frame:CreateFontString(nil,"OVERLAY","GameFontNormalSmall")
Asa@0 211 label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,-2)
Asa@0 212 label:SetPoint("TOPRIGHT",frame,"TOPRIGHT",0,-2)
Asa@0 213 label:SetJustifyH("LEFT")
Asa@0 214 label:SetHeight(18)
Asa@0 215 self.label = label
Asa@0 216
Asa@0 217 local button = CreateFrame("Button",nil,editbox,"UIPanelButtonTemplate")
Asa@0 218 button:SetWidth(40)
Asa@0 219 button:SetHeight(20)
Asa@0 220 button:SetPoint("RIGHT",editbox,"RIGHT",-2,0)
Asa@0 221 button:SetText(OKAY)
Asa@0 222 button:SetScript("OnClick", Button_OnClick)
Asa@0 223 button:Hide()
Asa@0 224
Asa@0 225 self.button = button
Asa@0 226 button.obj = self
Asa@0 227
Asa@0 228 AceGUI:RegisterAsWidget(self)
Asa@0 229 return self
Asa@0 230 end
Asa@0 231
Asa@0 232 AceGUI:RegisterWidgetType(Type,Constructor,Version)
Asa@0 233 end