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