edittext.lzx
<library>
<include href="base/baseformitem.lzx"/>
<class name="_internalinputtext" extends="inputtext">
<method name="construct" args="parent, args">
// args from parent
if ( parent['textwidth'] != null ) args.textwidth = parent.textwidth;
if ( parent['_initialtext'] != null ) args.text = parent._initialtext;
if ( parent['password'] != null ) args.password = parent.password;
if ( parent['multiline'] != null ) args.multiline = parent.multiline;
super.construct( parent, args );
</method>
<doc>
<text>Class for use in edittext, takes its parent's arguments
when it constructs.</text>
<tag name="access"><text>private</text></tag>
</doc>
</class>
<class name="edittext" extends="baseformitem" focusable="false" defaultplacement="content">
<attribute name="text" type="text"/>
<attribute name="multiline" value="false
"/>
<attribute name="password" value="false
"/>
<attribute name="resizable" value="false
"/>
<attribute name="height" value="26
"/>
<attribute name="width" value="106
"/>
<attribute name="text_y" value="${multiline ? 2 : Math.round(((this.height - this.field.getTextHeight())/2))}}" type="number"/>
<attribute name="maxlength" value="null
" type="number"/>
<attribute name="pattern" type="string" value="
"/>
<attribute name="fgcolor" setter="" value="#000000
"/>
<attribute name="_fgcolor" value="0
"/>
<attribute name="_initialtext" value="
" type="string"/>
<method name="init">
if (!this.hassetwidth) {
if (typeof(this.textwidth) == "undefined") {
this.textwidth = 100;
}
setAttribute('width', this.textwidth + 6);
}
super.init();
if ( this._initialtext != null ){
this.setAttribute('text', this._initialtext );
}
field.setAttribute('maxlength', this.maxlength);
field.setAttribute('pattern', this.pattern);
</method>
<method name="setText" args="t">
if ($debug) Debug.warn("edittext.setText is deprecated. Use setAttribute instead");
this.setAttribute('text', t);
</method>
<setter name="text" args="t">
// text value and event sent by this.field.ontext handler
if (this._initcomplete) {
this.setValue(t, true);
this.field.setAttribute('text', t);
} else {
this.text = t;
this._initialtext = t;
}
</setter>
<method name="clearText">
this.setAttribute('text', "");
</method>
<method name="setMaxlength" args="n">
if ($debug) Debug.warn("edittext.setMaxlength is deprecated. Use setAttribute instead");
this.setAttribute('maxlength', n);
</method>
<method name="setPattern" args="r">
if ($debug) Debug.warn("edittext.setPattern is deprecated. Use setAttribute instead");
this.setAttribute('pattern', r);
</method>
<setter name="maxlength" args="n">
if (this['maxlength'] === n) return;
this.maxlength = n;
if (this.isinited) field.setAttribute('maxlength', n);
if (this['onmaxlength']) this.onmaxlength.sendEvent(n);
</setter>
<setter name="pattern" args="n">
if (this['pattern'] === n) return;
this.pattern = n;
if (this.isinited) field.setAttribute('pattern', n);
if (this['onpattern']) this.onpattern.sendEvent(n);
</setter>
<method name="setSelection" args="start,end=null">
field.setSelection(start, end);
</method>
<method name="getFocusRect">
var fx = this.getAttributeRelative('x',canvas);
var fy = this.getAttributeRelative('y',canvas);
var fw = this.getAttributeRelative('width',canvas);
var fh = this.getAttributeRelative('height',canvas);
return [fx,fy,fw,fh];
</method>
<view name="_outerbezel" width="${parent.width}" height="${parent.height}">
<state applied="${this.classroot.enabled}" pooling="true">
<view bgcolor="0x989898" width="100%" height="1"/>
<view bgcolor="0x989898" width="1" height="100%"/>
<view bgcolor="0xe1e1e1" width="1" align="right" height="100%"/>
<view bgcolor="0xe1e1e1" valign="bottom" width="100%" height="1"/>
</state>
</view>
<view name="_innerbezel" x="1" y="1" width="${parent.width-2}" height="${parent.height-2}">
<state applied="${this.classroot.enabled}" pooling="true">
<view bgcolor="0x262626" width="${parent.width - 1}" height="1"/>
<view bgcolor="0x262626" width="1" height="100%"/>
<view bgcolor="0xefefef" valign="bottom" width="100%" height="1"/>
</state>
<state applied="${! this.classroot.enabled}" pooling="true">
<view bgcolor="0xa4a4a4" width="100%" height="100%"/>
<view bgcolor="white" x="1" y="1" width="${parent.width - 2}" height="${parent.height - 2}"/>
</state>
</view>
<view name="_face" x="2" y="2" width="${parent.width-3}" height="${parent.height-4}"/>
<setter name="font" args="f">
super.setAttribute('font', f);
if (this['field']) field.setAttribute('font', f);
</setter>
<setter name="fontsize" args="f">
super.setAttribute('fontsize', f);
if (this['field']) field.setAttribute('fontsize', f);
</setter>
<setter name="fontstyle" args="f">
super.setAttribute('fontstyle', f);
if (this['field']) field.setAttribute('fontstyle', f);
</setter>
<view name="content" x="3" y="${this.classroot.text_y}" width="${parent.width - 4}" height="${parent.height - y - 2}"/>
<_internalinputtext name="field" password="$once{parent.password}" x="3" y="${this.classroot.text_y}" width="${parent.width - 4}" height="${parent.height - y - 2}">
<handler name="onfocus" args="s">
if (parent['onfocus']) parent.onfocus.sendEvent(s);
</handler>
<handler name="onblur" args="s">
if (parent['onblur']) parent.onblur.sendEvent(s);
</handler>
<handler name="onkeyup" args="kc">
if (parent['onkeyup']) parent.onkeyup.sendEvent(kc);
if (kc == 13 && parent.doesenter) parent.doEnterUp();
</handler>
<handler name="onkeydown" args="kc">
if (parent['onkeydown']) parent.onkeydown.sendEvent(kc);
if (kc == 13 && parent.doesenter) parent.doEnterDown();
</handler>
<method name="getFocusRect">
return parent.getFocusRect();
</method>
<handler name="ontext">
// Don't use parent.updateData() or parent.setAttribute('text') because they call the text setter - which will call this method or clobber _initialtext
parent.text = this.text;
if (parent['ontext'] && parent.ontext.ready) parent.ontext.sendEvent(parent.text);
parent.setValue(parent.text, false);
</handler>
</_internalinputtext>
<method name="getText">
if (this._initcomplete) {
return this.field.text;
} else {
return this._initialtext;
}
</method>
<method name="applyData" args="d">
this.field.applyData( d );
</method>
<method name="acceptValue" args="d, type=null">
this.applyData( d );
</method>
<method name="updateData">
this.updateText();
return this.text;
</method>
<method name="updateText">
this.setAttribute('text', this.field.text );
</method>
<method name="getValue">
return this.field.text;
</method>
<method name="$lzc$getValue_dependencies" args="who, self">
// adapted from lztext:
//$lzc$getText_dependencies ( who , self){
// return [ self , "text" ];
//}
return [this.field, "text" ];
</method>
<method name="_showEnabled">
if (_enabled) {
this.field.setAttribute('enabled', true);
this.field.setAttribute('fgcolor', this.style != null ? this.style.textcolor : null);
this._face.setAttribute( 'opacity', 1 );
this._outerbezel.setAttribute('frame', 1 );
this._innerbezel.setAttribute('frame', 1 );
} else {
this.field.setAttribute('enabled', false);
this.field.setAttribute('width', this.width - 6);
this.field.setAttribute('height', this.height - 6);
this.field.setAttribute('fgcolor', this.style != null ? this.style.textdisabledcolor : null);
this._face.setAttribute( 'opacity', .65 );
this._outerbezel.setAttribute('frame', 2 );
this._innerbezel.setAttribute('frame', 2 );
}
</method>
<method name="_applystyle" args="s">
if (this.style != null) {
//field.setAttribute('bgcolor',s.textfieldcolor);
_face.setAttribute('bgcolor',s.textfieldcolor);
}
</method>
<doc>
<tag name="shortdesc">
<text>
text input component with lz components look and feel
</text></tag>
<text>
<p>The <varname>edittext</varname> tag provides a text input field which has a
look and feel to match the lz component set. It can accept any
<tagname>inputtext</tagname> attribute.</p>
<example title="Simple edittext">
<canvas bgcolor="blue" height="60" >
<edittext width="200" x="20" y="20">default text goes here</edittext>
</canvas>
</example>
</text>
</doc>
</class>
</library>
Cross References
Includes
Classes