1 /**************************************************************************** 2 Copyright (c) 2011-2012 cocos2d-x.org 3 Copyright (c) 2013-2014 Chukong Technologies Inc. 4 5 http://www.cocos2d-x.org 6 7 Permission is hereby granted, free of charge, to any person obtaining a copy 8 of this software and associated documentation files (the "Software"), to deal 9 in the Software without restriction, including without limitation the rights 10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 copies of the Software, and to permit persons to whom the Software is 12 furnished to do so, subject to the following conditions: 13 14 The above copyright notice and this permission notice shall be included in 15 all copies or substantial portions of the Software. 16 17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 THE SOFTWARE. 24 ****************************************************************************/ 25 26 /** 27 * @ignore 28 */ 29 //it's a private class, it's a renderer of ccui.TextField. 30 ccui._TextFieldRenderer = cc.TextFieldTTF.extend({ 31 _maxLengthEnabled: false, 32 _maxLength: 0, 33 _passwordEnabled: false, 34 _passwordStyleText: "", 35 _attachWithIME: false, 36 _detachWithIME: false, 37 _insertText: false, 38 _deleteBackward: false, 39 _className: "_TextFieldRenderer", 40 41 ctor: function () { 42 cc.TextFieldTTF.prototype.ctor.call(this); 43 this._maxLengthEnabled = false; 44 this._maxLength = 0; 45 this._passwordEnabled = false; 46 this._passwordStyleText = "*"; 47 this._attachWithIME = false; 48 this._detachWithIME = false; 49 this._insertText = false; 50 this._deleteBackward = false; 51 }, 52 53 onEnter: function () { 54 cc.TextFieldTTF.prototype.onEnter.call(this); 55 cc.TextFieldTTF.prototype.setDelegate.call(this, this); 56 }, 57 58 onTextFieldAttachWithIME: function (sender) { 59 this.setAttachWithIME(true); 60 return false; 61 }, 62 63 onTextFieldInsertText: function (sender, text, len) { 64 if (len === 1 && text === "\n") 65 return false; 66 67 this.setInsertText(true); 68 return (this._maxLengthEnabled) && (cc.TextFieldTTF.prototype.getCharCount.call(this) >= this._maxLength); 69 }, 70 71 onTextFieldDeleteBackward: function (sender, delText, nLen) { 72 this.setDeleteBackward(true); 73 return false; 74 }, 75 76 onTextFieldDetachWithIME: function (sender) { 77 this.setDetachWithIME(true); 78 return false; 79 }, 80 81 insertText: function (text, len) { 82 var input_text = text; 83 84 if (text !== "\n"){ 85 if (this._maxLengthEnabled){ 86 var text_count = this.getString().length; 87 if (text_count >= this._maxLength){ 88 // password 89 if (this._passwordEnabled) 90 this.setPasswordText(this.getString()); 91 return; 92 } 93 } 94 } 95 cc.TextFieldTTF.prototype.insertText.call(this, input_text, len); 96 97 // password 98 if (this._passwordEnabled && cc.TextFieldTTF.prototype.getCharCount.call(this) > 0) 99 this.setPasswordText(this.getString()); 100 }, 101 102 deleteBackward: function () { 103 cc.TextFieldTTF.prototype.deleteBackward.call(this); 104 105 if (cc.TextFieldTTF.prototype.getCharCount.call(this) > 0 && this._passwordEnabled) 106 this.setPasswordText(this._inputText); 107 }, 108 109 openIME: function () { 110 cc.TextFieldTTF.prototype.attachWithIME.call(this); 111 }, 112 113 closeIME: function () { 114 cc.TextFieldTTF.prototype.detachWithIME.call(this); 115 }, 116 117 setMaxLengthEnabled: function (enable) { 118 this._maxLengthEnabled = enable; 119 }, 120 121 isMaxLengthEnabled: function () { 122 return this._maxLengthEnabled; 123 }, 124 125 setMaxLength: function (length) { 126 this._maxLength = length; 127 }, 128 129 getMaxLength: function () { 130 return this._maxLength; 131 }, 132 133 getCharCount: function () { 134 return cc.TextFieldTTF.prototype.getCharCount.call(this); 135 }, 136 137 setPasswordEnabled: function (enable) { 138 this._passwordEnabled = enable; 139 }, 140 141 isPasswordEnabled: function () { 142 return this._passwordEnabled; 143 }, 144 145 setPasswordStyleText: function (styleText) { 146 if (styleText.length > 1) 147 return; 148 var header = styleText.charCodeAt(0); 149 if (header < 33 || header > 126) 150 return; 151 this._passwordStyleText = styleText; 152 }, 153 154 setPasswordText: function (text) { 155 var tempStr = ""; 156 var text_count = text.length; 157 var max = text_count; 158 159 if (this._maxLengthEnabled && text_count > this._maxLength) 160 max = this._maxLength; 161 162 for (var i = 0; i < max; ++i) 163 tempStr += this._passwordStyleText; 164 165 cc.LabelTTF.prototype.setString.call(this, tempStr); 166 }, 167 168 setAttachWithIME: function (attach) { 169 this._attachWithIME = attach; 170 }, 171 172 getAttachWithIME: function () { 173 return this._attachWithIME; 174 }, 175 176 setDetachWithIME: function (detach) { 177 this._detachWithIME = detach; 178 }, 179 180 getDetachWithIME: function () { 181 return this._detachWithIME; 182 }, 183 184 setInsertText: function (insert) { 185 this._insertText = insert; 186 }, 187 188 getInsertText: function () { 189 return this._insertText; 190 }, 191 192 setDeleteBackward: function (deleteBackward) { 193 this._deleteBackward = deleteBackward; 194 }, 195 196 getDeleteBackward: function () { 197 return this._deleteBackward; 198 }, 199 200 onDraw: function (sender) { 201 return false; 202 } 203 }); 204 205 ccui._TextFieldRenderer.create = function (placeholder, fontName, fontSize) { 206 var ret = new ccui._TextFieldRenderer(); 207 if (ret && ret.initWithString("", fontName, fontSize)) { 208 if (placeholder) 209 ret.setPlaceHolder(placeholder); 210 return ret; 211 } 212 return null; 213 }; 214 215 /** 216 * 217 * @class 218 * @extends ccui.Widget 219 * 220 * @property {String} string - The content string of the label 221 * @property {String} placeHolder - The place holder of the text field 222 * @property {String} font - The text field font with a style string: e.g. "18px Verdana" 223 * @property {String} fontName - The text field font name 224 * @property {Number} fontSize - The text field font size 225 * @property {Boolean} maxLengthEnabled - Indicate whether max length limit is enabled 226 * @property {Number} maxLength - The max length of the text field 227 * @property {Boolean} passwordEnabled - Indicate whether the text field is for entering password 228 */ 229 ccui.TextField = ccui.Widget.extend(/** @lends ccui.TextField# */{ 230 _textFieldRenderer: null, 231 _touchWidth: 0, 232 _touchHeight: 0, 233 _useTouchArea: false, 234 _textFieldEventListener: null, 235 _textFieldEventSelector: null, 236 _passwordStyleText: "", 237 _textFieldRendererAdaptDirty: true, 238 _fontName: "", 239 _fontSize: 12, 240 241 _ccEventCallback: null, 242 243 /** 244 * allocates and initializes a UITextField. 245 * Constructor of ccui.TextField. override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 246 * @param {string} placeholder 247 * @param {string} fontName 248 * @param {Number} fontSize 249 * @example 250 * // example 251 * var uiTextField = new ccui.TextField(); 252 */ 253 ctor: function (placeholder, fontName, fontSize) { 254 ccui.Widget.prototype.ctor.call(this); 255 this.setTouchEnabled(true); 256 if (fontName) 257 this.setFontName(fontName); 258 if (fontSize) 259 this.setFontSize(fontSize); 260 if (placeholder) 261 this.setPlaceHolder(placeholder); 262 }, 263 264 /** 265 * Calls parent class' onEnter and schedules update function. 266 * @override 267 */ 268 onEnter: function () { 269 ccui.Widget.prototype.onEnter.call(this); 270 this.scheduleUpdate(); 271 }, 272 273 _initRenderer: function () { 274 this._textFieldRenderer = ccui._TextFieldRenderer.create("input words here", "Thonburi", 20); 275 this.addProtectedChild(this._textFieldRenderer, ccui.TextField.RENDERER_ZORDER, -1); 276 }, 277 278 /** 279 * Sets touch size of ccui.TextField. 280 * @param {cc.Size} size 281 */ 282 setTouchSize: function (size) { 283 this._touchWidth = size.width; 284 this._touchHeight = size.height; 285 }, 286 287 /** 288 * Sets whether use touch area. 289 * @param enable 290 */ 291 setTouchAreaEnabled: function(enable){ 292 this._useTouchArea = enable; 293 }, 294 295 /** 296 * Checks a point if is in ccui.TextField's space 297 * @param {cc.Point} pt 298 * @returns {boolean} 299 */ 300 hitTest: function(pt){ 301 if (this._useTouchArea) { 302 var nsp = this.convertToNodeSpace(pt); 303 var bb = cc.rect( 304 -this._touchWidth * this._anchorPoint.x, 305 -this._touchHeight * this._anchorPoint.y, 306 this._touchWidth, this._touchHeight 307 ); 308 309 return ( nsp.x >= bb.x && nsp.x <= bb.x + bb.width && 310 nsp.y >= bb.y && nsp.y <= bb.y + bb.height ); 311 } else 312 return ccui.Widget.prototype.hitTest.call(this, pt); 313 }, 314 315 /** 316 * Returns touch size of ccui.TextField. 317 * @returns {cc.Size} 318 */ 319 getTouchSize: function () { 320 return cc.size(this._touchWidth, this._touchHeight); 321 }, 322 323 /** 324 * Changes the string value of textField. 325 * @deprecated since v3.0, please use setString instead. 326 * @param {String} text 327 */ 328 setText: function (text) { 329 cc.log("Please use the setString"); 330 this.setString(text); 331 }, 332 333 /** 334 * Changes the string value of textField. 335 * @param {String} text 336 */ 337 setString: function (text) { 338 if (text == null) 339 return; 340 341 text = String(text); 342 if (this.isMaxLengthEnabled()) 343 text = text.substr(0, this.getMaxLength()); 344 if (this.isPasswordEnabled()) { 345 this._textFieldRenderer.setPasswordText(text); 346 this._textFieldRenderer.setString(""); 347 this._textFieldRenderer.insertText(text, text.length); 348 } else 349 this._textFieldRenderer.setString(text); 350 this._textFieldRendererAdaptDirty = true; 351 this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize()); 352 }, 353 354 /** 355 * Sets the placeholder string. <br /> 356 * display this string if string equal "". 357 * @param {String} value 358 */ 359 setPlaceHolder: function (value) { 360 this._textFieldRenderer.setPlaceHolder(value); 361 this._textFieldRendererAdaptDirty = true; 362 this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize()); 363 }, 364 365 /** 366 * Returns the placeholder string. 367 * @returns {String} 368 */ 369 getPlaceHolder: function () { 370 return this._textFieldRenderer.getPlaceHolder(); 371 }, 372 373 /** 374 * Returns the color of ccui.TextField's place holder. 375 * @returns {cc.Color} 376 */ 377 getPlaceHolderColor: function(){ 378 return this._textFieldRenderer.getPlaceHolderColor(); 379 }, 380 381 /** 382 * Sets the place holder color to ccui.TextField. 383 * @param color 384 */ 385 setPlaceHolderColor: function(color){ 386 this._textFieldRenderer.setColorSpaceHolder(color); 387 }, 388 389 /** 390 * Sets the text color to ccui.TextField 391 * @param textColor 392 */ 393 setTextColor: function(textColor){ 394 this._textFieldRenderer.setTextColor(textColor); 395 }, 396 397 /** 398 * Sets font size for ccui.TextField. 399 * @param {Number} size 400 */ 401 setFontSize: function (size) { 402 this._textFieldRenderer.setFontSize(size); 403 this._fontSize = size; 404 this._textFieldRendererAdaptDirty = true; 405 this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize()); 406 }, 407 408 /** 409 * Gets font size of ccui.TextField. 410 * @return {Number} size 411 */ 412 getFontSize: function () { 413 return this._fontSize; 414 }, 415 416 /** 417 * Sets font name for ccui.TextField 418 * @param {String} name 419 */ 420 setFontName: function (name) { 421 this._textFieldRenderer.setFontName(name); 422 this._fontName = name; 423 this._textFieldRendererAdaptDirty = true; 424 this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize()); 425 }, 426 427 /** 428 * Returns font name of ccui.TextField. 429 * @return {String} font name 430 */ 431 getFontName: function () { 432 return this._fontName; 433 }, 434 435 /** 436 * detach with IME 437 */ 438 didNotSelectSelf: function () { 439 this._textFieldRenderer.detachWithIME(); 440 }, 441 442 /** 443 * Returns textField string value 444 * @deprecated since v3.0, please use getString instead. 445 * @returns {String} 446 */ 447 getStringValue: function () { 448 cc.log("Please use the getString"); 449 return this.getString(); 450 }, 451 452 /** 453 * Returns string value of ccui.TextField. 454 * @returns {String} 455 */ 456 getString: function () { 457 return this._textFieldRenderer.getString(); 458 }, 459 460 /** 461 * Returns the length of ccui.TextField. 462 * @returns {Number} 463 */ 464 getStringLength: function(){ 465 return this._textFieldRenderer.getStringLength(); 466 }, 467 468 /** 469 * The touch began event callback handler. 470 * @param {cc.Point} touchPoint 471 */ 472 onTouchBegan: function (touchPoint, unusedEvent) { 473 var self = this; 474 var pass = ccui.Widget.prototype.onTouchBegan.call(self, touchPoint, unusedEvent); 475 if (self._hit) { 476 setTimeout(function(){ 477 self._textFieldRenderer.attachWithIME(); 478 }, 0); 479 }else{ 480 setTimeout(function(){ 481 self._textFieldRenderer.detachWithIME(); 482 }, 0); 483 } 484 return pass; 485 }, 486 487 /** 488 * Sets Whether to open string length limit for ccui.TextField. 489 * @param {Boolean} enable 490 */ 491 setMaxLengthEnabled: function (enable) { 492 this._textFieldRenderer.setMaxLengthEnabled(enable); 493 }, 494 495 /** 496 * Returns Whether to open string length limit. 497 * @returns {Boolean} 498 */ 499 isMaxLengthEnabled: function () { 500 return this._textFieldRenderer.isMaxLengthEnabled(); 501 }, 502 503 /** 504 * Sets the max length of ccui.TextField. Only when you turn on the string length limit, it is valid. 505 * @param {number} length 506 */ 507 setMaxLength: function (length) { 508 this._textFieldRenderer.setMaxLength(length); 509 this.setString(this.getString()); 510 }, 511 512 /** 513 * Returns the max length of ccui.TextField. 514 * @returns {number} length 515 */ 516 getMaxLength: function () { 517 return this._textFieldRenderer.getMaxLength(); 518 }, 519 520 /** 521 * Sets whether to open setting string as password character. 522 * @param {Boolean} enable 523 */ 524 setPasswordEnabled: function (enable) { 525 this._textFieldRenderer.setPasswordEnabled(enable); 526 }, 527 528 /** 529 * Returns whether to open setting string as password character. 530 * @returns {Boolean} 531 */ 532 isPasswordEnabled: function () { 533 return this._textFieldRenderer.isPasswordEnabled(); 534 }, 535 536 /** 537 * Sets the password style character, Only when you turn on setting string as password character, it is valid. 538 * @param styleText 539 */ 540 setPasswordStyleText: function(styleText){ 541 this._textFieldRenderer.setPasswordStyleText(styleText); 542 this._passwordStyleText = styleText; 543 544 this.setString(this.getString()); 545 }, 546 547 /** 548 * Returns the password style character. 549 * @returns {String} 550 */ 551 getPasswordStyleText: function () { 552 return this._passwordStyleText; 553 }, 554 555 update: function (dt) { 556 if (this.getDetachWithIME()) { 557 this._detachWithIMEEvent(); 558 this.setDetachWithIME(false); 559 } 560 if (this.getAttachWithIME()) { 561 this._attachWithIMEEvent(); 562 this.setAttachWithIME(false); 563 } 564 if (this.getInsertText()) { 565 this._textFieldRendererAdaptDirty = true; 566 this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize()); 567 568 this._insertTextEvent(); 569 this.setInsertText(false); 570 } 571 if (this.getDeleteBackward()) { 572 this._textFieldRendererAdaptDirty = true; 573 this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize()); 574 575 this._deleteBackwardEvent(); 576 this.setDeleteBackward(false); 577 } 578 }, 579 580 /** 581 * Returns whether attach with IME. 582 * @returns {Boolean} 583 */ 584 getAttachWithIME: function () { 585 return this._textFieldRenderer.getAttachWithIME(); 586 }, 587 588 /** 589 * Sets attach with IME. 590 * @param {Boolean} attach 591 */ 592 setAttachWithIME: function (attach) { 593 this._textFieldRenderer.setAttachWithIME(attach); 594 }, 595 596 /** 597 * Returns whether detach with IME. 598 * @returns {Boolean} 599 */ 600 getDetachWithIME: function () { 601 return this._textFieldRenderer.getDetachWithIME(); 602 }, 603 604 /** 605 * Sets detach with IME. 606 * @param {Boolean} detach 607 */ 608 setDetachWithIME: function (detach) { 609 this._textFieldRenderer.setDetachWithIME(detach); 610 }, 611 612 /** 613 * Returns insertText string of ccui.TextField. 614 * @returns {String} 615 */ 616 getInsertText: function () { 617 return this._textFieldRenderer.getInsertText(); 618 }, 619 620 /** 621 * Sets insertText string to ccui.TextField. 622 * @param {String} insertText 623 */ 624 setInsertText: function (insertText) { 625 this._textFieldRenderer.setInsertText(insertText); 626 }, 627 628 /** 629 * Returns the delete backward of ccui.TextField. 630 * @returns {Boolean} 631 */ 632 getDeleteBackward: function () { 633 return this._textFieldRenderer.getDeleteBackward(); 634 }, 635 636 /** 637 * Sets the delete backward of ccui.TextField. 638 * @param {Boolean} deleteBackward 639 */ 640 setDeleteBackward: function (deleteBackward) { 641 this._textFieldRenderer.setDeleteBackward(deleteBackward); 642 }, 643 644 _attachWithIMEEvent: function () { 645 if(this._textFieldEventSelector){ 646 if (this._textFieldEventListener) 647 this._textFieldEventSelector.call(this._textFieldEventListener, this, ccui.TextField.EVENT_ATTACH_WITH_IME); 648 else 649 this._textFieldEventSelector(this, ccui.TextField.EVENT_ATTACH_WITH_IME); 650 } 651 if (this._ccEventCallback){ 652 this._ccEventCallback(this, ccui.TextField.EVENT_ATTACH_WITH_IME); 653 } 654 }, 655 656 _detachWithIMEEvent: function () { 657 if(this._textFieldEventSelector){ 658 if (this._textFieldEventListener) 659 this._textFieldEventSelector.call(this._textFieldEventListener, this, ccui.TextField.EVENT_DETACH_WITH_IME); 660 else 661 this._textFieldEventSelector(this, ccui.TextField.EVENT_DETACH_WITH_IME); 662 } 663 if (this._ccEventCallback) 664 this._ccEventCallback(this, ccui.TextField.EVENT_DETACH_WITH_IME); 665 }, 666 667 _insertTextEvent: function () { 668 if(this._textFieldEventSelector){ 669 if (this._textFieldEventListener) 670 this._textFieldEventSelector.call(this._textFieldEventListener, this, ccui.TextField.EVENT_INSERT_TEXT); 671 else 672 this._textFieldEventSelector(this, ccui.TextField.EVENT_INSERT_TEXT); //eventCallback 673 } 674 if (this._ccEventCallback) 675 this._ccEventCallback(this, ccui.TextField.EVENT_INSERT_TEXT); 676 }, 677 678 _deleteBackwardEvent: function () { 679 if(this._textFieldEventSelector){ 680 if (this._textFieldEventListener) 681 this._textFieldEventSelector.call(this._textFieldEventListener, this, ccui.TextField.EVENT_DELETE_BACKWARD); 682 else 683 this._textFieldEventSelector(this, ccui.TextField.EVENT_DELETE_BACKWARD); //eventCallback 684 } 685 if (this._ccEventCallback) 686 this._ccEventCallback(this, ccui.TextField.EVENT_DELETE_BACKWARD); 687 }, 688 689 /** 690 * Adds event listener to cuci.TextField. 691 * @param {Object} [target=] 692 * @param {Function} selector 693 * @deprecated since v3.0, please use addEventListener instead. 694 */ 695 addEventListenerTextField: function (selector, target) { 696 this.addEventListener(selector, target); 697 }, 698 699 /** 700 * Adds event listener callback. 701 * @param {Object} [target=] 702 * @param {Function} selector 703 */ 704 addEventListener: function(selector, target){ 705 this._textFieldEventSelector = selector; //when target is undefined, _textFieldEventSelector is ccEventCallback. 706 this._textFieldEventListener = target; 707 }, 708 709 _onSizeChanged: function () { 710 ccui.Widget.prototype._onSizeChanged.call(this); 711 this._textFieldRendererAdaptDirty = true; 712 }, 713 714 _adaptRenderers: function(){ 715 if (this._textFieldRendererAdaptDirty) { 716 this._textfieldRendererScaleChangedWithSize(); 717 this._textFieldRendererAdaptDirty = false; 718 } 719 }, 720 721 _textfieldRendererScaleChangedWithSize: function () { 722 if (!this._ignoreSize) 723 this._textFieldRenderer.setDimensions(this._contentSize); 724 this._textFieldRenderer.setPosition(this._contentSize.width / 2, this._contentSize.height / 2); 725 }, 726 727 //@since v3.3 728 getAutoRenderSize: function(){ 729 var virtualSize = this._textFieldRenderer.getContentSize(); 730 if (!this._ignoreSize) { 731 this._textFieldRenderer.setDimensions(0, 0); 732 virtualSize = this._textFieldRenderer.getContentSize(); 733 this._textFieldRenderer.setDimensions(this._contentSize.width, this._contentSize.height); 734 } 735 return virtualSize; 736 }, 737 738 /** 739 * Returns the ccui.TextField's content size. 740 * @returns {cc.Size} 741 */ 742 getVirtualRendererSize: function(){ 743 return this._textFieldRenderer.getContentSize(); 744 }, 745 746 /** 747 * Returns the renderer of ccui.TextField. 748 * @returns {cc.Node} 749 */ 750 getVirtualRenderer: function () { 751 return this._textFieldRenderer; 752 }, 753 754 /** 755 * Returns the "class name" of ccui.TextField. 756 * @returns {string} 757 */ 758 getDescription: function () { 759 return "TextField"; 760 }, 761 762 /** 763 * Open keyboard and receive input text. 764 * @return {Boolean} 765 */ 766 attachWithIME: function () { 767 this._textFieldRenderer.attachWithIME(); 768 }, 769 770 _createCloneInstance: function () { 771 return new ccui.TextField(); 772 }, 773 774 _copySpecialProperties: function (textField) { 775 this.setString(textField._textFieldRenderer.getString()); 776 this.setPlaceHolder(textField.getString()); 777 this.setFontSize(textField._textFieldRenderer.getFontSize()); 778 this.setFontName(textField._textFieldRenderer.getFontName()); 779 this.setMaxLengthEnabled(textField.isMaxLengthEnabled()); 780 this.setMaxLength(textField.getMaxLength()); 781 this.setPasswordEnabled(textField.isPasswordEnabled()); 782 this.setPasswordStyleText(textField._passwordStyleText); 783 this.setAttachWithIME(textField.getAttachWithIME()); 784 this.setDetachWithIME(textField.getDetachWithIME()); 785 this.setInsertText(textField.getInsertText()); 786 this.setDeleteBackward(textField.getDeleteBackward()); 787 this._ccEventCallback = textField._ccEventCallback; 788 this._textFieldEventListener = textField._textFieldEventListener; 789 this._textFieldEventSelector = textField._textFieldEventSelector; 790 }, 791 792 /** 793 * Sets the text area size to ccui.TextField. 794 * @param {cc.Size} size 795 */ 796 setTextAreaSize: function(size){ 797 this.setContentSize(size); 798 }, 799 800 /** 801 * Sets the text horizontal alignment of ccui.TextField. 802 * @param alignment 803 */ 804 setTextHorizontalAlignment: function(alignment){ 805 this._textFieldRenderer.setHorizontalAlignment(alignment); 806 }, 807 808 /** 809 * Sets the text vertical alignment of ccui.TextField. 810 * @param alignment 811 */ 812 setTextVerticalAlignment: function(alignment){ 813 this._textFieldRenderer.setVerticalAlignment(alignment); 814 }, 815 _setFont: function (font) { 816 this._textFieldRenderer._setFont(font); 817 this._textFieldRendererAdaptDirty = true; 818 }, 819 820 _getFont: function () { 821 return this._textFieldRenderer._getFont(); 822 }, 823 824 _changePosition: function(){ 825 this._adaptRenderers(); 826 } 827 }); 828 829 /** 830 * Creates a ccui.TextField. 831 * @deprecated since v3.0, please use new ccui.TextField() instead. 832 * @param {String} placeholder 833 * @param {String} fontName 834 * @param {Number} fontSize 835 * @returns {ccui.TextField} 836 */ 837 ccui.TextField.create = function(placeholder, fontName, fontSize){ 838 return new ccui.TextField(placeholder, fontName, fontSize); 839 }; 840 841 var _p = ccui.TextField.prototype; 842 843 // Extended properties 844 /** @expose */ 845 _p.string; 846 cc.defineGetterSetter(_p, "string", _p.getString, _p.setString); 847 /** @expose */ 848 _p.placeHolder; 849 cc.defineGetterSetter(_p, "placeHolder", _p.getPlaceHolder, _p.setPlaceHolder); 850 /** @expose */ 851 _p.font; 852 cc.defineGetterSetter(_p, "font", _p._getFont, _p._setFont); 853 /** @expose */ 854 _p.fontSize; 855 cc.defineGetterSetter(_p, "fontSize", _p.getFontSize, _p.setFontSize); 856 /** @expose */ 857 _p.fontName; 858 cc.defineGetterSetter(_p, "fontName", _p.getFontName, _p.setFontName); 859 /** @expose */ 860 _p.maxLengthEnabled; 861 cc.defineGetterSetter(_p, "maxLengthEnabled", _p.isMaxLengthEnabled, _p.setMaxLengthEnabled); 862 /** @expose */ 863 _p.maxLength; 864 cc.defineGetterSetter(_p, "maxLength", _p.getMaxLength, _p.setMaxLength); 865 /** @expose */ 866 _p.passwordEnabled; 867 cc.defineGetterSetter(_p, "passwordEnabled", _p.isPasswordEnabled, _p.setPasswordEnabled); 868 869 _p = null; 870 871 // Constants 872 //TextField event 873 /** 874 * The attach with IME event flag of ccui.TextField 875 * @constant 876 * @type {number} 877 */ 878 ccui.TextField.EVENT_ATTACH_WITH_IME = 0; 879 /** 880 * The detach with IME event flag of ccui.TextField 881 * @constant 882 * @type {number} 883 */ 884 ccui.TextField.EVENT_DETACH_WITH_IME = 1; 885 /** 886 * The insert text event flag of ccui.TextField 887 * @constant 888 * @type {number} 889 */ 890 ccui.TextField.EVENT_INSERT_TEXT = 2; 891 /** 892 * The delete backward event flag of ccui.TextField 893 * @constant 894 * @type {number} 895 */ 896 ccui.TextField.EVENT_DELETE_BACKWARD = 3; 897 898 /** 899 * The zOrder value of ccui.TextField's renderer. 900 * @constant 901 * @type {number} 902 */ 903 ccui.TextField.RENDERER_ZORDER = -1;