annotate Libs/DF/textentry.lua @ 11:2f09fe4be15c

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