basecomponent.lzx
<library>
<include href="base/style.lzx"/>
<include href="base/componentmanager.lzx"/>
<include href="base/basefocusview.lzx"/>
<class name="statictext" extends="text">
<doc>
<tag name="shortdesc"><text>
Text component that uses the default component font and fontsize.
</text></tag>
<text>
<p>
The <classname>statictext</classname> tag provides a text
field which has a look and feel to match the lz component
set, even when the canvas font has been changed. It can
accept any text attribute.
</p>
<example>
<canvas height="100" font="conga" layout="axis: y">
<font name="conga" src="congab.ttf"/>
<include href="base/basecomponent.lzx" />
<text>text in app default font (Conga)</text>
<statictext>text in component default font</statictext>
</canvas>
</example>
</text>
</doc>
</class>
<class name="basecomponent">
<attribute name="enabled" value="true
"/>
<attribute name="focusable" value="true
" type="boolean" setter="_setFocusable(focusable)"/>
<attribute name="_focusable" value="true
" type="boolean"/>
<event name="onfocusable"/>
<attribute name="text" type="html" value="
"/>
<attribute name="doesenter" type="boolean" value="false
" setter="this._setDoesEnter( doesenter )"/>
<attribute name="_enabled" value="${this.enabled && (this._parentcomponent ? this._parentcomponent._enabled : true)}" setter="this._setEnabled(_enabled)"/>
<attribute name="_parentcomponent" value="null
"/>
<attribute name="_initcomplete" value="false
"/>
<attribute name="isdefault" setter="this._setIsDefault(isdefault)"/>
<event name="onisdefault"/>
<attribute name="hasdefault" value="false
"/>
<method name="_setEnabled" args="isEnabled">
this._enabled = isEnabled;
var newFocusable = (this._enabled && this._focusable);
if (newFocusable != this.focusable) {
this.focusable = newFocusable;
if (this.onfocusable.ready) this.onfocusable.sendEvent();
}
if (_initcomplete) _showEnabled();
if (this.on_enabled.ready) this.on_enabled.sendEvent();
</method>
<method name="_setFocusable" args="isFocusable">
this._focusable = isFocusable;
if (this.enabled) {
this.focusable = this._focusable;
if (this.onfocusable.ready) this.onfocusable.sendEvent();
} else {
this.focusable = false;
}
</method>
<method name="construct" args="parent, args">
super.construct(parent, args);
// initialize internal _parentcomponent attribute
var p = this.immediateparent;
while (p != canvas) {
if (p is lz.basecomponent) {
this._parentcomponent = p;
break;
}
p = p.immediateparent;
}
</method>
<method name="init">
super.init();
this._initcomplete = true;
this._mousedownDel = new LzDelegate( this, "_doMousedown",
this, "onmousedown");
if (this.styleable) {
_usestyle( );
}
if (!this['_enabled']) _showEnabled()
</method>
<method name="_doMousedown" args="e">
</method>
<method name="doSpaceDown">
return false;
</method>
<method name="doSpaceUp">
return false;
</method>
<method name="doEnterDown">
return false;
</method>
<method name="doEnterUp">
return false;
</method>
<method name="_setIsDefault" args="def">
//avoid undefined property warnings
this.isdefault = this[ 'isdefault' ] == true;
if ( this.isdefault == def ) return;
if ( def ){
lz._componentmanager.service.makeDefault( this );
} else {
lz._componentmanager.service.unmakeDefault( this );
}
this.isdefault = def;
if ( this.onisdefault.ready ){
this.onisdefault.sendEvent( def );
}
</method>
<method name="_setDoesEnter" args="doe">
this.doesenter = doe;
if ( lz.Focus.getFocus() == this ){
lz._componentmanager.service.checkDefault( this );
}
</method>
<method name="updateDefault">
lz._componentmanager.service.checkDefault( lz.Focus.getFocus() );
</method>
<attribute name="style" value="null
" when="once" setter="styleable ? setStyle(style) : (this.style = null)"/>
<attribute name="styleable" value="true
"/>
<attribute name="_style" value="null
"/>
<event name="onstyle"/>
<attribute name="_styledel" value="null
"/>
<attribute name="_otherstyledel" value="null
"/>
<method name="setStyle" args="s">
if (!styleable) return;
// handle anon object, e.g. style="{basecolor:0xddddff}"
if (s != null && !s['isstyle']) {
var old_style = this._style;
if (!old_style) {
if (this._parentcomponent) old_style = this._parentcomponent.style;
else old_style = lz._componentmanager.service.getDefaultStyle();
}
s = old_style.extend(s);
}
this._style = s;
// set up delegates
if ( s == null ) {
if (!this._otherstyledel) {
this._otherstyledel = new LzDelegate(this, '_setstyle')
} else {
this._otherstyledel.unregisterAll();
}
// constraint to parent style if there is one
if ( this._parentcomponent && this._parentcomponent.styleable) {
this._otherstyledel.register(this._parentcomponent,
'onstyle');
s = this._parentcomponent.style;
} else { // constrain to canvas defaultstyle
this._otherstyledel.register(lz._componentmanager.service,
'ondefaultstyle');
s = lz._componentmanager.service.getDefaultStyle();
}
} else if (this._otherstyledel) {
this._otherstyledel.unregisterAll();
this._otherstyledel = null;
}
_setstyle(s);
</method>
<method name="_usestyle" args="e=null">
if (this._initcomplete && this['style'] && this.style.isinited) {
// note: in the case of lazy replication or if a component
// is new'd from script, the style may have been created
// but not inited
this._applystyle( this.style );
}
</method>
<method name="_setstyle" args="s">
if (!this._styledel) {
this._styledel = new LzDelegate( this, "_usestyle" );
} else {
_styledel.unregisterAll();
}
if (s) {
_styledel.register( s, 'onstylechanged' );
}
this.style = s;
_usestyle();
if (this.onstyle.ready) this.onstyle.sendEvent(this.style);
</method>
<method name="_applystyle" args="s">
</method>
<method name="setTint" args="v, color, brightness=0">
if (v.capabilities.colortransform) {
if (color != "" && color != null){
var rgb = color;
var red=(rgb >> 16) & 0xFF;
var green=(rgb >> 8) & 0xFF;
var blue=rgb & 0xFF;
red += 0x33;
green += 0x33;
blue += 0x33;
// these are percentages
red = red/255;
green = green/255;
blue = blue/255;
// Can't shade 114% rgb with tintcolor...
v.setAttribute('colortransform', {redMultiplier : red,
greenMultiplier : green,
blueMultiplier : blue,
redOffset : brightness,
greenOffset : brightness,
blueOffset : brightness});
}
}
</method>
<event name="on_enabled"/>
<method name="_showEnabled">
</method>
<method name="acceptValue" args="data, type=null">
this.setAttribute('text', data);
</method>
<method name="presentValue" args="type=null">
return this.text;
</method>
<method name="$lzc$presentValue_dependencies" args="who, self, type=null">
return [this, 'text'];
</method>
<method name="applyData" args="d">
this.acceptValue(d);
</method>
<method name="updateData">
return this.presentValue();
</method>
<method name="destroy">
// prevent destroyed stylable objects from applying
this.styleable = false;
// prevent other things from being applied
this._initcomplete = false;
if (this['isdefault'] && this.isdefault) {
lz._componentmanager.service.unmakeDefault( this );
}
super.destroy();
</method>
<method name="toString">
var idstring = "";
var namestring = "";
var textstring = "";
if (this['id'] != null) idstring = " id="+this.id;
if (this['name'] != null) namestring = " named \""+this.name+"\"";
if (this['text'] && this.text != "") textstring = " text="+this.text;
return this.constructor.tagname + namestring + idstring + textstring;
</method>
<doc>
<tag name="shortdesc"><text>an abstract class which all components subclass</text></tag>
<text>
<p>
An abstract base class that handles focus, the text attribute, and style.
</p>
</text>
</doc>
</class>
</library>
Cross References
Includes
Classes