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  * Base class for ccui.UICCTextField
 28  * @class
 29  * @extends cc.TextFieldTTF
 30  *
 31  * @property {Boolean}  maxLengthEnabled    - Indicate whether max length limit is enabled
 32  * @property {Number}   maxLength           - The max length of the text field
 33  * @property {Boolean}  passwordEnabled     - Indicate whether the text field is for entering password
 34  */
 35 ccui.UICCTextField = cc.TextFieldTTF.extend(/** @lends ccui.UICCTextField# */{
 36     maxLengthEnabled: false,
 37     maxLength: 0,
 38     passwordEnabled: false,
 39     _passwordStyleText: "",
 40     _attachWithIME: false,
 41     _detachWithIME: false,
 42     _insertText: false,
 43     _deleteBackward: false,
 44     _className: "UICCTextField",
 45     _textFieldRendererAdaptDirty: true,
 46     ctor: function () {
 47         cc.TextFieldTTF.prototype.ctor.call(this);
 48         this.maxLengthEnabled = false;
 49         this.maxLength = 0;
 50         this.passwordEnabled = false;
 51         this._passwordStyleText = "*";
 52         this._attachWithIME = false;
 53         this._detachWithIME = false;
 54         this._insertText = false;
 55         this._deleteBackward = false;
 56     },
 57     onEnter: function () {
 58         cc.TextFieldTTF.prototype.setDelegate.call(this, this);
 59     },
 60     //CCTextFieldDelegate
 61     onTextFieldAttachWithIME: function (sender) {
 62         this.setAttachWithIME(true);
 63         return false;
 64     },
 65     onTextFieldInsertText: function (sender, text, len) {
 66         if (len == 1 && text == "\n") {
 67             return false;
 68         }
 69         this.setInsertText(true);
 70         if (this.maxLengthEnabled) {
 71             if (cc.TextFieldTTF.prototype.getCharCount.call(this) >= this.maxLength) {
 72                 return true;
 73             }
 74         }
 75 
 76         return false;
 77     },
 78     onTextFieldDeleteBackward: function (sender, delText, nLen) {
 79         this.setDeleteBackward(true);
 80         return false;
 81     },
 82     onTextFieldDetachWithIME: function (sender) {
 83         this.setDetachWithIME(true);
 84         return false;
 85     },
 86     insertText: function (text, len) {        //todo need to delete
 87         var input_text = text;
 88 
 89         if (text != "\n")
 90         {
 91             if (this.maxLengthEnabled)
 92             {
 93                 var text_count = this.getString().length;
 94                 if (text_count >= this.maxLength)
 95                 {
 96                     // password
 97                     if (this.passwordEnabled)
 98                     {
 99                         this.setPasswordText(this.getString());
100                     }
101                     return;
102                 }
103             }
104         }
105         cc.TextFieldTTF.prototype.insertText.call(this, input_text, len);
106 
107         // password
108         if (this.passwordEnabled)
109         {
110             if (cc.TextFieldTTF.prototype.getCharCount.call(this) > 0)
111             {
112                 this.setPasswordText(this.getString());
113             }
114         }
115     },
116     deleteBackward: function () {
117         cc.TextFieldTTF.prototype.deleteBackward.call(this);
118 
119         if (cc.TextFieldTTF.prototype.getCharCount.call(this) > 0) {
120             // password
121             if (this.passwordEnabled) {
122                 this.setPasswordText(this._inputText);
123             }
124         }
125     },
126     openIME: function () {
127         cc.TextFieldTTF.prototype.attachWithIME.call(this);
128     },
129     closeIME: function () {
130         cc.TextFieldTTF.prototype.detachWithIME.call(this);
131     },
132     setMaxLengthEnabled: function (enable) {
133         this.maxLengthEnabled = enable;
134     },
135     isMaxLengthEnabled: function () {
136         return this.maxLengthEnabled;
137     },
138     setMaxLength: function (length) {
139         this.maxLength = length;
140     },
141     getMaxLength: function () {
142         return this.maxLength;
143     },
144     getCharCount: function () {
145         return cc.TextFieldTTF.prototype.getCharCount.call(this);
146     },
147     setPasswordEnabled: function (enable) {
148         this.passwordEnabled = enable;
149     },
150     isPasswordEnabled: function () {
151         return this.passwordEnabled;
152     },
153     setPasswordStyleText: function (styleText) {
154         if (styleText.length > 1) {
155             return;
156         }
157         var header = styleText.charCodeAt(0);
158         if (header < 33 || header > 126) {
159             return;
160         }
161         this._passwordStyleText = styleText;
162     },
163     setPasswordText: function (text) {
164         var tempStr = "";
165         var text_count = text.length;
166         var max = text_count;
167 
168         if (this.maxLengthEnabled)
169         {
170             if (text_count > this.maxLength)
171             {
172                 max = this.maxLength;
173             }
174         }
175 
176         for (var i = 0; i < max; ++i)
177         {
178             tempStr += this._passwordStyleText;
179         }
180 
181         cc.LabelTTF.prototype.setString.call(this, tempStr);
182     },
183     setAttachWithIME: function (attach) {
184         this._attachWithIME = attach;
185     },
186     getAttachWithIME: function () {
187         return this._attachWithIME;
188     },
189     setDetachWithIME: function (detach) {
190         this._detachWithIME = detach;
191     },
192     getDetachWithIME: function () {
193         return this._detachWithIME;
194     },
195     setInsertText: function (insert) {
196         this._insertText = insert;
197     },
198     getInsertText: function () {
199         return this._insertText;
200     },
201     setDeleteBackward: function (deleteBackward) {
202         this._deleteBackward = deleteBackward;
203     },
204     getDeleteBackward: function () {
205         return this._deleteBackward;
206     },
207     init: function () {
208         if (ccui.Widget.prototype.init.call(this)) {
209             this.setTouchEnabled(true);
210             return true;
211         }
212         return false;
213     },
214     onDraw: function (sender) {
215         return false;
216     }
217 });
218 
219 ccui.UICCTextField.create = function (placeholder, fontName, fontSize) {
220     var ret = new ccui.UICCTextField();
221     if (ret && ret.initWithString("", fontName, fontSize)) {
222         if (placeholder) {
223             ret.setPlaceHolder(placeholder);
224         }
225         return ret;
226     }
227     return null;
228 };
229 
230 /**
231  * Base class for ccui.TextField
232  * @class
233  * @extends ccui.Widget
234  *
235  * @property {String}   string              - The content string of the label
236  * @property {Number}   placeHolder         - The place holder of the text field
237  * @property {String}   font                - The text field font with a style string: e.g. "18px Verdana"
238  * @property {String}   fontName            - The text field font name
239  * @property {Number}   fontSize            - The text field font size
240  * @property {Boolean}  maxLengthEnabled    - Indicate whether max length limit is enabled
241  * @property {Number}   maxLength           - The max length of the text field
242  * @property {Boolean}  passwordEnabled     - Indicate whether the text field is for entering password
243  */
244 ccui.TextField = ccui.Widget.extend(/** @lends ccui.TextField# */{
245     _textFieldRender: null,
246     _touchWidth: 0,
247     _touchHeight: 0,
248     _useTouchArea: false,
249     _textFieldEventListener: null,
250     _textFieldEventSelector: null,
251     _attachWithIMEListener: null,
252     _detachWithIMEListener: null,
253     _insertTextListener: null,
254     _deleteBackwardListener: null,
255     _attachWithIMESelector: null,
256     _detachWithIMESelector: null,
257     _insertTextSelector: null,
258     _deleteBackwardSelector: null,
259     _passwordStyleText: "",
260     _textFieldRendererAdaptDirty: true,
261 
262     /**
263      * allocates and initializes a UITextField.
264      * Constructor of ccui.TextField
265      * @example
266      * // example
267      * var uiTextField = new ccui.TextField();
268      */
269     ctor: function () {
270         ccui.Widget.prototype.ctor.call(this);
271     },
272 
273     init: function(){
274         if(ccui.Widget.prototype.init.call(this)){
275             this.setTouchEnabled(true);
276             return true;
277         }
278         return false;
279     },
280 
281     onEnter: function () {
282         ccui.Widget.prototype.onEnter.call(this);
283         this.setUpdateEnabled(true);
284     },
285 
286     onExit:function(){
287         this.setUpdateEnabled(false);
288         ccui.Layout.prototype.onExit.call(this);
289     },
290 
291     initRenderer: function () {
292         this._textFieldRender = ccui.UICCTextField.create("input words here", "Thonburi", 20);
293         this.addProtectedChild(this._textFieldRender, ccui.TextField.RENDERER_ZORDER, -1);
294 
295     },
296 
297     /**
298      * Set touch size
299      * @param {cc.Size} size
300      */
301     setTouchSize: function (size) {
302         this._touchWidth = size.width;
303         this._touchHeight = size.height;
304     },
305 
306     setTouchAreaEnabled: function(enable){
307         this._useTouchArea = enable;
308     },
309 
310     adaptRenderers: function(){
311         if (this._textFieldRendererAdaptDirty)
312         {
313             this.textfieldRendererScaleChangedWithSize();
314             this._textFieldRendererAdaptDirty = false;
315         }
316     },
317 
318     hitTest: function(pt){
319         if (this._useTouchArea)
320         {
321             var nsp = this.convertToNodeSpace(pt);
322             var bb = cc.rect(
323                 -this._touchWidth * this._anchorPoint.x,
324                 -this._touchHeight * this._anchorPoint.y,
325                 this._touchWidth, this._touchHeight
326             );
327             if (
328                 nsp.x >= bb.origin.x &&
329                 nsp.x <= bb.origin.x + bb.size.width &&
330                 nsp.y >= bb.origin.y &&
331                 nsp.y <= bb.origin.y + bb.size.height
332             )
333             {
334                 return true;
335             }
336         }
337         else
338         {
339             return ccui.Widget.prototype.hitTest.call(this, pt);
340         }
341 
342         return false;
343     },
344 
345     /**
346      * Get touch size.
347      * @returns {cc.Size}
348      */
349     getTouchSize: function () {
350         return cc.size(this._touchWidth, this._touchHeight);
351     },
352 
353     /**
354      *  Changes the string value of textField.
355      * @deprecated
356      * @param {String} text
357      */
358     setText: function (text) {
359         cc.log("Please use the setString");
360         this.setString(text);
361     },
362 
363     /**
364      *  Changes the string value of textField.
365      * @param {String} text
366      */
367     setString: function (text) {
368         if (!text) {
369             return;
370         }
371         text = String(text);
372         if (this.isMaxLengthEnabled()) {
373             text = text.substr(0, this.getMaxLength());
374         }
375         if (this.isPasswordEnabled()) {
376             this._textFieldRender.setPasswordText(text);
377             this._textFieldRender.setString("");
378             this._textFieldRender.insertText(text, text.length);
379         }
380         else {
381             this._textFieldRender.setString(text);
382         }
383         this._textFieldRendererAdaptDirty = true;
384         this._updateContentSizeWithTextureSize(this._textFieldRender.getContentSize());
385     },
386 
387     /**
388      * @param {String} value
389      */
390     setPlaceHolder: function (value) {
391         this._textFieldRender.setPlaceHolder(value);
392         this._textFieldRendererAdaptDirty = true;
393         this._updateContentSizeWithTextureSize(this._textFieldRender.getContentSize());
394     },
395 
396     /**
397      * @returns {String}
398      */
399     getPlaceHolder: function () {
400         return this._textFieldRender.getPlaceHolder();
401     },
402 
403     _setFont: function (font) {
404         this._textFieldRender._setFont(font);
405         this._textFieldRendererAdaptDirty = true;
406     },
407 
408     _getFont: function () {
409         return this._textFieldRender._getFont();
410     },
411 
412     /**
413      * Set font size for text field content
414      * @param {cc.Size} size
415      */
416     setFontSize: function (size) {
417         this._textFieldRender.setFontSize(size);
418         this._textFieldRendererAdaptDirty = true;
419         this._updateContentSizeWithTextureSize(this._textFieldRender.getContentSize());
420     },
421 
422     /**
423      * Get font size for text field content
424      * @param {cc.Size} size
425      */
426     getFontSize: function () {
427         return this._textFieldRender.getSystemFontSize();
428     },
429 
430     /**
431      * Set font name for text field content
432      * @param {String} name
433      */
434     setFontName: function (name) {
435         this._textFieldRender.setFontName(name);
436         this._textFieldRendererAdaptDirty = true;
437         this._updateContentSizeWithTextureSize(this._textFieldRender.getContentSize());
438 
439     },
440 
441     /**
442      * Get font name for text field content
443      * @param {cc.Size} size
444      */
445     getFontName: function () {
446         return this._textFieldRender.getSystemFontName();
447     },
448 
449     /**
450      * detach with IME
451      */
452     didNotSelectSelf: function () {
453         this._textFieldRender.detachWithIME();
454     },
455 
456     /**
457      * get textField string value
458      * @deprecated
459      * @returns {String}
460      */
461     getStringValue: function () {
462         cc.log("Please use the getString");
463         return this.getString();
464     },
465 
466     /**
467      * get textField string value
468      * @returns {String}
469      */
470     getString: function () {
471         return this._textFieldRender.getString();
472     },
473 
474     getStringLength: function(){
475         return this._textFieldRender.getStringLength();
476     },
477 
478     /**
479      * touch began
480      * @param {cc.Point} touchPoint
481      */
482     onTouchBegan: function (touchPoint, unusedEvent) {
483         var self = this;
484         var pass = ccui.Widget.prototype.onTouchBegan.call(self, touchPoint, unusedEvent);
485         if (self._hitted)
486         {
487             setTimeout(function(){
488                 self._textFieldRender.attachWithIME();
489             }, 0);
490         }
491         return pass;
492     },
493 
494     /**
495      * @param {Boolean} enable
496      */
497     setMaxLengthEnabled: function (enable) {
498         this._textFieldRender.setMaxLengthEnabled(enable);
499     },
500 
501     /**
502      * @returns {Boolean}
503      */
504     isMaxLengthEnabled: function () {
505         return this._textFieldRender.isMaxLengthEnabled();
506     },
507 
508     /**
509      * @param {number} length
510      */
511     setMaxLength: function (length) {
512         this._textFieldRender.setMaxLength(length);
513 
514         this.setString(this.getString());
515     },
516 
517     /**
518      * @returns {number} length
519      */
520     getMaxLength: function () {
521         return this._textFieldRender.getMaxLength();
522     },
523 
524     /**
525      * @param {Boolean} enable
526      */
527     setPasswordEnabled: function (enable) {
528         this._textFieldRender.setPasswordEnabled(enable);
529     },
530 
531     /**
532      * @returns {Boolean}
533      */
534     isPasswordEnabled: function () {
535         return this._textFieldRender.isPasswordEnabled();
536     },
537 
538     /**
539      * @param {String} enable
540      */
541     setPasswordStyleText: function (styleText) {
542         this._textFieldRender.setPasswordStyleText(styleText);
543         this._passwordStyleText = styleText;
544 
545         this.setString(this.getString());
546     },
547 
548     /**
549      * @returns {String}
550      */
551     getPasswordStyleText: function () {
552         return this._passwordStyleText;
553     },
554 
555     update: function (dt) {
556         if (this.getAttachWithIME()) {
557             this.attachWithIMEEvent();
558             this.setAttachWithIME(false);
559         }
560         if (this.getDetachWithIME()) {
561             this.detachWithIMEEvent();
562             this.setDetachWithIME(false);
563         }
564         if (this.getInsertText()) {
565             this.insertTextEvent();
566             this.setInsertText(false);
567 
568             this._textFieldRendererAdaptDirty = true;
569             this._updateContentSizeWithTextureSize(this._textFieldRender.getContentSize());
570         }
571         if (this.getDeleteBackward()) {
572             this.deleteBackwardEvent();
573             this.setDeleteBackward(false);
574 
575             this._textFieldRendererAdaptDirty = true;
576             this._updateContentSizeWithTextureSize(this._textFieldRender.getContentSize());
577         }
578     },
579 
580     /**
581      * get whether attach with IME.
582      * @returns {Boolean}
583      */
584     getAttachWithIME: function () {
585         return this._textFieldRender.getAttachWithIME();
586     },
587 
588     /**
589      * set attach with IME.
590      * @param {Boolean} attach
591      */
592     setAttachWithIME: function (attach) {
593         this._textFieldRender.setAttachWithIME(attach);
594     },
595 
596     /**
597      * get whether eetach with IME.
598      * @returns {Boolean}
599      */
600     getDetachWithIME: function () {
601         return this._textFieldRender.getDetachWithIME();
602     },
603 
604     /**
605      * set detach with IME.
606      * @param {Boolean} detach
607      */
608     setDetachWithIME: function (detach) {
609         this._textFieldRender.setDetachWithIME(detach);
610     },
611 
612     /**
613      * get insertText
614      * @returns {String}
615      */
616     getInsertText: function () {
617         return this._textFieldRender.getInsertText();
618     },
619 
620     /**
621      * set insertText
622      * @param {String} insertText
623      */
624     setInsertText: function (insertText) {
625         this._textFieldRender.setInsertText(insertText);
626     },
627 
628     /**
629      * @returns {Boolean}
630      */
631     getDeleteBackward: function () {
632         return this._textFieldRender.getDeleteBackward();
633     },
634 
635     /**
636      * @param {Boolean} deleteBackward
637      */
638     setDeleteBackward: function (deleteBackward) {
639         this._textFieldRender.setDeleteBackward(deleteBackward);
640     },
641 
642     attachWithIMEEvent: function () {
643         if (this._textFieldEventListener && this._textFieldEventSelector) {
644             this._textFieldEventSelector.call(this._textFieldEventListener, this, ccui.TextField.EVENT_ATTACH_WITH_ME);
645         }
646         if (this._eventCallback) {
647             this._eventCallback(this, 0);
648         }
649     },
650 
651     detachWithIMEEvent: function () {
652         if (this._textFieldEventListener && this._textFieldEventSelector) {
653             this._textFieldEventSelector.call(this._textFieldEventListener, this, ccui.TextField.EVENT_DETACH_WITH_ME);
654         }
655         if (this._eventCallback) {
656             this._eventCallback(this, 1);
657         }
658     },
659 
660     insertTextEvent: function () {
661         if (this._textFieldEventListener && this._textFieldEventSelector) {
662             this._textFieldEventSelector.call(this._textFieldEventListener, this, ccui.TextField.EVENT_INSERT_TEXT);
663         }
664         if (this._eventCallback) {
665             this._eventCallback(this, 2);
666         }
667     },
668 
669     deleteBackwardEvent: function () {
670         if (this._textFieldEventListener && this._textFieldEventSelector) {
671             this._textFieldEventSelector.call(this._textFieldEventListener, this, ccui.TextField.EVENT_DELETE_BACKWARD);
672         }
673         if (this._eventCallback) {
674             this._eventCallback(this, 3);
675         }
676     },
677 
678     /**
679      * add event listener
680      * @param {Function} selector
681      * @param {Object} target
682      */
683     addEventListenerTextField: function (selector, target) {
684         this._textFieldEventSelector = selector;
685         this._textFieldEventListener = target;
686     },
687 
688     /**
689      * override "setAnchorPoint" of widget.
690      * @param {cc.Point|Number} point The anchor point of UILabelBMFont or The anchor point.x of UILabelBMFont.
691      * @param {Number} [y] The anchor point.y of UILabelBMFont.
692      */
693     setAnchorPoint: function (point, y) {
694         if (y === undefined) {
695             ccui.Widget.prototype.setAnchorPoint.call(this, point);
696             this._textFieldRender.setAnchorPoint(point);
697         } else {
698             ccui.Widget.prototype.setAnchorPoint.call(this, point, y);
699             this._textFieldRender.setAnchorPoint(point, y);
700         }
701     },
702     _setAnchorX: function (value) {
703         ccui.Widget.prototype._setAnchorX.call(this, value);
704         this._textFieldRender._setAnchorX(value);
705     },
706     _setAnchorY: function (value) {
707         ccui.Widget.prototype._setAnchorY.call(this, value);
708         this._textFieldRender._setAnchorY(value);
709     },
710 
711     onSizeChanged: function () {
712         ccui.Widget.prototype.onSizeChanged.call(this);
713         this._textFieldRendererAdaptDirty = true;
714     },
715 
716     textfieldRendererScaleChangedWithSize: function () {
717         if (this._ignoreSize) {
718             this._textFieldRender.setScale(1.0);
719             var rendererSize = this.getContentSize();
720             this._size.width = rendererSize.width;
721             this._size.height = rendererSize.height;
722         }
723         else {
724             var textureSize = this.getContentSize();
725             if (textureSize.width <= 0.0 || textureSize.height <= 0.0) {
726                 this._textFieldRender.setScale(1.0);
727                 return;
728             }
729             var scaleX = this._size.width / textureSize.width;
730             var scaleY = this._size.height / textureSize.height;
731             this._textFieldRender.setScaleX(scaleX);
732             this._textFieldRender.setScaleY(scaleY);
733         }
734         this._textFieldRender.setPosition(this._contentSize.width / 2, this._contentSize.height / 2);
735     },
736 
737     /**
738      * override "getContentSize" method of widget.
739      * @returns {cc.Size}
740      */
741     getContentSize: function () {
742         return this._textFieldRender.getContentSize();
743     },
744     _getWidth: function () {
745         return this._textFieldRender._getWidth();
746     },
747     _getHeight: function () {
748         return this._textFieldRender._getHeight();
749     },
750 
751     /**
752      * override "getContentSize" method of widget.
753      * @returns {cc.Node}
754      */
755     getVirtualRenderer: function () {
756         return this._textFieldRender;
757     },
758 
759     updateTextureColor: function () {
760         this.updateColorToRenderer(this._textFieldRender);
761     },
762 
763     updateTextureOpacity: function () {
764         this.updateOpacityToRenderer(this._textFieldRender);
765     },
766 
767     /**
768      * Returns the "class name" of widget.
769      * @returns {string}
770      */
771     getDescription: function () {
772         return "TextField";
773     },
774 
775     attachWithIME: function () {
776         this._textFieldRender.attachWithIME();
777     },
778 
779     createCloneInstance: function () {
780         return ccui.TextField.create();
781     },
782 
783     copySpecialProperties: function (textField) {
784         this.setString(textField._textFieldRender.getString());
785         this.setPlaceHolder(textField.getString());
786         this.setFontSize(textField._textFieldRender.getFontSize());
787         this.setFontName(textField._textFieldRender.getFontName());
788         this.setMaxLengthEnabled(textField.isMaxLengthEnabled());
789         this.setMaxLength(textField.getMaxLength());
790         this.setPasswordEnabled(textField.isPasswordEnabled());
791         this.setPasswordStyleText(textField._passwordStyleText);
792         this.setAttachWithIME(textField.getAttachWithIME());
793         this.setDetachWithIME(textField.getDetachWithIME());
794         this.setInsertText(textField.getInsertText());
795         this.setDeleteBackward(textField.getDeleteBackward());
796     }
797 });
798 
799 ccui.TextField.create = function(placeholder, fontName, fontSize){
800     var widget = new ccui.TextField();
801     if (widget && widget.init())
802     {
803         if(placeholder && fontName && fontSize){
804             widget.setPlaceHolder(placeholder);
805             widget.setFontName(fontName);
806             widget.setFontSize(fontSize);
807 
808         }
809         return widget;
810     }
811     return null;
812 
813 };
814 
815 var _p = ccui.TextField.prototype;
816 
817 // Extended properties
818 /** @expose */
819 _p.string;
820 cc.defineGetterSetter(_p, "string", _p.getString, _p.setString);
821 /** @expose */
822 _p.placeHolder;
823 cc.defineGetterSetter(_p, "placeHolder", _p.getPlaceHolder, _p.setPlaceHolder);
824 /** @expose */
825 _p.font;
826 cc.defineGetterSetter(_p, "font", _p._getFont, _p._setFont);
827 /** @expose */
828 _p.fontSize;
829 cc.defineGetterSetter(_p, "fontSize", _p.getFontSize, _p.setFontSize);
830 /** @expose */
831 _p.fontName;
832 cc.defineGetterSetter(_p, "fontName", _p.getFontName, _p.setFontName);
833 /** @expose */
834 _p.maxLengthEnabled;
835 cc.defineGetterSetter(_p, "maxLengthEnabled", _p.isMaxLengthEnabled, _p.setMaxLengthEnabled);
836 /** @expose */
837 _p.maxLength;
838 cc.defineGetterSetter(_p, "maxLength", _p.getMaxLength, _p.setMaxLength);
839 /** @expose */
840 _p.passwordEnabled;
841 cc.defineGetterSetter(_p, "passwordEnabled", _p.isPasswordEnabled, _p.setPasswordEnabled);
842 
843 _p = null;
844 
845 /**
846  * allocates and initializes a UITextField.
847  * @constructs
848  * @return {ccui.TextField}
849  * @example
850  * // example
851  * var uiTextField = ccui.TextField.create();
852  */
853 ccui.TextField.create = function () {
854     return new ccui.TextField();
855 };
856 
857 // Constants
858 //TextField event
859 ccui.TextField.EVENT_ATTACH_WITH_ME = 0;
860 ccui.TextField.EVENT_DETACH_WITH_ME = 1;
861 ccui.TextField.EVENT_INSERT_TEXT = 2;
862 ccui.TextField.EVENT_DELETE_BACKWARD = 3;
863 
864 ccui.TextField.RENDERER_ZORDER = -1;