annotate Libs/DF/textentry.lua @ 20:dc1c77254f80

- added close button to users panel. - framework update.
author Tercio
date Tue, 11 Aug 2015 12:46:46 -0300
parents 2f09fe4be15c
children dbd417f413a8
rev   line source
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 local TextEntryMetaFunctions = {}
Tercio@11 20
Tercio@11 21 DF.TextEntryCounter = 1
Tercio@11 22
Tercio@11 23 ------------------------------------------------------------------------------------------------------------
Tercio@11 24 --> metatables
Tercio@11 25
Tercio@11 26 TextEntryMetaFunctions.__call = function (_table, value)
Tercio@11 27 --> unknow
Tercio@11 28 end
Tercio@11 29
Tercio@11 30 ------------------------------------------------------------------------------------------------------------
Tercio@11 31 --> members
Tercio@11 32
Tercio@11 33 --> tooltip
Tercio@11 34 local gmember_tooltip = function (_object)
Tercio@11 35 return _object:GetTooltip()
Tercio@11 36 end
Tercio@11 37 --> shown
Tercio@11 38 local gmember_shown = function (_object)
Tercio@11 39 return _object:IsShown()
Tercio@11 40 end
Tercio@11 41 --> frame width
Tercio@11 42 local gmember_width = function (_object)
Tercio@11 43 return _object.editbox:GetWidth()
Tercio@11 44 end
Tercio@11 45 --> frame height
Tercio@11 46 local gmember_height = function (_object)
Tercio@11 47 return _object.editbox:GetHeight()
Tercio@11 48 end
Tercio@11 49 --> get text
Tercio@11 50 local gmember_text = function (_object)
Tercio@11 51 return _object.editbox:GetText()
Tercio@11 52 end
Tercio@11 53
Tercio@11 54 local get_members_function_index = {
Tercio@11 55 ["tooltip"] = gmember_tooltip,
Tercio@11 56 ["shown"] = gmember_shown,
Tercio@11 57 ["width"] = gmember_width,
Tercio@11 58 ["height"] = gmember_height,
Tercio@11 59 ["text"] = gmember_text,
Tercio@11 60 }
Tercio@11 61
Tercio@11 62 TextEntryMetaFunctions.__index = function (_table, _member_requested)
Tercio@11 63
Tercio@11 64 local func = get_members_function_index [_member_requested]
Tercio@11 65 if (func) then
Tercio@11 66 return func (_table, _member_requested)
Tercio@11 67 end
Tercio@11 68
Tercio@11 69 local fromMe = _rawget (_table, _member_requested)
Tercio@11 70 if (fromMe) then
Tercio@11 71 return fromMe
Tercio@11 72 end
Tercio@11 73
Tercio@11 74 return TextEntryMetaFunctions [_member_requested]
Tercio@11 75 end
Tercio@11 76
Tercio@11 77 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 78
Tercio@11 79 --> tooltip
Tercio@11 80 local smember_tooltip = function (_object, _value)
Tercio@11 81 return _object:SetTooltip (_value)
Tercio@11 82 end
Tercio@11 83 --> show
Tercio@11 84 local smember_show = function (_object, _value)
Tercio@11 85 if (_value) then
Tercio@11 86 return _object:Show()
Tercio@11 87 else
Tercio@11 88 return _object:Hide()
Tercio@11 89 end
Tercio@11 90 end
Tercio@11 91 --> hide
Tercio@11 92 local smember_hide = function (_object, _value)
Tercio@11 93 if (not _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 --> frame width
Tercio@11 100 local smember_width = function (_object, _value)
Tercio@11 101 return _object.editbox:SetWidth (_value)
Tercio@11 102 end
Tercio@11 103 --> frame height
Tercio@11 104 local smember_height = function (_object, _value)
Tercio@11 105 return _object.editbox:SetHeight (_value)
Tercio@11 106 end
Tercio@11 107 --> set text
Tercio@11 108 local smember_text = function (_object, _value)
Tercio@11 109 return _object.editbox:SetText (_value)
Tercio@11 110 end
Tercio@11 111 --> set multiline
Tercio@11 112 local smember_multiline = function (_object, _value)
Tercio@11 113 if (_value) then
Tercio@11 114 return _object.editbox:SetMultiLine (true)
Tercio@11 115 else
Tercio@11 116 return _object.editbox:SetMultiLine (false)
Tercio@11 117 end
Tercio@11 118 end
Tercio@11 119 --> text horizontal pos
Tercio@11 120 local smember_horizontalpos = function (_object, _value)
Tercio@11 121 return _object.editbox:SetJustifyH (string.lower (_value))
Tercio@11 122 end
Tercio@11 123
Tercio@11 124 local set_members_function_index = {
Tercio@11 125 ["tooltip"] = smember_tooltip,
Tercio@11 126 ["show"] = smember_show,
Tercio@11 127 ["hide"] = smember_hide,
Tercio@11 128 ["width"] = smember_width,
Tercio@11 129 ["height"] = smember_height,
Tercio@11 130 ["text"] = smember_text,
Tercio@11 131 ["multiline"] = smember_multiline,
Tercio@11 132 ["align"] = smember_horizontalpos,
Tercio@11 133 }
Tercio@11 134
Tercio@11 135 TextEntryMetaFunctions.__newindex = function (_table, _key, _value)
Tercio@11 136 local func = set_members_function_index [_key]
Tercio@11 137 if (func) then
Tercio@11 138 return func (_table, _value)
Tercio@11 139 else
Tercio@11 140 return _rawset (_table, _key, _value)
Tercio@11 141 end
Tercio@11 142 end
Tercio@11 143
Tercio@11 144 ------------------------------------------------------------------------------------------------------------
Tercio@11 145 --> methods
Tercio@11 146
Tercio@11 147 --> set point
Tercio@11 148 function TextEntryMetaFunctions:SetPoint (MyAnchor, SnapTo, HisAnchor, x, y, Width)
Tercio@11 149
Tercio@11 150 if (type (MyAnchor) == "boolean" and MyAnchor and self.space) then
Tercio@11 151 local textWidth = self.label:GetStringWidth()+2
Tercio@11 152 self.editbox:SetWidth (self.space - textWidth - 15)
Tercio@11 153 return
Tercio@11 154
Tercio@11 155 elseif (type (MyAnchor) == "boolean" and MyAnchor and not self.space) then
Tercio@11 156 self.space = self.label:GetStringWidth()+2 + self.editbox:GetWidth()
Tercio@11 157 end
Tercio@11 158
Tercio@11 159 if (Width) then
Tercio@11 160 self.space = Width
Tercio@11 161 end
Tercio@11 162
Tercio@11 163 MyAnchor, SnapTo, HisAnchor, x, y = DF:CheckPoints (MyAnchor, SnapTo, HisAnchor, x, y, self)
Tercio@11 164 if (not MyAnchor) then
Tercio@11 165 print ("Invalid parameter for SetPoint")
Tercio@11 166 return
Tercio@11 167 end
Tercio@11 168
Tercio@11 169 if (self.space) then
Tercio@11 170 self.label:ClearAllPoints()
Tercio@11 171 self.editbox:ClearAllPoints()
Tercio@11 172
Tercio@11 173 self.label:SetPoint (MyAnchor, SnapTo, HisAnchor, x, y)
Tercio@11 174 self.editbox:SetPoint ("left", self.label, "right", 2, 0)
Tercio@11 175
Tercio@11 176 local textWidth = self.label:GetStringWidth()+2
Tercio@11 177 self.editbox:SetWidth (self.space - textWidth - 15)
Tercio@11 178 else
Tercio@11 179 self.label:ClearAllPoints()
Tercio@11 180 self.editbox:ClearAllPoints()
Tercio@11 181 self.editbox:SetPoint (MyAnchor, SnapTo, HisAnchor, x, y)
Tercio@11 182 end
Tercio@11 183
Tercio@11 184 end
Tercio@11 185
Tercio@11 186 --> frame levels
Tercio@11 187 function TextEntryMetaFunctions:GetFrameLevel()
Tercio@11 188 return self.editbox:GetFrameLevel()
Tercio@11 189 end
Tercio@11 190 function TextEntryMetaFunctions:SetFrameLevel (level, frame)
Tercio@11 191 if (not frame) then
Tercio@11 192 return self.editbox:SetFrameLevel (level)
Tercio@11 193 else
Tercio@11 194 local framelevel = frame:GetFrameLevel (frame) + level
Tercio@11 195 return self.editbox:SetFrameLevel (framelevel)
Tercio@11 196 end
Tercio@11 197 end
Tercio@11 198
Tercio@11 199 --> select all text
Tercio@11 200 function TextEntryMetaFunctions:SelectAll()
Tercio@11 201 self.editbox:HighlightText()
Tercio@11 202 end
Tercio@11 203
Tercio@11 204 --> set labal description
Tercio@11 205 function TextEntryMetaFunctions:SetLabelText (text)
Tercio@11 206 if (text) then
Tercio@11 207 self.label:SetText (text)
Tercio@11 208 else
Tercio@11 209 self.label:SetText ("")
Tercio@11 210 end
Tercio@11 211 self:SetPoint (true) --> refresh
Tercio@11 212 end
Tercio@11 213
Tercio@11 214 --> set tab order
Tercio@11 215 function TextEntryMetaFunctions:SetNext (nextbox)
Tercio@11 216 self.next = nextbox
Tercio@11 217 end
Tercio@11 218
Tercio@11 219 --> blink
Tercio@11 220 function TextEntryMetaFunctions:Blink()
Tercio@11 221 self.label:SetTextColor (1, .2, .2, 1)
Tercio@11 222 end
Tercio@11 223
Tercio@11 224 --> show & hide
Tercio@11 225 function TextEntryMetaFunctions:IsShown()
Tercio@11 226 return self.editbox:IsShown()
Tercio@11 227 end
Tercio@11 228 function TextEntryMetaFunctions:Show()
Tercio@11 229 return self.editbox:Show()
Tercio@11 230 end
Tercio@11 231 function TextEntryMetaFunctions:Hide()
Tercio@11 232 return self.editbox:Hide()
Tercio@11 233 end
Tercio@11 234
Tercio@11 235 -- tooltip
Tercio@11 236 function TextEntryMetaFunctions:SetTooltip (tooltip)
Tercio@11 237 if (tooltip) then
Tercio@11 238 return _rawset (self, "have_tooltip", tooltip)
Tercio@11 239 else
Tercio@11 240 return _rawset (self, "have_tooltip", nil)
Tercio@11 241 end
Tercio@11 242 end
Tercio@11 243 function TextEntryMetaFunctions:GetTooltip()
Tercio@11 244 return _rawget (self, "have_tooltip")
Tercio@11 245 end
Tercio@11 246
Tercio@11 247 --> hooks
Tercio@11 248 function TextEntryMetaFunctions:SetHook (hookType, func)
Tercio@11 249 if (func) then
Tercio@11 250 _rawset (self, hookType.."Hook", func)
Tercio@11 251 else
Tercio@11 252 _rawset (self, hookType.."Hook", nil)
Tercio@11 253 end
Tercio@11 254 end
Tercio@11 255
Tercio@11 256 function TextEntryMetaFunctions:Enable()
Tercio@11 257 if (not self.editbox:IsEnabled()) then
Tercio@11 258 self.editbox:Enable()
Tercio@11 259 self.editbox:SetBackdropBorderColor (unpack (self.enabled_border_color))
Tercio@11 260 self.editbox:SetBackdropColor (unpack (self.enabled_backdrop_color))
Tercio@11 261 self.editbox:SetTextColor (unpack (self.enabled_text_color))
Tercio@11 262 end
Tercio@11 263 end
Tercio@11 264
Tercio@11 265 function TextEntryMetaFunctions:Disable()
Tercio@11 266 if (self.editbox:IsEnabled()) then
Tercio@11 267 self.enabled_border_color = {self.editbox:GetBackdropBorderColor()}
Tercio@11 268 self.enabled_backdrop_color = {self.editbox:GetBackdropColor()}
Tercio@11 269 self.enabled_text_color = {self.editbox:GetTextColor()}
Tercio@11 270
Tercio@11 271 self.editbox:Disable()
Tercio@11 272
Tercio@11 273 self.editbox:SetBackdropBorderColor (.5, .5, .5, .5)
Tercio@11 274 self.editbox:SetBackdropColor (.5, .5, .5, .5)
Tercio@11 275 self.editbox:SetTextColor (.5, .5, .5, .5)
Tercio@11 276 end
Tercio@11 277 end
Tercio@11 278
Tercio@11 279 ------------------------------------------------------------------------------------------------------------
Tercio@11 280 --> scripts
Tercio@11 281 local OnEnter = function (textentry)
Tercio@11 282
Tercio@11 283 if (textentry.MyObject.OnEnterHook) then
Tercio@11 284 local interrupt = textentry.MyObject.OnEnterHook (textentry)
Tercio@11 285 if (interrupt) then
Tercio@11 286 return
Tercio@11 287 end
Tercio@11 288 end
Tercio@11 289
Tercio@11 290 if (textentry.MyObject.have_tooltip) then
Tercio@11 291 GameCooltip2:Preset (2)
Tercio@11 292 GameCooltip2:AddLine (textentry.MyObject.have_tooltip)
Tercio@11 293 GameCooltip2:ShowCooltip (textentry, "tooltip")
Tercio@11 294 end
Tercio@11 295
Tercio@11 296 textentry.mouse_over = true
Tercio@11 297
Tercio@11 298 if (textentry:IsEnabled()) then
Tercio@11 299 textentry.current_bordercolor = textentry.current_bordercolor or {textentry:GetBackdropBorderColor()}
Tercio@11 300 textentry:SetBackdropBorderColor (1, 1, 1, 1)
Tercio@11 301 end
Tercio@11 302
Tercio@11 303 local parent = textentry:GetParent().MyObject
Tercio@11 304 if (parent and parent.type == "panel") then
Tercio@11 305 if (parent.GradientEnabled) then
Tercio@11 306 parent:RunGradient()
Tercio@11 307 end
Tercio@11 308 end
Tercio@11 309
Tercio@11 310 end
Tercio@11 311
Tercio@11 312 local OnLeave = function (textentry)
Tercio@11 313 if (textentry.MyObject.OnLeaveHook) then
Tercio@11 314 local interrupt = textentry.MyObject.OnLeaveHook (textentry)
Tercio@11 315 if (interrupt) then
Tercio@11 316 return
Tercio@11 317 end
Tercio@11 318 end
Tercio@11 319
Tercio@11 320 if (textentry.MyObject.have_tooltip) then
Tercio@11 321 GameCooltip2:ShowMe (false)
Tercio@11 322 end
Tercio@11 323
Tercio@11 324 textentry.mouse_over = false
Tercio@11 325
Tercio@11 326 if (textentry:IsEnabled()) then
Tercio@11 327 textentry:SetBackdropBorderColor (unpack (textentry.current_bordercolor))
Tercio@11 328 end
Tercio@11 329
Tercio@11 330 local parent = textentry:GetParent().MyObject
Tercio@11 331 if (parent and parent.type == "panel") then
Tercio@11 332 if (parent.GradientEnabled) then
Tercio@11 333 parent:RunGradient (false)
Tercio@11 334 end
Tercio@11 335 end
Tercio@11 336 end
Tercio@11 337
Tercio@11 338 local OnHide = function (textentry)
Tercio@11 339 if (textentry.MyObject.OnHideHook) then
Tercio@11 340 local interrupt = textentry.MyObject.OnHideHook (textentry)
Tercio@11 341 if (interrupt) then
Tercio@11 342 return
Tercio@11 343 end
Tercio@11 344 end
Tercio@11 345 end
Tercio@11 346
Tercio@11 347 local OnShow = function (textentry)
Tercio@11 348 if (textentry.MyObject.OnShowHook) then
Tercio@11 349 local interrupt = textentry.MyObject.OnShowHook (textentry)
Tercio@11 350 if (interrupt) then
Tercio@11 351 return
Tercio@11 352 end
Tercio@11 353 end
Tercio@11 354 end
Tercio@11 355
Tercio@11 356 local OnEnterPressed = function (textentry, byScript)
Tercio@11 357
Tercio@11 358 if (textentry.MyObject.OnEnterPressedHook) then
Tercio@11 359 local interrupt = textentry.MyObject.OnEnterPressedHook (textentry)
Tercio@11 360 if (interrupt) then
Tercio@11 361 return
Tercio@11 362 end
Tercio@11 363 end
Tercio@11 364
Tercio@11 365 local texto = DF:trim (textentry:GetText())
Tercio@11 366 if (_string_len (texto) > 0) then
Tercio@11 367 textentry.text = texto
Tercio@11 368 if (textentry.MyObject.func) then
Tercio@11 369 textentry.MyObject.func (textentry.MyObject.param1, textentry.MyObject.param2, texto, textentry, byScript or textentry)
Tercio@11 370 end
Tercio@11 371 else
Tercio@11 372 textentry:SetText ("")
Tercio@11 373 textentry.MyObject.currenttext = ""
Tercio@11 374 end
Tercio@11 375 textentry.focuslost = true --> perdeu_focus isso aqui pra quando estiver editando e clicar em outra caixa
Tercio@11 376 textentry:ClearFocus()
Tercio@11 377
Tercio@11 378 if (textentry.MyObject.tab_on_enter and textentry.MyObject.next) then
Tercio@11 379 textentry.MyObject.next:SetFocus()
Tercio@11 380 end
Tercio@11 381 end
Tercio@11 382
Tercio@11 383 local OnEscapePressed = function (textentry)
Tercio@11 384
Tercio@11 385 if (textentry.MyObject.OnEscapePressedHook) then
Tercio@11 386 local interrupt = textentry.MyObject.OnEscapePressedHook (textentry)
Tercio@11 387 if (interrupt) then
Tercio@11 388 return
Tercio@11 389 end
Tercio@11 390 end
Tercio@11 391
Tercio@11 392 --textentry:SetText("")
Tercio@11 393 --textentry.MyObject.currenttext = ""
Tercio@11 394 textentry.focuslost = true
Tercio@11 395 textentry:ClearFocus()
Tercio@11 396 end
Tercio@11 397
Tercio@11 398 local OnEditFocusLost = function (textentry)
Tercio@11 399
Tercio@11 400 if (textentry:IsShown()) then
Tercio@11 401
Tercio@11 402 if (textentry.MyObject.OnEditFocusLostHook) then
Tercio@11 403 local interrupt = textentry.MyObject.OnEditFocusLostHook (textentry)
Tercio@11 404 if (interrupt) then
Tercio@11 405 return
Tercio@11 406 end
Tercio@11 407 end
Tercio@11 408
Tercio@11 409 if (not textentry.focuslost) then
Tercio@11 410 local texto = DF:trim (textentry:GetText())
Tercio@11 411 if (_string_len (texto) > 0) then
Tercio@11 412 textentry.MyObject.currenttext = texto
Tercio@11 413 if (textentry.MyObject.func) then
Tercio@11 414 textentry.MyObject.func (textentry.MyObject.param1, textentry.MyObject.param2, texto, textentry, nil)
Tercio@11 415 end
Tercio@11 416 else
Tercio@11 417 textentry:SetText ("")
Tercio@11 418 textentry.MyObject.currenttext = ""
Tercio@11 419 end
Tercio@11 420 else
Tercio@11 421 textentry.focuslost = false
Tercio@11 422 end
Tercio@11 423
Tercio@11 424 textentry.MyObject.label:SetTextColor (.8, .8, .8, 1)
Tercio@11 425
Tercio@11 426 end
Tercio@11 427 end
Tercio@11 428
Tercio@11 429 local OnEditFocusGained = function (textentry)
Tercio@11 430 if (textentry.MyObject.OnEditFocusGainedHook) then
Tercio@11 431 local interrupt = textentry.MyObject.OnEditFocusGainedHook (textentry)
Tercio@11 432 if (interrupt) then
Tercio@11 433 return
Tercio@11 434 end
Tercio@11 435 end
Tercio@11 436 textentry.MyObject.label:SetTextColor (1, 1, 1, 1)
Tercio@11 437 end
Tercio@11 438
Tercio@11 439 local OnChar = function (textentry, text)
Tercio@11 440 if (textentry.MyObject.OnCharHook) then
Tercio@11 441 local interrupt = textentry.MyObject.OnCharHook (textentry, text)
Tercio@11 442 if (interrupt) then
Tercio@11 443 return
Tercio@11 444 end
Tercio@11 445 end
Tercio@11 446 end
Tercio@11 447
Tercio@11 448 local OnTextChanged = function (textentry, byUser)
Tercio@11 449 if (textentry.MyObject.OnTextChangedHook) then
Tercio@11 450 local interrupt = textentry.MyObject.OnTextChangedHook (textentry, byUser)
Tercio@11 451 if (interrupt) then
Tercio@11 452 return
Tercio@11 453 end
Tercio@11 454 end
Tercio@11 455 end
Tercio@11 456
Tercio@11 457 local OnTabPressed = function (textentry)
Tercio@11 458 if (textentry.MyObject.OnTabPressedHook) then
Tercio@11 459 local interrupt = textentry.MyObject.OnTabPressedHook (textentry, byUser)
Tercio@11 460 if (interrupt) then
Tercio@11 461 return
Tercio@11 462 end
Tercio@11 463 end
Tercio@11 464
Tercio@11 465 if (textentry.MyObject.next) then
Tercio@11 466 OnEnterPressed (textentry, false)
Tercio@11 467 textentry.MyObject.next:SetFocus()
Tercio@11 468 end
Tercio@11 469 end
Tercio@11 470
Tercio@11 471 function TextEntryMetaFunctions:PressEnter (byScript)
Tercio@11 472 OnEnterPressed (self.editbox, byScript)
Tercio@11 473 end
Tercio@11 474
Tercio@11 475 ------------------------------------------------------------------------------------------------------------
Tercio@11 476 --> object constructor
Tercio@11 477
Tercio@11 478 function DF:CreateTextEntry (parent, func, w, h, member, name)
Tercio@11 479 return DF:NewTextEntry (parent, parent, name, member, w, h, func)
Tercio@11 480 end
Tercio@11 481
Tercio@11 482 function DF:NewTextEntry (parent, container, name, member, w, h, func, param1, param2, space)
Tercio@11 483
Tercio@11 484 if (not name) then
Tercio@11 485 name = "DetailsFrameworkTextEntryNumber" .. DF.TextEntryCounter
Tercio@11 486 DF.TextEntryCounter = DF.TextEntryCounter + 1
Tercio@11 487
Tercio@11 488 elseif (not parent) then
Tercio@11 489 return nil
Tercio@11 490 end
Tercio@11 491
Tercio@11 492 if (not container) then
Tercio@11 493 container = parent
Tercio@11 494 end
Tercio@11 495
Tercio@11 496 if (name:find ("$parent")) then
Tercio@11 497 name = name:gsub ("$parent", parent:GetName())
Tercio@11 498 end
Tercio@11 499
Tercio@11 500 local TextEntryObject = {type = "textentry", dframework = true}
Tercio@11 501
Tercio@11 502 if (member) then
Tercio@11 503 parent [member] = TextEntryObject
Tercio@11 504 end
Tercio@11 505
Tercio@11 506 if (parent.dframework) then
Tercio@11 507 parent = parent.widget
Tercio@11 508 end
Tercio@11 509 if (container.dframework) then
Tercio@11 510 container = container.widget
Tercio@11 511 end
Tercio@11 512
Tercio@11 513 --> default members:
Tercio@11 514 --> hooks
Tercio@11 515 TextEntryObject.OnEnterHook = nil
Tercio@11 516 TextEntryObject.OnLeaveHook = nil
Tercio@11 517 TextEntryObject.OnHideHook = nil
Tercio@11 518 TextEntryObject.OnShowHook = nil
Tercio@11 519 TextEntryObject.OnEnterPressedHook = nil
Tercio@11 520 TextEntryObject.OnEscapePressedHook = nil
Tercio@11 521 TextEntryObject.OnEditFocusGainedHook = nil
Tercio@11 522 TextEntryObject.OnEditFocusLostHook = nil
Tercio@11 523 TextEntryObject.OnCharHook = nil
Tercio@11 524 TextEntryObject.OnTextChangedHook = nil
Tercio@11 525 TextEntryObject.OnTabPressedHook = nil
Tercio@11 526
Tercio@11 527 --> misc
Tercio@11 528 TextEntryObject.container = container
Tercio@11 529 TextEntryObject.have_tooltip = nil
Tercio@11 530
Tercio@11 531 TextEntryObject.editbox = CreateFrame ("EditBox", name, parent, "DetailsFrameworkEditBoxTemplate2")
Tercio@11 532 TextEntryObject.widget = TextEntryObject.editbox
Tercio@11 533
Tercio@11 534 TextEntryObject.editbox:SetTextInsets (3, 0, 0, -3)
Tercio@11 535
Tercio@11 536 if (not APITextEntryFunctions) then
Tercio@11 537 APITextEntryFunctions = true
Tercio@11 538 local idx = getmetatable (TextEntryObject.editbox).__index
Tercio@11 539 for funcName, funcAddress in pairs (idx) do
Tercio@11 540 if (not TextEntryMetaFunctions [funcName]) then
Tercio@11 541 TextEntryMetaFunctions [funcName] = function (object, ...)
Tercio@20 542 local x = loadstring ( "return _G['"..object.editbox:GetName().."']:"..funcName.."(...)")
Tercio@11 543 return x (...)
Tercio@11 544 end
Tercio@11 545 end
Tercio@11 546 end
Tercio@11 547 end
Tercio@11 548
Tercio@11 549 TextEntryObject.editbox.MyObject = TextEntryObject
Tercio@11 550
Tercio@11 551 if (not w and space) then
Tercio@11 552 w = space
Tercio@11 553 elseif (w and space) then
Tercio@11 554 if (DF.debug) then
Tercio@11 555 print ("warning: you are using width and space, try use only space for better results.")
Tercio@11 556 end
Tercio@11 557 end
Tercio@11 558
Tercio@11 559 TextEntryObject.editbox:SetWidth (w)
Tercio@11 560 TextEntryObject.editbox:SetHeight (h)
Tercio@11 561
Tercio@11 562 TextEntryObject.editbox:SetJustifyH ("center")
Tercio@11 563 TextEntryObject.editbox:EnableMouse (true)
Tercio@11 564 TextEntryObject.editbox:SetText ("")
Tercio@11 565
Tercio@11 566 TextEntryObject.editbox:SetAutoFocus (false)
Tercio@11 567 TextEntryObject.editbox:SetFontObject ("GameFontHighlightSmall")
Tercio@11 568
Tercio@11 569 TextEntryObject.editbox.current_bordercolor = {1, 1, 1, 0.7}
Tercio@11 570 TextEntryObject.editbox:SetBackdropBorderColor (1, 1, 1, 0.7)
Tercio@11 571 TextEntryObject.enabled_border_color = {TextEntryObject.editbox:GetBackdropBorderColor()}
Tercio@11 572 TextEntryObject.enabled_backdrop_color = {TextEntryObject.editbox:GetBackdropColor()}
Tercio@11 573 TextEntryObject.enabled_text_color = {TextEntryObject.editbox:GetTextColor()}
Tercio@11 574
Tercio@11 575 TextEntryObject.func = func
Tercio@11 576 TextEntryObject.param1 = param1
Tercio@11 577 TextEntryObject.param2 = param2
Tercio@11 578 TextEntryObject.next = nil
Tercio@11 579 TextEntryObject.space = space
Tercio@11 580 TextEntryObject.tab_on_enter = false
Tercio@11 581
Tercio@11 582 TextEntryObject.label = _G [name .. "_Desc"]
Tercio@11 583
Tercio@11 584 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 585
Tercio@11 586 --> hooks
Tercio@11 587 TextEntryObject.editbox:SetScript ("OnEnter", OnEnter)
Tercio@11 588 TextEntryObject.editbox:SetScript ("OnLeave", OnLeave)
Tercio@11 589 TextEntryObject.editbox:SetScript ("OnHide", OnHide)
Tercio@11 590 TextEntryObject.editbox:SetScript ("OnShow", OnShow)
Tercio@11 591
Tercio@11 592 TextEntryObject.editbox:SetScript ("OnEnterPressed", OnEnterPressed)
Tercio@11 593 TextEntryObject.editbox:SetScript ("OnEscapePressed", OnEscapePressed)
Tercio@11 594 TextEntryObject.editbox:SetScript ("OnEditFocusLost", OnEditFocusLost)
Tercio@11 595 TextEntryObject.editbox:SetScript ("OnEditFocusGained", OnEditFocusGained)
Tercio@11 596 TextEntryObject.editbox:SetScript ("OnChar", OnChar)
Tercio@11 597 TextEntryObject.editbox:SetScript ("OnTextChanged", OnTextChanged)
Tercio@11 598 TextEntryObject.editbox:SetScript ("OnTabPressed", OnTabPressed)
Tercio@11 599
Tercio@11 600 _setmetatable (TextEntryObject, TextEntryMetaFunctions)
Tercio@11 601
Tercio@11 602 return TextEntryObject
Tercio@11 603
Tercio@11 604 end
Tercio@11 605
Tercio@11 606 local function_gettext = function (self)
Tercio@11 607 return self.editbox:GetText()
Tercio@11 608 end
Tercio@11 609 local function_settext = function (self, text)
Tercio@11 610 return self.editbox:SetText (text)
Tercio@11 611 end
Tercio@11 612 local function_clearfocus = function (self)
Tercio@11 613 return self.editbox:ClearFocus()
Tercio@11 614 end
Tercio@11 615 local function_setfocus = function (self)
Tercio@11 616 return self.editbox:SetFocus (true)
Tercio@11 617 end
Tercio@11 618
Tercio@11 619 function DF:NewSpecialLuaEditorEntry (parent, w, h, member, name, nointent)
Tercio@11 620
Tercio@11 621 if (name:find ("$parent")) then
Tercio@11 622 name = name:gsub ("$parent", parent:GetName())
Tercio@11 623 end
Tercio@11 624
Tercio@11 625 local borderframe = CreateFrame ("Frame", name, parent)
Tercio@11 626 borderframe:SetSize (w, h)
Tercio@11 627
Tercio@11 628 if (member) then
Tercio@11 629 parent [member] = borderframe
Tercio@11 630 end
Tercio@11 631
Tercio@11 632 local scrollframe = CreateFrame ("ScrollFrame", name, borderframe, "DetailsFrameworkEditBoxMultiLineTemplate")
Tercio@11 633
Tercio@11 634 scrollframe:SetScript ("OnSizeChanged", function (self)
Tercio@11 635 scrollframe.editbox:SetSize (self:GetSize())
Tercio@11 636 end)
Tercio@11 637
Tercio@11 638 scrollframe:SetPoint ("topleft", borderframe, "topleft", 10, -10)
Tercio@11 639 scrollframe:SetPoint ("bottomright", borderframe, "bottomright", -30, 10)
Tercio@11 640
Tercio@11 641 scrollframe.editbox:SetMultiLine (true)
Tercio@11 642 scrollframe.editbox:SetJustifyH ("left")
Tercio@11 643 scrollframe.editbox:SetJustifyV ("top")
Tercio@11 644 scrollframe.editbox:SetMaxBytes (1024000)
Tercio@11 645 scrollframe.editbox:SetMaxLetters (128000)
Tercio@11 646
Tercio@11 647 borderframe.GetText = function_gettext
Tercio@11 648 borderframe.SetText = function_settext
Tercio@11 649 borderframe.ClearFocus = function_clearfocus
Tercio@11 650 borderframe.SetFocus = function_setfocus
Tercio@11 651
Tercio@11 652 if (not nointent) then
Tercio@11 653 IndentationLib.enable (scrollframe.editbox, nil, 4)
Tercio@11 654 end
Tercio@11 655
Tercio@11 656 borderframe:SetBackdrop ({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]],
Tercio@11 657 tile = 1, tileSize = 16, edgeSize = 16, insets = {left = 5, right = 5, top = 5, bottom = 5}})
Tercio@11 658 borderframe:SetBackdropColor (0.090195, 0.090195, 0.188234, 1)
Tercio@11 659 borderframe:SetBackdropBorderColor (1, 1, 1, 1)
Tercio@11 660
Tercio@11 661 borderframe.scroll = scrollframe
Tercio@11 662 borderframe.editbox = scrollframe.editbox
Tercio@11 663
Tercio@11 664 return borderframe
Tercio@11 665 end