|
Tercio@11
|
1
|
|
Tercio@11
|
2 local DF = _G ["DetailsFramework"]
|
|
Tercio@20
|
3 if (not DF or not DetailsFrameworkCanLoad) then
|
|
Tercio@20
|
4 return
|
|
Tercio@20
|
5 end
|
|
Tercio@20
|
6
|
|
Tercio@11
|
7 local _
|
|
Tercio@11
|
8 local _rawset = rawset --> lua local
|
|
Tercio@11
|
9 local _rawget = rawget --> lua local
|
|
Tercio@11
|
10 local _setmetatable = setmetatable --> lua local
|
|
Tercio@11
|
11 local _unpack = unpack --> lua local
|
|
Tercio@11
|
12 local _type = type --> lua local
|
|
Tercio@11
|
13 local _math_floor = math.floor --> lua local
|
|
Tercio@11
|
14 local loadstring = loadstring --> lua local
|
|
Tercio@11
|
15 local _string_len = string.len --> lua local
|
|
Tercio@11
|
16
|
|
Tercio@11
|
17 local cleanfunction = function() end
|
|
Tercio@11
|
18 local APITextEntryFunctions = false
|
|
Tercio@11
|
19
|
|
Tercio@39
|
20 do
|
|
Tercio@39
|
21 local metaPrototype = {
|
|
Tercio@39
|
22 WidgetType = "textentry",
|
|
Tercio@39
|
23 SetHook = DF.SetHook,
|
|
Tercio@39
|
24 RunHooksForWidget = DF.RunHooksForWidget,
|
|
Tercio@39
|
25 }
|
|
Tercio@39
|
26
|
|
Tercio@39
|
27 _G [DF.GlobalWidgetControlNames ["textentry"]] = _G [DF.GlobalWidgetControlNames ["textentry"]] or metaPrototype
|
|
Tercio@39
|
28 end
|
|
Tercio@39
|
29
|
|
Tercio@39
|
30 local TextEntryMetaFunctions = _G [DF.GlobalWidgetControlNames ["textentry"]]
|
|
Tercio@39
|
31 DF.TextEntryCounter = DF.TextEntryCounter or 1
|
|
Tercio@11
|
32
|
|
Tercio@11
|
33 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
34 --> metatables
|
|
Tercio@11
|
35
|
|
Tercio@11
|
36 TextEntryMetaFunctions.__call = function (_table, value)
|
|
Tercio@11
|
37 --> unknow
|
|
Tercio@11
|
38 end
|
|
Tercio@11
|
39
|
|
Tercio@11
|
40 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
41 --> members
|
|
Tercio@11
|
42
|
|
Tercio@11
|
43 --> tooltip
|
|
Tercio@11
|
44 local gmember_tooltip = function (_object)
|
|
Tercio@11
|
45 return _object:GetTooltip()
|
|
Tercio@11
|
46 end
|
|
Tercio@11
|
47 --> shown
|
|
Tercio@11
|
48 local gmember_shown = function (_object)
|
|
Tercio@11
|
49 return _object:IsShown()
|
|
Tercio@11
|
50 end
|
|
Tercio@11
|
51 --> frame width
|
|
Tercio@11
|
52 local gmember_width = function (_object)
|
|
Tercio@11
|
53 return _object.editbox:GetWidth()
|
|
Tercio@11
|
54 end
|
|
Tercio@11
|
55 --> frame height
|
|
Tercio@11
|
56 local gmember_height = function (_object)
|
|
Tercio@11
|
57 return _object.editbox:GetHeight()
|
|
Tercio@11
|
58 end
|
|
Tercio@11
|
59 --> get text
|
|
Tercio@11
|
60 local gmember_text = function (_object)
|
|
Tercio@11
|
61 return _object.editbox:GetText()
|
|
Tercio@11
|
62 end
|
|
Tercio@11
|
63
|
|
Tercio@39
|
64 TextEntryMetaFunctions.GetMembers = TextEntryMetaFunctions.GetMembers or {}
|
|
Tercio@39
|
65 TextEntryMetaFunctions.GetMembers ["tooltip"] = gmember_tooltip
|
|
Tercio@39
|
66 TextEntryMetaFunctions.GetMembers ["shown"] = gmember_shown
|
|
Tercio@39
|
67 TextEntryMetaFunctions.GetMembers ["width"] = gmember_width
|
|
Tercio@39
|
68 TextEntryMetaFunctions.GetMembers ["height"] = gmember_height
|
|
Tercio@39
|
69 TextEntryMetaFunctions.GetMembers ["text"] = gmember_text
|
|
Tercio@11
|
70
|
|
Tercio@11
|
71 TextEntryMetaFunctions.__index = function (_table, _member_requested)
|
|
Tercio@39
|
72 local func = TextEntryMetaFunctions.GetMembers [_member_requested]
|
|
Tercio@11
|
73 if (func) then
|
|
Tercio@11
|
74 return func (_table, _member_requested)
|
|
Tercio@11
|
75 end
|
|
Tercio@11
|
76
|
|
Tercio@11
|
77 local fromMe = _rawget (_table, _member_requested)
|
|
Tercio@11
|
78 if (fromMe) then
|
|
Tercio@11
|
79 return fromMe
|
|
Tercio@11
|
80 end
|
|
Tercio@11
|
81
|
|
Tercio@11
|
82 return TextEntryMetaFunctions [_member_requested]
|
|
Tercio@11
|
83 end
|
|
Tercio@11
|
84
|
|
Tercio@11
|
85 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
86
|
|
Tercio@11
|
87 --> tooltip
|
|
Tercio@11
|
88 local smember_tooltip = function (_object, _value)
|
|
Tercio@11
|
89 return _object:SetTooltip (_value)
|
|
Tercio@11
|
90 end
|
|
Tercio@11
|
91 --> show
|
|
Tercio@11
|
92 local smember_show = function (_object, _value)
|
|
Tercio@11
|
93 if (_value) then
|
|
Tercio@11
|
94 return _object:Show()
|
|
Tercio@11
|
95 else
|
|
Tercio@11
|
96 return _object:Hide()
|
|
Tercio@11
|
97 end
|
|
Tercio@11
|
98 end
|
|
Tercio@11
|
99 --> hide
|
|
Tercio@11
|
100 local smember_hide = function (_object, _value)
|
|
Tercio@11
|
101 if (not _value) then
|
|
Tercio@11
|
102 return _object:Show()
|
|
Tercio@11
|
103 else
|
|
Tercio@11
|
104 return _object:Hide()
|
|
Tercio@11
|
105 end
|
|
Tercio@11
|
106 end
|
|
Tercio@11
|
107 --> frame width
|
|
Tercio@11
|
108 local smember_width = function (_object, _value)
|
|
Tercio@11
|
109 return _object.editbox:SetWidth (_value)
|
|
Tercio@11
|
110 end
|
|
Tercio@11
|
111 --> frame height
|
|
Tercio@11
|
112 local smember_height = function (_object, _value)
|
|
Tercio@11
|
113 return _object.editbox:SetHeight (_value)
|
|
Tercio@11
|
114 end
|
|
Tercio@11
|
115 --> set text
|
|
Tercio@11
|
116 local smember_text = function (_object, _value)
|
|
Tercio@11
|
117 return _object.editbox:SetText (_value)
|
|
Tercio@11
|
118 end
|
|
Tercio@11
|
119 --> set multiline
|
|
Tercio@11
|
120 local smember_multiline = function (_object, _value)
|
|
Tercio@11
|
121 if (_value) then
|
|
Tercio@11
|
122 return _object.editbox:SetMultiLine (true)
|
|
Tercio@11
|
123 else
|
|
Tercio@11
|
124 return _object.editbox:SetMultiLine (false)
|
|
Tercio@11
|
125 end
|
|
Tercio@11
|
126 end
|
|
Tercio@11
|
127 --> text horizontal pos
|
|
Tercio@11
|
128 local smember_horizontalpos = function (_object, _value)
|
|
Tercio@11
|
129 return _object.editbox:SetJustifyH (string.lower (_value))
|
|
Tercio@11
|
130 end
|
|
Tercio@11
|
131
|
|
Tercio@39
|
132 TextEntryMetaFunctions.SetMembers = TextEntryMetaFunctions.SetMembers or {}
|
|
Tercio@39
|
133 TextEntryMetaFunctions.SetMembers ["tooltip"] = smember_tooltip
|
|
Tercio@39
|
134 TextEntryMetaFunctions.SetMembers ["show"] = smember_show
|
|
Tercio@39
|
135 TextEntryMetaFunctions.SetMembers ["hide"] = smember_hide
|
|
Tercio@39
|
136 TextEntryMetaFunctions.SetMembers ["width"] = smember_width
|
|
Tercio@39
|
137 TextEntryMetaFunctions.SetMembers ["height"] = smember_height
|
|
Tercio@39
|
138 TextEntryMetaFunctions.SetMembers ["text"] = smember_text
|
|
Tercio@39
|
139 TextEntryMetaFunctions.SetMembers ["multiline"] = smember_multiline
|
|
Tercio@39
|
140 TextEntryMetaFunctions.SetMembers ["align"] = smember_horizontalpos
|
|
Tercio@11
|
141
|
|
Tercio@11
|
142 TextEntryMetaFunctions.__newindex = function (_table, _key, _value)
|
|
Tercio@39
|
143 local func = TextEntryMetaFunctions.SetMembers [_key]
|
|
Tercio@11
|
144 if (func) then
|
|
Tercio@11
|
145 return func (_table, _value)
|
|
Tercio@11
|
146 else
|
|
Tercio@11
|
147 return _rawset (_table, _key, _value)
|
|
Tercio@11
|
148 end
|
|
Tercio@11
|
149 end
|
|
Tercio@11
|
150
|
|
Tercio@11
|
151 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
152 --> methods
|
|
Tercio@39
|
153 local cleanfunction = function()end
|
|
Tercio@39
|
154 function TextEntryMetaFunctions:SetEnterFunction (func, param1, param2)
|
|
Tercio@39
|
155 if (func) then
|
|
Tercio@39
|
156 _rawset (self, "func", func)
|
|
Tercio@39
|
157 else
|
|
Tercio@39
|
158 _rawset (self, "func", cleanfunction)
|
|
Tercio@39
|
159 end
|
|
Tercio@39
|
160
|
|
Tercio@39
|
161 if (param1 ~= nil) then
|
|
Tercio@39
|
162 _rawset (self, "param1", param1)
|
|
Tercio@39
|
163 end
|
|
Tercio@39
|
164 if (param2 ~= nil) then
|
|
Tercio@39
|
165 _rawset (self, "param2", param2)
|
|
Tercio@39
|
166 end
|
|
Tercio@39
|
167 end
|
|
Tercio@11
|
168
|
|
Tercio@11
|
169 --> set point
|
|
Tercio@11
|
170 function TextEntryMetaFunctions:SetPoint (MyAnchor, SnapTo, HisAnchor, x, y, Width)
|
|
Tercio@11
|
171
|
|
Tercio@11
|
172 if (type (MyAnchor) == "boolean" and MyAnchor and self.space) then
|
|
Tercio@11
|
173 local textWidth = self.label:GetStringWidth()+2
|
|
Tercio@11
|
174 self.editbox:SetWidth (self.space - textWidth - 15)
|
|
Tercio@11
|
175 return
|
|
Tercio@11
|
176
|
|
Tercio@11
|
177 elseif (type (MyAnchor) == "boolean" and MyAnchor and not self.space) then
|
|
Tercio@11
|
178 self.space = self.label:GetStringWidth()+2 + self.editbox:GetWidth()
|
|
Tercio@11
|
179 end
|
|
Tercio@11
|
180
|
|
Tercio@11
|
181 if (Width) then
|
|
Tercio@11
|
182 self.space = Width
|
|
Tercio@11
|
183 end
|
|
Tercio@11
|
184
|
|
Tercio@11
|
185 MyAnchor, SnapTo, HisAnchor, x, y = DF:CheckPoints (MyAnchor, SnapTo, HisAnchor, x, y, self)
|
|
Tercio@11
|
186 if (not MyAnchor) then
|
|
Tercio@11
|
187 print ("Invalid parameter for SetPoint")
|
|
Tercio@11
|
188 return
|
|
Tercio@11
|
189 end
|
|
Tercio@11
|
190
|
|
Tercio@11
|
191 if (self.space) then
|
|
Tercio@11
|
192 self.label:ClearAllPoints()
|
|
Tercio@11
|
193 self.editbox:ClearAllPoints()
|
|
Tercio@11
|
194
|
|
Tercio@11
|
195 self.label:SetPoint (MyAnchor, SnapTo, HisAnchor, x, y)
|
|
Tercio@11
|
196 self.editbox:SetPoint ("left", self.label, "right", 2, 0)
|
|
Tercio@11
|
197
|
|
Tercio@11
|
198 local textWidth = self.label:GetStringWidth()+2
|
|
Tercio@11
|
199 self.editbox:SetWidth (self.space - textWidth - 15)
|
|
Tercio@11
|
200 else
|
|
Tercio@11
|
201 self.label:ClearAllPoints()
|
|
Tercio@11
|
202 self.editbox:ClearAllPoints()
|
|
Tercio@11
|
203 self.editbox:SetPoint (MyAnchor, SnapTo, HisAnchor, x, y)
|
|
Tercio@11
|
204 end
|
|
Tercio@11
|
205
|
|
Tercio@11
|
206 end
|
|
Tercio@11
|
207
|
|
Tercioo@29
|
208 function TextEntryMetaFunctions:SetText (text)
|
|
Tercioo@29
|
209 self.editbox:SetText (text)
|
|
Tercioo@29
|
210 end
|
|
Tercioo@29
|
211 function TextEntryMetaFunctions:GetText()
|
|
Tercioo@29
|
212 return self.editbox:GetText()
|
|
Tercioo@29
|
213 end
|
|
Tercioo@29
|
214
|
|
Tercio@11
|
215 --> frame levels
|
|
Tercio@11
|
216 function TextEntryMetaFunctions:GetFrameLevel()
|
|
Tercio@11
|
217 return self.editbox:GetFrameLevel()
|
|
Tercio@11
|
218 end
|
|
Tercio@11
|
219 function TextEntryMetaFunctions:SetFrameLevel (level, frame)
|
|
Tercio@11
|
220 if (not frame) then
|
|
Tercio@11
|
221 return self.editbox:SetFrameLevel (level)
|
|
Tercio@11
|
222 else
|
|
Tercio@11
|
223 local framelevel = frame:GetFrameLevel (frame) + level
|
|
Tercio@11
|
224 return self.editbox:SetFrameLevel (framelevel)
|
|
Tercio@11
|
225 end
|
|
Tercio@11
|
226 end
|
|
Tercio@11
|
227
|
|
Tercio@11
|
228 --> select all text
|
|
Tercio@11
|
229 function TextEntryMetaFunctions:SelectAll()
|
|
Tercio@11
|
230 self.editbox:HighlightText()
|
|
Tercio@11
|
231 end
|
|
Tercio@11
|
232
|
|
Tercio@11
|
233 --> set labal description
|
|
Tercio@11
|
234 function TextEntryMetaFunctions:SetLabelText (text)
|
|
Tercio@11
|
235 if (text) then
|
|
Tercio@11
|
236 self.label:SetText (text)
|
|
Tercio@11
|
237 else
|
|
Tercio@11
|
238 self.label:SetText ("")
|
|
Tercio@11
|
239 end
|
|
Tercio@11
|
240 self:SetPoint (true) --> refresh
|
|
Tercio@11
|
241 end
|
|
Tercio@11
|
242
|
|
Tercio@11
|
243 --> set tab order
|
|
Tercio@11
|
244 function TextEntryMetaFunctions:SetNext (nextbox)
|
|
Tercio@11
|
245 self.next = nextbox
|
|
Tercio@11
|
246 end
|
|
Tercio@11
|
247
|
|
Tercio@11
|
248 --> blink
|
|
Tercio@11
|
249 function TextEntryMetaFunctions:Blink()
|
|
Tercio@11
|
250 self.label:SetTextColor (1, .2, .2, 1)
|
|
Tercio@11
|
251 end
|
|
Tercio@11
|
252
|
|
Tercio@11
|
253 --> show & hide
|
|
Tercio@11
|
254 function TextEntryMetaFunctions:IsShown()
|
|
Tercio@11
|
255 return self.editbox:IsShown()
|
|
Tercio@11
|
256 end
|
|
Tercio@11
|
257 function TextEntryMetaFunctions:Show()
|
|
Tercio@11
|
258 return self.editbox:Show()
|
|
Tercio@11
|
259 end
|
|
Tercio@11
|
260 function TextEntryMetaFunctions:Hide()
|
|
Tercio@11
|
261 return self.editbox:Hide()
|
|
Tercio@11
|
262 end
|
|
Tercio@11
|
263
|
|
Tercio@11
|
264 -- tooltip
|
|
Tercio@11
|
265 function TextEntryMetaFunctions:SetTooltip (tooltip)
|
|
Tercio@11
|
266 if (tooltip) then
|
|
Tercio@11
|
267 return _rawset (self, "have_tooltip", tooltip)
|
|
Tercio@11
|
268 else
|
|
Tercio@11
|
269 return _rawset (self, "have_tooltip", nil)
|
|
Tercio@11
|
270 end
|
|
Tercio@11
|
271 end
|
|
Tercio@11
|
272 function TextEntryMetaFunctions:GetTooltip()
|
|
Tercio@11
|
273 return _rawget (self, "have_tooltip")
|
|
Tercio@11
|
274 end
|
|
Tercio@11
|
275
|
|
Tercio@11
|
276 --> hooks
|
|
Tercio@11
|
277 function TextEntryMetaFunctions:Enable()
|
|
Tercio@11
|
278 if (not self.editbox:IsEnabled()) then
|
|
Tercio@11
|
279 self.editbox:Enable()
|
|
Tercio@11
|
280 self.editbox:SetBackdropBorderColor (unpack (self.enabled_border_color))
|
|
Tercio@11
|
281 self.editbox:SetBackdropColor (unpack (self.enabled_backdrop_color))
|
|
Tercio@11
|
282 self.editbox:SetTextColor (unpack (self.enabled_text_color))
|
|
Tercio@22
|
283 if (self.editbox.borderframe) then
|
|
Tercio@22
|
284 self.editbox.borderframe:SetBackdropColor (unpack (self.editbox.borderframe.onleave_backdrop))
|
|
Tercio@22
|
285 end
|
|
Tercio@11
|
286 end
|
|
Tercio@11
|
287 end
|
|
Tercio@11
|
288
|
|
Tercio@11
|
289 function TextEntryMetaFunctions:Disable()
|
|
Tercio@11
|
290 if (self.editbox:IsEnabled()) then
|
|
Tercio@11
|
291 self.enabled_border_color = {self.editbox:GetBackdropBorderColor()}
|
|
Tercio@11
|
292 self.enabled_backdrop_color = {self.editbox:GetBackdropColor()}
|
|
Tercio@11
|
293 self.enabled_text_color = {self.editbox:GetTextColor()}
|
|
Tercio@11
|
294
|
|
Tercio@11
|
295 self.editbox:Disable()
|
|
Tercio@11
|
296
|
|
Tercio@11
|
297 self.editbox:SetBackdropBorderColor (.5, .5, .5, .5)
|
|
Tercio@11
|
298 self.editbox:SetBackdropColor (.5, .5, .5, .5)
|
|
Tercio@11
|
299 self.editbox:SetTextColor (.5, .5, .5, .5)
|
|
Tercio@22
|
300
|
|
Tercio@22
|
301 if (self.editbox.borderframe) then
|
|
Tercio@22
|
302 self.editbox.borderframe:SetBackdropColor (.5, .5, .5, .5)
|
|
Tercio@22
|
303 end
|
|
Tercio@11
|
304 end
|
|
Tercio@11
|
305 end
|
|
Tercio@11
|
306
|
|
Tercio@11
|
307 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@39
|
308 --> scripts and hooks
|
|
Tercio@39
|
309
|
|
Tercio@11
|
310 local OnEnter = function (textentry)
|
|
Tercio@39
|
311 local capsule = textentry.MyObject
|
|
Tercio@39
|
312
|
|
Tercio@39
|
313 local kill = capsule:RunHooksForWidget ("OnEnter", textentry, capsule)
|
|
Tercio@39
|
314 if (kill) then
|
|
Tercio@39
|
315 return
|
|
Tercio@39
|
316 end
|
|
Tercio@11
|
317
|
|
Tercio@39
|
318 if (capsule.have_tooltip) then
|
|
Tercio@11
|
319 GameCooltip2:Preset (2)
|
|
Tercio@39
|
320 GameCooltip2:AddLine (capsule.have_tooltip)
|
|
Tercio@11
|
321 GameCooltip2:ShowCooltip (textentry, "tooltip")
|
|
Tercio@11
|
322 end
|
|
Tercio@11
|
323
|
|
Tercio@11
|
324 textentry.mouse_over = true
|
|
Tercio@11
|
325
|
|
Tercio@11
|
326 if (textentry:IsEnabled()) then
|
|
Tercio@11
|
327 textentry.current_bordercolor = textentry.current_bordercolor or {textentry:GetBackdropBorderColor()}
|
|
Tercio@11
|
328 textentry:SetBackdropBorderColor (1, 1, 1, 1)
|
|
Tercio@11
|
329 end
|
|
Tercio@11
|
330 end
|
|
Tercio@11
|
331
|
|
Tercio@11
|
332 local OnLeave = function (textentry)
|
|
Tercio@39
|
333 local capsule = textentry.MyObject
|
|
Tercio@39
|
334
|
|
Tercio@39
|
335 local kill = capsule:RunHooksForWidget ("OnLeave", textentry, capsule)
|
|
Tercio@39
|
336 if (kill) then
|
|
Tercio@39
|
337 return
|
|
Tercio@11
|
338 end
|
|
Tercio@39
|
339
|
|
Tercio@11
|
340 if (textentry.MyObject.have_tooltip) then
|
|
Tercio@11
|
341 GameCooltip2:ShowMe (false)
|
|
Tercio@11
|
342 end
|
|
Tercio@11
|
343
|
|
Tercio@11
|
344 textentry.mouse_over = false
|
|
Tercio@11
|
345
|
|
Tercio@11
|
346 if (textentry:IsEnabled()) then
|
|
Tercio@11
|
347 textentry:SetBackdropBorderColor (unpack (textentry.current_bordercolor))
|
|
Tercio@11
|
348 end
|
|
Tercio@11
|
349 end
|
|
Tercio@11
|
350
|
|
Tercio@11
|
351 local OnHide = function (textentry)
|
|
Tercio@39
|
352 local capsule = textentry.MyObject
|
|
Tercio@39
|
353
|
|
Tercio@39
|
354 local kill = capsule:RunHooksForWidget ("OnHide", textentry, capsule)
|
|
Tercio@39
|
355 if (kill) then
|
|
Tercio@39
|
356 return
|
|
Tercio@11
|
357 end
|
|
Tercio@11
|
358 end
|
|
Tercio@11
|
359
|
|
Tercio@11
|
360 local OnShow = function (textentry)
|
|
Tercio@39
|
361 local capsule = textentry.MyObject
|
|
Tercio@39
|
362
|
|
Tercio@39
|
363 local kill = capsule:RunHooksForWidget ("OnShow", textentry, capsule)
|
|
Tercio@39
|
364 if (kill) then
|
|
Tercio@39
|
365 return
|
|
Tercio@11
|
366 end
|
|
Tercio@11
|
367 end
|
|
Tercio@11
|
368
|
|
Tercio@39
|
369 local OnEnterPressed = function (textentry, byScript)
|
|
Tercio@39
|
370 local capsule = textentry.MyObject
|
|
Tercio@11
|
371
|
|
Tercio@39
|
372 local kill = capsule:RunHooksForWidget ("OnEnterPressed", textentry, capsule)
|
|
Tercio@39
|
373 if (kill) then
|
|
Tercio@39
|
374 return
|
|
Tercio@11
|
375 end
|
|
Tercio@11
|
376
|
|
Tercio@11
|
377 local texto = DF:trim (textentry:GetText())
|
|
Tercio@11
|
378 if (_string_len (texto) > 0) then
|
|
Tercio@11
|
379 textentry.text = texto
|
|
Tercio@11
|
380 if (textentry.MyObject.func) then
|
|
Tercio@11
|
381 textentry.MyObject.func (textentry.MyObject.param1, textentry.MyObject.param2, texto, textentry, byScript or textentry)
|
|
Tercio@11
|
382 end
|
|
Tercio@11
|
383 else
|
|
Tercio@11
|
384 textentry:SetText ("")
|
|
Tercio@11
|
385 textentry.MyObject.currenttext = ""
|
|
Tercio@11
|
386 end
|
|
Tercio@11
|
387
|
|
Tercio@39
|
388 if (not capsule.NoClearFocusOnEnterPressed) then
|
|
Tercio@39
|
389 textentry.focuslost = true --> quando estiver editando e clicar em outra caixa
|
|
Tercio@39
|
390 textentry:ClearFocus()
|
|
Tercio@39
|
391
|
|
Tercio@39
|
392 if (textentry.MyObject.tab_on_enter and textentry.MyObject.next) then
|
|
Tercio@39
|
393 textentry.MyObject.next:SetFocus()
|
|
Tercio@39
|
394 end
|
|
Tercio@11
|
395 end
|
|
Tercio@11
|
396 end
|
|
Tercio@11
|
397
|
|
Tercio@11
|
398 local OnEscapePressed = function (textentry)
|
|
Tercio@39
|
399 local capsule = textentry.MyObject
|
|
Tercio@11
|
400
|
|
Tercio@39
|
401 local kill = capsule:RunHooksForWidget ("OnEscapePressed", textentry, capsule)
|
|
Tercio@39
|
402 if (kill) then
|
|
Tercio@39
|
403 return
|
|
Tercio@39
|
404 end
|
|
Tercio@39
|
405
|
|
Tercio@11
|
406 textentry.focuslost = true
|
|
Tercio@11
|
407 textentry:ClearFocus()
|
|
Tercio@11
|
408 end
|
|
Tercio@11
|
409
|
|
Tercio@39
|
410 local OnSpacePressed = function (textentry)
|
|
Tercio@39
|
411 local capsule = textentry.MyObject
|
|
Tercio@39
|
412
|
|
Tercio@39
|
413 local kill = capsule:RunHooksForWidget ("OnSpacePressed", textentry, capsule)
|
|
Tercio@39
|
414 if (kill) then
|
|
Tercio@39
|
415 return
|
|
Tercio@39
|
416 end
|
|
Tercio@39
|
417 end
|
|
Tercio@39
|
418
|
|
Tercio@11
|
419 local OnEditFocusLost = function (textentry)
|
|
Tercio@11
|
420
|
|
Tercio@39
|
421 local capsule = textentry.MyObject
|
|
Tercio@39
|
422
|
|
Tercio@11
|
423 if (textentry:IsShown()) then
|
|
Tercio@11
|
424
|
|
Tercio@39
|
425 local kill = capsule:RunHooksForWidget ("OnEditFocusLost", textentry, capsule)
|
|
Tercio@39
|
426 if (kill) then
|
|
Tercio@39
|
427 return
|
|
Tercio@11
|
428 end
|
|
Tercio@11
|
429
|
|
Tercio@11
|
430 if (not textentry.focuslost) then
|
|
Tercio@11
|
431 local texto = DF:trim (textentry:GetText())
|
|
Tercio@11
|
432 if (_string_len (texto) > 0) then
|
|
Tercio@11
|
433 textentry.MyObject.currenttext = texto
|
|
Tercio@11
|
434 if (textentry.MyObject.func) then
|
|
Tercio@11
|
435 textentry.MyObject.func (textentry.MyObject.param1, textentry.MyObject.param2, texto, textentry, nil)
|
|
Tercio@11
|
436 end
|
|
Tercio@11
|
437 else
|
|
Tercio@11
|
438 textentry:SetText ("")
|
|
Tercio@11
|
439 textentry.MyObject.currenttext = ""
|
|
Tercio@11
|
440 end
|
|
Tercio@11
|
441 else
|
|
Tercio@11
|
442 textentry.focuslost = false
|
|
Tercio@11
|
443 end
|
|
Tercio@11
|
444
|
|
Tercio@11
|
445 textentry.MyObject.label:SetTextColor (.8, .8, .8, 1)
|
|
Tercio@11
|
446
|
|
Tercio@11
|
447 end
|
|
Tercio@11
|
448 end
|
|
Tercio@11
|
449
|
|
Tercio@11
|
450 local OnEditFocusGained = function (textentry)
|
|
Tercio@39
|
451
|
|
Tercio@39
|
452 local capsule = textentry.MyObject
|
|
Tercio@39
|
453
|
|
Tercio@39
|
454 local kill = capsule:RunHooksForWidget ("OnEditFocusGained", textentry, capsule)
|
|
Tercio@39
|
455 if (kill) then
|
|
Tercio@39
|
456 return
|
|
Tercio@11
|
457 end
|
|
Tercio@39
|
458
|
|
Tercio@11
|
459 textentry.MyObject.label:SetTextColor (1, 1, 1, 1)
|
|
Tercio@11
|
460 end
|
|
Tercio@11
|
461
|
|
Tercio@39
|
462 local OnChar = function (textentry, char)
|
|
Tercio@39
|
463 local capsule = textentry.MyObject
|
|
Tercio@39
|
464
|
|
Tercio@39
|
465 local kill = capsule:RunHooksForWidget ("OnChar", textentry, char, capsule)
|
|
Tercio@39
|
466 if (kill) then
|
|
Tercio@39
|
467 return
|
|
Tercio@11
|
468 end
|
|
Tercio@11
|
469 end
|
|
Tercio@11
|
470
|
|
Tercio@11
|
471 local OnTextChanged = function (textentry, byUser)
|
|
Tercio@39
|
472 local capsule = textentry.MyObject
|
|
Tercio@39
|
473
|
|
Tercio@39
|
474 local kill = capsule:RunHooksForWidget ("OnTextChanged", textentry, byUser, capsule)
|
|
Tercio@39
|
475 if (kill) then
|
|
Tercio@39
|
476 return
|
|
Tercio@11
|
477 end
|
|
Tercio@11
|
478 end
|
|
Tercio@11
|
479
|
|
Tercio@11
|
480 local OnTabPressed = function (textentry)
|
|
Tercio@39
|
481
|
|
Tercio@39
|
482 local capsule = textentry.MyObject
|
|
Tercio@39
|
483
|
|
Tercio@39
|
484 local kill = capsule:RunHooksForWidget ("OnTabPressed", textentry, byUser, capsule)
|
|
Tercio@39
|
485 if (kill) then
|
|
Tercio@39
|
486 return
|
|
Tercio@11
|
487 end
|
|
Tercio@11
|
488
|
|
Tercio@11
|
489 if (textentry.MyObject.next) then
|
|
Tercio@11
|
490 OnEnterPressed (textentry, false)
|
|
Tercio@11
|
491 textentry.MyObject.next:SetFocus()
|
|
Tercio@11
|
492 end
|
|
Tercio@11
|
493 end
|
|
Tercio@11
|
494
|
|
Tercio@11
|
495 function TextEntryMetaFunctions:PressEnter (byScript)
|
|
Tercio@11
|
496 OnEnterPressed (self.editbox, byScript)
|
|
Tercio@11
|
497 end
|
|
Tercio@11
|
498
|
|
Tercio@11
|
499 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@22
|
500
|
|
Tercio@22
|
501 function TextEntryMetaFunctions:SetTemplate (template)
|
|
Tercio@22
|
502 if (template.width) then
|
|
Tercioo@29
|
503 self.editbox:SetWidth (template.width)
|
|
Tercio@22
|
504 end
|
|
Tercio@22
|
505 if (template.height) then
|
|
Tercioo@29
|
506 self.editbox:SetHeight (template.height)
|
|
Tercio@22
|
507 end
|
|
Tercio@22
|
508
|
|
Tercio@22
|
509 if (template.backdrop) then
|
|
Tercioo@29
|
510 self.editbox:SetBackdrop (template.backdrop)
|
|
Tercio@22
|
511 end
|
|
Tercio@22
|
512 if (template.backdropcolor) then
|
|
Tercio@22
|
513 local r, g, b, a = DF:ParseColors (template.backdropcolor)
|
|
Tercioo@29
|
514 self.editbox:SetBackdropColor (r, g, b, a)
|
|
Tercio@22
|
515 self.onleave_backdrop = {r, g, b, a}
|
|
Tercio@22
|
516 end
|
|
Tercio@22
|
517 if (template.backdropbordercolor) then
|
|
Tercio@22
|
518 local r, g, b, a = DF:ParseColors (template.backdropbordercolor)
|
|
Tercioo@29
|
519 self.editbox:SetBackdropBorderColor (r, g, b, a)
|
|
Tercio@22
|
520 self.editbox.current_bordercolor[1] = r
|
|
Tercio@22
|
521 self.editbox.current_bordercolor[2] = g
|
|
Tercio@22
|
522 self.editbox.current_bordercolor[3] = b
|
|
Tercio@22
|
523 self.editbox.current_bordercolor[4] = a
|
|
Tercio@22
|
524 self.onleave_backdrop_border_color = {r, g, b, a}
|
|
Tercio@22
|
525 end
|
|
Tercio@22
|
526 end
|
|
Tercio@22
|
527
|
|
Tercio@22
|
528 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
529 --> object constructor
|
|
Tercio@11
|
530
|
|
Tercio@22
|
531 function DF:CreateTextEntry (parent, func, w, h, member, name, with_label, entry_template, label_template)
|
|
Tercio@22
|
532 return DF:NewTextEntry (parent, parent, name, member, w, h, func, nil, nil, nil, with_label, entry_template, label_template)
|
|
Tercio@11
|
533 end
|
|
Tercio@11
|
534
|
|
Tercio@22
|
535 function DF:NewTextEntry (parent, container, name, member, w, h, func, param1, param2, space, with_label, entry_template, label_template)
|
|
Tercio@11
|
536
|
|
Tercio@11
|
537 if (not name) then
|
|
Tercio@11
|
538 name = "DetailsFrameworkTextEntryNumber" .. DF.TextEntryCounter
|
|
Tercio@11
|
539 DF.TextEntryCounter = DF.TextEntryCounter + 1
|
|
Tercio@11
|
540
|
|
Tercio@11
|
541 elseif (not parent) then
|
|
Tercioo@29
|
542 return error ("Details! FrameWork: parent not found.", 2)
|
|
Tercio@11
|
543 end
|
|
Tercio@11
|
544
|
|
Tercio@11
|
545 if (not container) then
|
|
Tercio@11
|
546 container = parent
|
|
Tercio@11
|
547 end
|
|
Tercio@11
|
548
|
|
Tercio@11
|
549 if (name:find ("$parent")) then
|
|
Tercioo@29
|
550 local parentName = DF.GetParentName (parent)
|
|
Tercioo@29
|
551 name = name:gsub ("$parent", parentName)
|
|
Tercio@11
|
552 end
|
|
Tercio@11
|
553
|
|
Tercio@11
|
554 local TextEntryObject = {type = "textentry", dframework = true}
|
|
Tercio@11
|
555
|
|
Tercio@11
|
556 if (member) then
|
|
Tercio@11
|
557 parent [member] = TextEntryObject
|
|
Tercio@11
|
558 end
|
|
Tercio@11
|
559
|
|
Tercio@11
|
560 if (parent.dframework) then
|
|
Tercio@11
|
561 parent = parent.widget
|
|
Tercio@11
|
562 end
|
|
Tercio@11
|
563 if (container.dframework) then
|
|
Tercio@11
|
564 container = container.widget
|
|
Tercio@11
|
565 end
|
|
Tercio@11
|
566
|
|
Tercio@11
|
567 --> default members:
|
|
Tercio@11
|
568 --> hooks
|
|
Tercio@11
|
569 TextEntryObject.OnEnterHook = nil
|
|
Tercio@11
|
570 TextEntryObject.OnLeaveHook = nil
|
|
Tercio@11
|
571 TextEntryObject.OnHideHook = nil
|
|
Tercio@11
|
572 TextEntryObject.OnShowHook = nil
|
|
Tercio@11
|
573 TextEntryObject.OnEnterPressedHook = nil
|
|
Tercio@11
|
574 TextEntryObject.OnEscapePressedHook = nil
|
|
Tercio@11
|
575 TextEntryObject.OnEditFocusGainedHook = nil
|
|
Tercio@11
|
576 TextEntryObject.OnEditFocusLostHook = nil
|
|
Tercio@11
|
577 TextEntryObject.OnCharHook = nil
|
|
Tercio@11
|
578 TextEntryObject.OnTextChangedHook = nil
|
|
Tercio@11
|
579 TextEntryObject.OnTabPressedHook = nil
|
|
Tercio@11
|
580
|
|
Tercio@11
|
581 --> misc
|
|
Tercio@11
|
582 TextEntryObject.container = container
|
|
Tercio@11
|
583 TextEntryObject.have_tooltip = nil
|
|
Tercio@11
|
584
|
|
Tercio@11
|
585 TextEntryObject.editbox = CreateFrame ("EditBox", name, parent, "DetailsFrameworkEditBoxTemplate2")
|
|
Tercio@11
|
586 TextEntryObject.widget = TextEntryObject.editbox
|
|
Tercio@11
|
587
|
|
Tercio@11
|
588 TextEntryObject.editbox:SetTextInsets (3, 0, 0, -3)
|
|
Tercio@11
|
589
|
|
Tercio@11
|
590 if (not APITextEntryFunctions) then
|
|
Tercio@11
|
591 APITextEntryFunctions = true
|
|
Tercio@11
|
592 local idx = getmetatable (TextEntryObject.editbox).__index
|
|
Tercio@11
|
593 for funcName, funcAddress in pairs (idx) do
|
|
Tercio@11
|
594 if (not TextEntryMetaFunctions [funcName]) then
|
|
Tercio@11
|
595 TextEntryMetaFunctions [funcName] = function (object, ...)
|
|
Tercio@20
|
596 local x = loadstring ( "return _G['"..object.editbox:GetName().."']:"..funcName.."(...)")
|
|
Tercio@11
|
597 return x (...)
|
|
Tercio@11
|
598 end
|
|
Tercio@11
|
599 end
|
|
Tercio@11
|
600 end
|
|
Tercio@11
|
601 end
|
|
Tercio@11
|
602
|
|
Tercio@11
|
603 TextEntryObject.editbox.MyObject = TextEntryObject
|
|
Tercio@11
|
604
|
|
Tercio@11
|
605 if (not w and space) then
|
|
Tercio@11
|
606 w = space
|
|
Tercio@11
|
607 elseif (w and space) then
|
|
Tercio@11
|
608 if (DF.debug) then
|
|
Tercio@39
|
609 --print ("warning: you are using width and space, try use only space for better results.")
|
|
Tercio@11
|
610 end
|
|
Tercio@11
|
611 end
|
|
Tercio@11
|
612
|
|
Tercio@11
|
613 TextEntryObject.editbox:SetWidth (w)
|
|
Tercio@11
|
614 TextEntryObject.editbox:SetHeight (h)
|
|
Tercio@11
|
615
|
|
Tercio@11
|
616 TextEntryObject.editbox:SetJustifyH ("center")
|
|
Tercio@11
|
617 TextEntryObject.editbox:EnableMouse (true)
|
|
Tercio@11
|
618 TextEntryObject.editbox:SetText ("")
|
|
Tercio@11
|
619
|
|
Tercio@11
|
620 TextEntryObject.editbox:SetAutoFocus (false)
|
|
Tercio@11
|
621 TextEntryObject.editbox:SetFontObject ("GameFontHighlightSmall")
|
|
Tercio@11
|
622
|
|
Tercio@11
|
623 TextEntryObject.editbox.current_bordercolor = {1, 1, 1, 0.7}
|
|
Tercio@11
|
624 TextEntryObject.editbox:SetBackdropBorderColor (1, 1, 1, 0.7)
|
|
Tercio@11
|
625 TextEntryObject.enabled_border_color = {TextEntryObject.editbox:GetBackdropBorderColor()}
|
|
Tercio@11
|
626 TextEntryObject.enabled_backdrop_color = {TextEntryObject.editbox:GetBackdropColor()}
|
|
Tercio@11
|
627 TextEntryObject.enabled_text_color = {TextEntryObject.editbox:GetTextColor()}
|
|
Tercio@22
|
628 TextEntryObject.onleave_backdrop = {TextEntryObject.editbox:GetBackdropColor()}
|
|
Tercio@22
|
629 TextEntryObject.onleave_backdrop_border_color = {TextEntryObject.editbox:GetBackdropBorderColor()}
|
|
Tercio@11
|
630
|
|
Tercio@11
|
631 TextEntryObject.func = func
|
|
Tercio@11
|
632 TextEntryObject.param1 = param1
|
|
Tercio@11
|
633 TextEntryObject.param2 = param2
|
|
Tercio@11
|
634 TextEntryObject.next = nil
|
|
Tercio@11
|
635 TextEntryObject.space = space
|
|
Tercio@11
|
636 TextEntryObject.tab_on_enter = false
|
|
Tercio@11
|
637
|
|
Tercio@11
|
638 TextEntryObject.label = _G [name .. "_Desc"]
|
|
Tercio@11
|
639
|
|
Tercio@11
|
640 TextEntryObject.editbox:SetBackdrop ({bgFile = DF.folder .. "background", tileSize = 64, edgeFile = DF.folder .. "border_2", edgeSize = 10, insets = {left = 1, right = 1, top = 1, bottom = 1}})
|
|
Tercio@11
|
641
|
|
Tercio@11
|
642 --> hooks
|
|
Tercio@39
|
643
|
|
Tercio@39
|
644 TextEntryObject.HookList = {
|
|
Tercio@39
|
645 OnEnter = {},
|
|
Tercio@39
|
646 OnLeave = {},
|
|
Tercio@39
|
647 OnHide = {},
|
|
Tercio@39
|
648 OnShow = {},
|
|
Tercio@39
|
649 OnEnterPressed = {},
|
|
Tercio@39
|
650 OnEscapePressed = {},
|
|
Tercio@39
|
651 OnSpacePressed = {},
|
|
Tercio@39
|
652 OnEditFocusLost = {},
|
|
Tercio@39
|
653 OnEditFocusGained = {},
|
|
Tercio@39
|
654 OnChar = {},
|
|
Tercio@39
|
655 OnTextChanged = {},
|
|
Tercio@39
|
656 OnTabPressed = {},
|
|
Tercio@39
|
657 }
|
|
Tercio@40
|
658
|
|
Tercio@11
|
659 TextEntryObject.editbox:SetScript ("OnEnter", OnEnter)
|
|
Tercio@11
|
660 TextEntryObject.editbox:SetScript ("OnLeave", OnLeave)
|
|
Tercio@11
|
661 TextEntryObject.editbox:SetScript ("OnHide", OnHide)
|
|
Tercio@11
|
662 TextEntryObject.editbox:SetScript ("OnShow", OnShow)
|
|
Tercio@11
|
663
|
|
Tercio@11
|
664 TextEntryObject.editbox:SetScript ("OnEnterPressed", OnEnterPressed)
|
|
Tercio@11
|
665 TextEntryObject.editbox:SetScript ("OnEscapePressed", OnEscapePressed)
|
|
Tercio@39
|
666 TextEntryObject.editbox:SetScript ("OnSpacePressed", OnSpacePressed)
|
|
Tercio@11
|
667 TextEntryObject.editbox:SetScript ("OnEditFocusLost", OnEditFocusLost)
|
|
Tercio@11
|
668 TextEntryObject.editbox:SetScript ("OnEditFocusGained", OnEditFocusGained)
|
|
Tercio@11
|
669 TextEntryObject.editbox:SetScript ("OnChar", OnChar)
|
|
Tercio@11
|
670 TextEntryObject.editbox:SetScript ("OnTextChanged", OnTextChanged)
|
|
Tercio@11
|
671 TextEntryObject.editbox:SetScript ("OnTabPressed", OnTabPressed)
|
|
Tercio@11
|
672
|
|
Tercio@11
|
673 _setmetatable (TextEntryObject, TextEntryMetaFunctions)
|
|
Tercio@11
|
674
|
|
Tercio@22
|
675 if (with_label) then
|
|
Tercio@22
|
676 local label = DF:CreateLabel (TextEntryObject.editbox, with_label, nil, nil, nil, "label", nil, "overlay")
|
|
Tercio@22
|
677 label.text = with_label
|
|
Tercio@22
|
678 TextEntryObject.editbox:SetPoint ("left", label.widget, "right", 2, 0)
|
|
Tercio@22
|
679 if (label_template) then
|
|
Tercio@22
|
680 label:SetTemplate (label_template)
|
|
Tercio@22
|
681 end
|
|
Tercio@22
|
682 with_label = label
|
|
Tercio@22
|
683 end
|
|
Tercio@11
|
684
|
|
Tercio@22
|
685 if (entry_template) then
|
|
Tercio@22
|
686 TextEntryObject:SetTemplate (entry_template)
|
|
Tercio@22
|
687 end
|
|
Tercio@22
|
688
|
|
Tercio@22
|
689 return TextEntryObject, with_label
|
|
Tercio@22
|
690
|
|
Tercio@22
|
691 end
|
|
Tercio@22
|
692
|
|
Tercio@22
|
693 function DF:NewSpellEntry (parent, func, w, h, param1, param2, member, name)
|
|
Tercio@22
|
694 local editbox = DF:NewTextEntry (parent, parent, name, member, w, h, func, param1, param2)
|
|
Tercio@22
|
695
|
|
Tercio@39
|
696 -- editbox:SetHook ("OnEditFocusGained", SpellEntryOnEditFocusGained)
|
|
Tercio@39
|
697 -- editbox:SetHook ("OnTextChanged", SpellEntryOnTextChanged)
|
|
Tercio@22
|
698
|
|
Tercio@22
|
699 return editbox
|
|
Tercio@11
|
700 end
|
|
Tercio@11
|
701
|
|
Tercio@11
|
702 local function_gettext = function (self)
|
|
Tercio@11
|
703 return self.editbox:GetText()
|
|
Tercio@11
|
704 end
|
|
Tercio@11
|
705 local function_settext = function (self, text)
|
|
Tercio@11
|
706 return self.editbox:SetText (text)
|
|
Tercio@11
|
707 end
|
|
Tercio@11
|
708 local function_clearfocus = function (self)
|
|
Tercio@11
|
709 return self.editbox:ClearFocus()
|
|
Tercio@11
|
710 end
|
|
Tercio@11
|
711 local function_setfocus = function (self)
|
|
Tercio@11
|
712 return self.editbox:SetFocus (true)
|
|
Tercio@11
|
713 end
|
|
Tercio@11
|
714
|
|
Tercio@11
|
715 function DF:NewSpecialLuaEditorEntry (parent, w, h, member, name, nointent)
|
|
Tercio@11
|
716
|
|
Tercio@11
|
717 if (name:find ("$parent")) then
|
|
Tercioo@29
|
718 local parentName = DF.GetParentName (parent)
|
|
Tercioo@29
|
719 name = name:gsub ("$parent", parentName)
|
|
Tercio@11
|
720 end
|
|
Tercio@11
|
721
|
|
Tercio@11
|
722 local borderframe = CreateFrame ("Frame", name, parent)
|
|
Tercio@11
|
723 borderframe:SetSize (w, h)
|
|
Tercio@11
|
724
|
|
Tercio@11
|
725 if (member) then
|
|
Tercio@11
|
726 parent [member] = borderframe
|
|
Tercio@11
|
727 end
|
|
Tercio@11
|
728
|
|
Tercio@11
|
729 local scrollframe = CreateFrame ("ScrollFrame", name, borderframe, "DetailsFrameworkEditBoxMultiLineTemplate")
|
|
Tercio@11
|
730
|
|
Tercio@11
|
731 scrollframe:SetScript ("OnSizeChanged", function (self)
|
|
Tercio@11
|
732 scrollframe.editbox:SetSize (self:GetSize())
|
|
Tercio@11
|
733 end)
|
|
Tercio@11
|
734
|
|
Tercio@11
|
735 scrollframe:SetPoint ("topleft", borderframe, "topleft", 10, -10)
|
|
Tercio@11
|
736 scrollframe:SetPoint ("bottomright", borderframe, "bottomright", -30, 10)
|
|
Tercio@11
|
737
|
|
Tercio@11
|
738 scrollframe.editbox:SetMultiLine (true)
|
|
Tercio@11
|
739 scrollframe.editbox:SetJustifyH ("left")
|
|
Tercio@11
|
740 scrollframe.editbox:SetJustifyV ("top")
|
|
Tercio@11
|
741 scrollframe.editbox:SetMaxBytes (1024000)
|
|
Tercio@11
|
742 scrollframe.editbox:SetMaxLetters (128000)
|
|
Tercio@11
|
743
|
|
Tercio@11
|
744 borderframe.GetText = function_gettext
|
|
Tercio@11
|
745 borderframe.SetText = function_settext
|
|
Tercio@11
|
746 borderframe.ClearFocus = function_clearfocus
|
|
Tercio@11
|
747 borderframe.SetFocus = function_setfocus
|
|
Tercio@11
|
748
|
|
Tercio@22
|
749 borderframe.Enable = TextEntryMetaFunctions.Enable
|
|
Tercio@22
|
750 borderframe.Disable = TextEntryMetaFunctions.Disable
|
|
Tercio@22
|
751
|
|
Tercio@22
|
752 borderframe.SetTemplate = TextEntryMetaFunctions.SetTemplate
|
|
Tercio@22
|
753
|
|
Tercio@11
|
754 if (not nointent) then
|
|
Tercio@11
|
755 IndentationLib.enable (scrollframe.editbox, nil, 4)
|
|
Tercio@11
|
756 end
|
|
Tercio@11
|
757
|
|
Tercio@11
|
758 borderframe:SetBackdrop ({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]],
|
|
Tercio@11
|
759 tile = 1, tileSize = 16, edgeSize = 16, insets = {left = 5, right = 5, top = 5, bottom = 5}})
|
|
Tercio@22
|
760
|
|
Tercio@22
|
761 scrollframe.editbox.current_bordercolor = {1, 1, 1, 0.7}
|
|
Tercio@22
|
762 borderframe:SetBackdropBorderColor (1, 1, 1, 0.7)
|
|
Tercio@11
|
763 borderframe:SetBackdropColor (0.090195, 0.090195, 0.188234, 1)
|
|
Tercio@22
|
764
|
|
Tercio@22
|
765 borderframe.enabled_border_color = {borderframe:GetBackdropBorderColor()}
|
|
Tercio@22
|
766 borderframe.enabled_backdrop_color = {borderframe:GetBackdropColor()}
|
|
Tercio@22
|
767 borderframe.enabled_text_color = {scrollframe.editbox:GetTextColor()}
|
|
Tercio@22
|
768
|
|
Tercio@22
|
769 borderframe.onleave_backdrop = {scrollframe.editbox:GetBackdropColor()}
|
|
Tercio@22
|
770 borderframe.onleave_backdrop_border_color = {scrollframe.editbox:GetBackdropBorderColor()}
|
|
Tercio@11
|
771
|
|
Tercio@11
|
772 borderframe.scroll = scrollframe
|
|
Tercio@11
|
773 borderframe.editbox = scrollframe.editbox
|
|
Tercio@22
|
774 borderframe.editbox.borderframe = borderframe
|
|
Tercio@11
|
775
|
|
Tercio@11
|
776 return borderframe
|
|
Tercio@39
|
777 end
|
|
Tercio@39
|
778
|
|
Tercio@39
|
779
|
|
Tercio@39
|
780 ------------------------------------------------------------------------------------
|
|
Tercio@39
|
781 --auto complete
|
|
Tercio@39
|
782
|
|
Tercio@39
|
783 -- block -------------------
|
|
Tercio@39
|
784 --code author Saiket from http://www.wowinterface.com/forums/showpost.php?p=245759&postcount=6
|
|
Tercio@39
|
785 --- @return StartPos, EndPos of highlight in this editbox.
|
|
Tercio@39
|
786 local function GetTextHighlight ( self )
|
|
Tercio@39
|
787 local Text, Cursor = self:GetText(), self:GetCursorPosition();
|
|
Tercio@39
|
788 self:Insert( "" ); -- Delete selected text
|
|
Tercio@39
|
789 local TextNew, CursorNew = self:GetText(), self:GetCursorPosition();
|
|
Tercio@39
|
790 -- Restore previous text
|
|
Tercio@39
|
791 self:SetText( Text );
|
|
Tercio@39
|
792 self:SetCursorPosition( Cursor );
|
|
Tercio@39
|
793 local Start, End = CursorNew, #Text - ( #TextNew - CursorNew );
|
|
Tercio@39
|
794 self:HighlightText( Start, End );
|
|
Tercio@39
|
795 return Start, End;
|
|
Tercio@39
|
796 end
|
|
Tercio@39
|
797 local StripColors;
|
|
Tercio@39
|
798 do
|
|
Tercio@39
|
799 local CursorPosition, CursorDelta;
|
|
Tercio@39
|
800 --- Callback for gsub to remove unescaped codes.
|
|
Tercio@39
|
801 local function StripCodeGsub ( Escapes, Code, End )
|
|
Tercio@39
|
802 if ( #Escapes % 2 == 0 ) then -- Doesn't escape Code
|
|
Tercio@39
|
803 if ( CursorPosition and CursorPosition >= End - 1 ) then
|
|
Tercio@39
|
804 CursorDelta = CursorDelta - #Code;
|
|
Tercio@39
|
805 end
|
|
Tercio@39
|
806 return Escapes;
|
|
Tercio@39
|
807 end
|
|
Tercio@39
|
808 end
|
|
Tercio@39
|
809 --- Removes a single escape sequence.
|
|
Tercio@39
|
810 local function StripCode ( Pattern, Text, OldCursor )
|
|
Tercio@39
|
811 CursorPosition, CursorDelta = OldCursor, 0;
|
|
Tercio@39
|
812 return Text:gsub( Pattern, StripCodeGsub ), OldCursor and CursorPosition + CursorDelta;
|
|
Tercio@39
|
813 end
|
|
Tercio@39
|
814 --- Strips Text of all color escape sequences.
|
|
Tercio@39
|
815 -- @param Cursor Optional cursor position to keep track of.
|
|
Tercio@39
|
816 -- @return Stripped text, and the updated cursor position if Cursor was given.
|
|
Tercio@39
|
817 function StripColors ( Text, Cursor )
|
|
Tercio@39
|
818 Text, Cursor = StripCode( "(|*)(|c%x%x%x%x%x%x%x%x)()", Text, Cursor );
|
|
Tercio@39
|
819 return StripCode( "(|*)(|r)()", Text, Cursor );
|
|
Tercio@39
|
820 end
|
|
Tercio@39
|
821 end
|
|
Tercio@39
|
822
|
|
Tercio@39
|
823 local COLOR_END = "|r";
|
|
Tercio@39
|
824 --- Wraps this editbox's selected text with the given color.
|
|
Tercio@39
|
825 local function ColorSelection ( self, ColorCode )
|
|
Tercio@39
|
826 local Start, End = GetTextHighlight( self );
|
|
Tercio@39
|
827 local Text, Cursor = self:GetText(), self:GetCursorPosition();
|
|
Tercio@39
|
828 if ( Start == End ) then -- Nothing selected
|
|
Tercio@39
|
829 --Start, End = Cursor, Cursor; -- Wrap around cursor
|
|
Tercio@39
|
830 return; -- Wrapping the cursor in a color code and hitting backspace crashes the client!
|
|
Tercio@39
|
831 end
|
|
Tercio@39
|
832 -- Find active color code at the end of the selection
|
|
Tercio@39
|
833 local ActiveColor;
|
|
Tercio@39
|
834 if ( End < #Text ) then -- There is text to color after the selection
|
|
Tercio@39
|
835 local ActiveEnd;
|
|
Tercio@39
|
836 local CodeEnd, _, Escapes, Color = 0;
|
|
Tercio@39
|
837 while ( true ) do
|
|
Tercio@39
|
838 _, CodeEnd, Escapes, Color = Text:find( "(|*)(|c%x%x%x%x%x%x%x%x)", CodeEnd + 1 );
|
|
Tercio@39
|
839 if ( not CodeEnd or CodeEnd > End ) then
|
|
Tercio@39
|
840 break;
|
|
Tercio@39
|
841 end
|
|
Tercio@39
|
842 if ( #Escapes % 2 == 0 ) then -- Doesn't escape Code
|
|
Tercio@39
|
843 ActiveColor, ActiveEnd = Color, CodeEnd;
|
|
Tercio@39
|
844 end
|
|
Tercio@39
|
845 end
|
|
Tercio@39
|
846
|
|
Tercio@39
|
847 if ( ActiveColor ) then
|
|
Tercio@39
|
848 -- Check if color gets terminated before selection ends
|
|
Tercio@39
|
849 CodeEnd = 0;
|
|
Tercio@39
|
850 while ( true ) do
|
|
Tercio@39
|
851 _, CodeEnd, Escapes = Text:find( "(|*)|r", CodeEnd + 1 );
|
|
Tercio@39
|
852 if ( not CodeEnd or CodeEnd > End ) then
|
|
Tercio@39
|
853 break;
|
|
Tercio@39
|
854 end
|
|
Tercio@39
|
855 if ( CodeEnd > ActiveEnd and #Escapes % 2 == 0 ) then -- Terminates ActiveColor
|
|
Tercio@39
|
856 ActiveColor = nil;
|
|
Tercio@39
|
857 break;
|
|
Tercio@39
|
858 end
|
|
Tercio@39
|
859 end
|
|
Tercio@39
|
860 end
|
|
Tercio@39
|
861 end
|
|
Tercio@39
|
862
|
|
Tercio@39
|
863 local Selection = Text:sub( Start + 1, End );
|
|
Tercio@39
|
864 -- Remove color codes from the selection
|
|
Tercio@39
|
865 local Replacement, CursorReplacement = StripColors( Selection, Cursor - Start );
|
|
Tercio@39
|
866
|
|
Tercio@39
|
867 self:SetText( ( "" ):join(
|
|
Tercio@39
|
868 Text:sub( 1, Start ),
|
|
Tercio@39
|
869 ColorCode, Replacement, COLOR_END,
|
|
Tercio@39
|
870 ActiveColor or "", Text:sub( End + 1 )
|
|
Tercio@39
|
871 ) );
|
|
Tercio@39
|
872
|
|
Tercio@39
|
873 -- Restore cursor and highlight, adjusting for wrapper text
|
|
Tercio@39
|
874 Cursor = Start + CursorReplacement;
|
|
Tercio@39
|
875 if ( CursorReplacement > 0 ) then -- Cursor beyond start of color code
|
|
Tercio@39
|
876 Cursor = Cursor + #ColorCode;
|
|
Tercio@39
|
877 end
|
|
Tercio@39
|
878 if ( CursorReplacement >= #Replacement ) then -- Cursor beyond end of color
|
|
Tercio@39
|
879 Cursor = Cursor + #COLOR_END;
|
|
Tercio@39
|
880 end
|
|
Tercio@39
|
881
|
|
Tercio@39
|
882 self:SetCursorPosition( Cursor );
|
|
Tercio@39
|
883 -- Highlight selection and wrapper
|
|
Tercio@39
|
884 self:HighlightText( Start, #ColorCode + ( #Replacement - #Selection ) + #COLOR_END + End );
|
|
Tercio@39
|
885 end
|
|
Tercio@39
|
886 -- end of the block ---------------------
|
|
Tercio@39
|
887
|
|
Tercio@39
|
888 local get_last_word = function (self)
|
|
Tercio@39
|
889 self.lastword = ""
|
|
Tercio@39
|
890 local cursor_pos = self.editbox:GetCursorPosition()
|
|
Tercio@39
|
891 local text = self.editbox:GetText()
|
|
Tercio@39
|
892 for i = cursor_pos, 1, -1 do
|
|
Tercio@39
|
893 local character = text:sub (i, i)
|
|
Tercio@39
|
894 if (character:match ("%a")) then
|
|
Tercio@39
|
895 self.lastword = character .. self.lastword
|
|
Tercio@39
|
896 else
|
|
Tercio@39
|
897 break
|
|
Tercio@39
|
898 end
|
|
Tercio@39
|
899 end
|
|
Tercio@39
|
900 end
|
|
Tercio@39
|
901
|
|
Tercio@39
|
902 --On Text Changed
|
|
Tercio@39
|
903 local AutoComplete_OnTextChanged = function (editboxWidget, byUser, capsule)
|
|
Tercio@39
|
904 capsule = capsule or editboxWidget.MyObject
|
|
Tercio@39
|
905
|
|
Tercio@39
|
906 local chars_now = editboxWidget:GetText():len()
|
|
Tercio@39
|
907 if (not editboxWidget.ignore_textchange) then
|
|
Tercio@39
|
908 --> backspace
|
|
Tercio@39
|
909 if (chars_now == capsule.characters_count -1) then
|
|
Tercio@39
|
910 capsule.lastword = capsule.lastword:sub (1, capsule.lastword:len()-1)
|
|
Tercio@39
|
911 --> delete lots of text
|
|
Tercio@39
|
912 elseif (chars_now < capsule.characters_count) then
|
|
Tercio@39
|
913 --o auto complete selecionou outra palavra bem menor e caiu nesse filtro
|
|
Tercio@39
|
914 editboxWidget.end_selection = nil
|
|
Tercio@39
|
915 capsule:GetLastWord()
|
|
Tercio@39
|
916 end
|
|
Tercio@39
|
917 else
|
|
Tercio@39
|
918 editboxWidget.ignore_textchange = nil
|
|
Tercio@39
|
919 end
|
|
Tercio@39
|
920 capsule.characters_count = chars_now
|
|
Tercio@39
|
921 end
|
|
Tercio@39
|
922
|
|
Tercio@39
|
923 local AutoComplete_OnSpacePressed = function (editboxWidget, capsule)
|
|
Tercio@39
|
924 capsule = capsule or editboxWidget.MyObject
|
|
Tercio@39
|
925
|
|
Tercio@39
|
926 -- if (not gotMatch) then
|
|
Tercio@39
|
927 --editboxWidget.end_selection = nil
|
|
Tercio@39
|
928 -- end
|
|
Tercio@39
|
929 end
|
|
Tercio@39
|
930
|
|
Tercio@39
|
931 local AutoComplete_OnEscapePressed = function (editboxWidget)
|
|
Tercio@39
|
932 editboxWidget.end_selection = nil
|
|
Tercio@39
|
933 end
|
|
Tercio@39
|
934
|
|
Tercio@39
|
935 local AutoComplete_OnEnterPressed = function (editboxWidget)
|
|
Tercio@39
|
936
|
|
Tercio@39
|
937 local capsule = editboxWidget.MyObject
|
|
Tercio@39
|
938 if (editboxWidget.end_selection) then
|
|
Tercio@39
|
939 editboxWidget:SetCursorPosition (editboxWidget.end_selection)
|
|
Tercio@39
|
940 editboxWidget:HighlightText (0, 0)
|
|
Tercio@39
|
941 editboxWidget.end_selection = nil
|
|
Tercio@39
|
942 --editboxWidget:Insert (" ") --estava causando a adição de uma palavra a mais quando o próximo catactere for um espaço
|
|
Tercio@39
|
943 else
|
|
Tercio@39
|
944 if (editboxWidget:IsMultiLine()) then
|
|
Tercio@39
|
945 editboxWidget:Insert ("\n")
|
|
Tercio@39
|
946 --reseta a palavra se acabou de ganhar focus e apertou enter
|
|
Tercio@39
|
947 if (editboxWidget.focusGained) then
|
|
Tercio@39
|
948 capsule.lastword = ""
|
|
Tercio@39
|
949 editboxWidget.focusGained = nil
|
|
Tercio@39
|
950 end
|
|
Tercio@39
|
951 else
|
|
Tercio@39
|
952 editboxWidget:Insert ("")
|
|
Tercio@39
|
953 editboxWidget.focuslost = true
|
|
Tercio@39
|
954 editboxWidget:ClearFocus()
|
|
Tercio@39
|
955 end
|
|
Tercio@39
|
956 end
|
|
Tercio@39
|
957 capsule.lastword = ""
|
|
Tercio@39
|
958
|
|
Tercio@39
|
959 end
|
|
Tercio@39
|
960
|
|
Tercio@39
|
961 local AutoComplete_OnEditFocusGained = function (editboxWidget)
|
|
Tercio@39
|
962 local capsule = editboxWidget.MyObject
|
|
Tercio@39
|
963 capsule:GetLastWord()
|
|
Tercio@39
|
964 editboxWidget.end_selection = nil
|
|
Tercio@39
|
965 editboxWidget.focusGained = true
|
|
Tercio@39
|
966 capsule.characters_count = editboxWidget:GetText():len()
|
|
Tercio@39
|
967 end
|
|
Tercio@39
|
968
|
|
Tercio@39
|
969 local AutoComplete_OnChar = function (editboxWidget, char, capsule)
|
|
Tercio@39
|
970 if (char == "") then
|
|
Tercio@39
|
971 return
|
|
Tercio@39
|
972 end
|
|
Tercio@39
|
973
|
|
Tercio@39
|
974 capsule = capsule or editboxWidget.MyObject
|
|
Tercio@39
|
975 editboxWidget.end_selection = nil
|
|
Tercio@39
|
976
|
|
Tercio@39
|
977 if (editboxWidget.ignore_input) then
|
|
Tercio@39
|
978 return
|
|
Tercio@39
|
979 end
|
|
Tercio@39
|
980
|
|
Tercio@39
|
981 --reseta a palavra se acabou de ganhar focus e apertou espaço
|
|
Tercio@39
|
982 if (editboxWidget.focusGained and char == " ") then
|
|
Tercio@39
|
983 capsule.lastword = ""
|
|
Tercio@39
|
984 editboxWidget.focusGained = nil
|
|
Tercio@39
|
985 else
|
|
Tercio@39
|
986 editboxWidget.focusGained = nil
|
|
Tercio@39
|
987 end
|
|
Tercio@39
|
988
|
|
Tercio@39
|
989 if (char:match ("%a") or (char == " " and capsule.lastword ~= "")) then
|
|
Tercio@39
|
990 capsule.lastword = capsule.lastword .. char
|
|
Tercio@39
|
991 else
|
|
Tercio@39
|
992 capsule.lastword = ""
|
|
Tercio@39
|
993 end
|
|
Tercio@39
|
994
|
|
Tercio@39
|
995 editboxWidget.ignore_input = true
|
|
Tercio@39
|
996 if (capsule.lastword:len() >= 2) then
|
|
Tercio@39
|
997
|
|
Tercio@39
|
998 local wordList = capsule [capsule.poolName]
|
|
Tercio@39
|
999 if (not wordList) then
|
|
Tercio@39
|
1000 if (DF.debug) then
|
|
Tercio@39
|
1001 error ("Details! Framework: Invalid word list table.")
|
|
Tercio@39
|
1002 end
|
|
Tercio@39
|
1003 return
|
|
Tercio@39
|
1004 end
|
|
Tercio@39
|
1005
|
|
Tercio@39
|
1006 for i = 1, #wordList do
|
|
Tercio@39
|
1007 local thisWord = wordList [i]
|
|
Tercio@39
|
1008 if (thisWord and (thisWord:find ("^" .. capsule.lastword) or thisWord:lower():find ("^" .. capsule.lastword))) then
|
|
Tercio@39
|
1009 local rest = thisWord:gsub (capsule.lastword, "")
|
|
Tercio@39
|
1010 rest = rest:lower():gsub (capsule.lastword, "")
|
|
Tercio@39
|
1011 local cursor_pos = editboxWidget:GetCursorPosition()
|
|
Tercio@39
|
1012 editboxWidget:Insert (rest)
|
|
Tercio@39
|
1013 editboxWidget:HighlightText (cursor_pos, cursor_pos + rest:len())
|
|
Tercio@39
|
1014 editboxWidget:SetCursorPosition (cursor_pos)
|
|
Tercio@39
|
1015 editboxWidget.end_selection = cursor_pos + rest:len()
|
|
Tercio@39
|
1016 editboxWidget.ignore_textchange = true
|
|
Tercio@39
|
1017 break
|
|
Tercio@39
|
1018 end
|
|
Tercio@39
|
1019 end
|
|
Tercio@39
|
1020
|
|
Tercio@39
|
1021 end
|
|
Tercio@39
|
1022 editboxWidget.ignore_input = false
|
|
Tercio@39
|
1023 end
|
|
Tercio@39
|
1024
|
|
Tercio@39
|
1025 function TextEntryMetaFunctions:SetAsAutoComplete (poolName)
|
|
Tercio@39
|
1026
|
|
Tercio@39
|
1027 self.lastword = ""
|
|
Tercio@39
|
1028 self.characters_count = 0
|
|
Tercio@39
|
1029 self.poolName = poolName
|
|
Tercio@39
|
1030 self.GetLastWord = get_last_word --editbox:GetLastWord()
|
|
Tercio@39
|
1031 self.NoClearFocusOnEnterPressed = true --avoid auto clear focus
|
|
Tercio@39
|
1032
|
|
Tercio@39
|
1033 self:SetHook ("OnEditFocusGained", AutoComplete_OnEditFocusGained)
|
|
Tercio@39
|
1034 self.editbox:HookScript ("OnEscapePressed", AutoComplete_OnEscapePressed)
|
|
Tercio@39
|
1035
|
|
Tercio@39
|
1036 -- self:SetHook ("OnTextChanged", AutoComplete_OnTextChanged)
|
|
Tercio@39
|
1037 self:SetHook ("OnEnterPressed", AutoComplete_OnEnterPressed)
|
|
Tercio@39
|
1038 -- self:SetHook ("OnChar", AutoComplete_OnChar)
|
|
Tercio@39
|
1039 -- self:SetHook ("OnSpacePressed", AutoComplete_OnSpacePressed)
|
|
Tercio@39
|
1040
|
|
Tercio@39
|
1041 self.editbox:SetScript ("OnTextChanged", AutoComplete_OnTextChanged)
|
|
Tercio@39
|
1042 -- self.editbox:SetScript ("OnEnterPressed", AutoComplete_OnEnterPressed)
|
|
Tercio@39
|
1043 self.editbox:SetScript ("OnChar", AutoComplete_OnChar)
|
|
Tercio@39
|
1044 self.editbox:SetScript ("OnSpacePressed", AutoComplete_OnSpacePressed)
|
|
Tercio@39
|
1045
|
|
Tercio@39
|
1046 end
|
|
Tercio@39
|
1047
|
|
Tercio@39
|
1048 -- endp |