bfagan
03-30-2005, 11:33 AM
I rewrote parts of gbevin's scrollinputtext class.
Changes:
+ now properly accepts onfocus and onblur methods
+ calling updateData now works.
+ there's no replace function in 3.0b2 ECMAscript, so I wrote one.
<!--
- Copyright 2005 Uwyn bvba/sprl <info[remove] at uwyn dot com>
- Distributed under the terms of the GNU General Public License, v2 or later
- $Id$
-->
<library>
<!--================================================== ===================-->
<!-- Classes -->
<!--================================================== ===================-->
<class name="_scrollinputfield" extends="inputtext">
<attribute name="lineheight" value="26" />
<attribute name="maxheight"
value="${this.height + this.lineheight * (this.maxscroll - 1)}" />
<attribute name="onpos" value="null" />
<attribute name="pos" value="0" setter="setPos(pos);" />
<method event="oninit"></method>
<method event="onmaxscroll"></method>
<method name="setPos" args="p">
if (this.isinited) { this.setScroll(1 - (p /
this.lineheight)); this.pos = p; if (this.onpos)
this.onpos.sendEvent(p); }
</method>
<method event="onscroll">
this.setPos(-this.lineheight * (this.scroll - 1), true);
</method>
</class>
<class name="scrollinputtext" bgcolor="#ffffff"
extends="baseformitem" focusable="false">
<attribute name="text" />
<method name="applyData" args="d">
<![CDATA[
this.setAttribute('text',d);
this._inputcontainer._textentry.setText(d);
]]>
</method>
<method name="getText">
<![CDATA[
var text = this._inputcontainer._textentry.getText();
text = this.replace(text, "\r", "\n");
return text;
]]>
</method>
<method name="setText" args="t">
<![CDATA[
this.setAttribute('text',t);
return this._inputcontainer._textentry.setText(t);
]]>
</method>
<method name="getValue">
<![CDATA[
return this.getText();
]]>
</method>
<method name="refresh">
<![CDATA[
if (this.datapath.p &&
this.datapath.p.hasChildNodes()) {
this._inputcontainer._textentry.setText(this.datap ath.p.getFirstChild().data);
}
]]>
</method>
<method name="replace" args="text,c1,c2">
<![CDATA[
var lastIndex = 0;
while (text.indexOf(c1,lastIndex) > 0) {
var index = text.indexOf(c1,lastIndex);
text = text.substr(0,index) + c2 + text.substr((index+1),text.length);
lastIndex = index;
}
return text;
]]>
</method>
<view name="_outerbezel" resource="lzedittext_bezel_outer_rsc"
width="${parent.width-1}" height="${parent.height-1}"
stretches="both" />
<view name="_innerbezel" resource="lzedittext_bezel_inner_rsc"
x="1" y="1" width="${parent.width-3}" height="${parent.height-3}"
stretches="both" />
<view name="_face" x="2" y="2" width="${parent.width-4}"
height="${parent.height-4}" />
<view name="_inputcontainer" x="3" y="4"
width="${parent.width - 6}" height="${parent.height - 6}"
clip="true">
<_scrollinputfield name="_textentry"
height="${parent.height}" width="${parent.width - 20}"
multiline="true">
<method event="onfocus" args="s">
<![CDATA[
if (parent.parent['onfocus']) parent.parent.onfocus.sendEvent(s);
]]>
</method>
<method event="onblur" args="s">
<![CDATA[
parent.parent.setText(parent.parent.getText());
if (parent.parent['onblur']) parent.parent.onblur.sendEvent(s);
]]>
</method>
</_scrollinputfield>
<scrollbar name="sb" axis="y" scrollattr="pos"
stepsize="${parent._textentry.lineheight}"
scrollmax="${parent._textentry.maxheight}" />
</view>
</class>
</library>
And how I've got it implemented:
<scrollinputtext name="treatment" multiline="true"
onfocus="util.valuePrep(this)"
onblur="util.valueEvaluateChange(this)"
datapath="treatment/text()" x="20" y="30" width="550"
height="300">
<method event="onconstruct">
this.datapath.setAttribute('dataControlsVisibility ','false');
</method>
</scrollinputtext>
Comments?
Changes:
+ now properly accepts onfocus and onblur methods
+ calling updateData now works.
+ there's no replace function in 3.0b2 ECMAscript, so I wrote one.
<!--
- Copyright 2005 Uwyn bvba/sprl <info[remove] at uwyn dot com>
- Distributed under the terms of the GNU General Public License, v2 or later
- $Id$
-->
<library>
<!--================================================== ===================-->
<!-- Classes -->
<!--================================================== ===================-->
<class name="_scrollinputfield" extends="inputtext">
<attribute name="lineheight" value="26" />
<attribute name="maxheight"
value="${this.height + this.lineheight * (this.maxscroll - 1)}" />
<attribute name="onpos" value="null" />
<attribute name="pos" value="0" setter="setPos(pos);" />
<method event="oninit"></method>
<method event="onmaxscroll"></method>
<method name="setPos" args="p">
if (this.isinited) { this.setScroll(1 - (p /
this.lineheight)); this.pos = p; if (this.onpos)
this.onpos.sendEvent(p); }
</method>
<method event="onscroll">
this.setPos(-this.lineheight * (this.scroll - 1), true);
</method>
</class>
<class name="scrollinputtext" bgcolor="#ffffff"
extends="baseformitem" focusable="false">
<attribute name="text" />
<method name="applyData" args="d">
<![CDATA[
this.setAttribute('text',d);
this._inputcontainer._textentry.setText(d);
]]>
</method>
<method name="getText">
<![CDATA[
var text = this._inputcontainer._textentry.getText();
text = this.replace(text, "\r", "\n");
return text;
]]>
</method>
<method name="setText" args="t">
<![CDATA[
this.setAttribute('text',t);
return this._inputcontainer._textentry.setText(t);
]]>
</method>
<method name="getValue">
<![CDATA[
return this.getText();
]]>
</method>
<method name="refresh">
<![CDATA[
if (this.datapath.p &&
this.datapath.p.hasChildNodes()) {
this._inputcontainer._textentry.setText(this.datap ath.p.getFirstChild().data);
}
]]>
</method>
<method name="replace" args="text,c1,c2">
<![CDATA[
var lastIndex = 0;
while (text.indexOf(c1,lastIndex) > 0) {
var index = text.indexOf(c1,lastIndex);
text = text.substr(0,index) + c2 + text.substr((index+1),text.length);
lastIndex = index;
}
return text;
]]>
</method>
<view name="_outerbezel" resource="lzedittext_bezel_outer_rsc"
width="${parent.width-1}" height="${parent.height-1}"
stretches="both" />
<view name="_innerbezel" resource="lzedittext_bezel_inner_rsc"
x="1" y="1" width="${parent.width-3}" height="${parent.height-3}"
stretches="both" />
<view name="_face" x="2" y="2" width="${parent.width-4}"
height="${parent.height-4}" />
<view name="_inputcontainer" x="3" y="4"
width="${parent.width - 6}" height="${parent.height - 6}"
clip="true">
<_scrollinputfield name="_textentry"
height="${parent.height}" width="${parent.width - 20}"
multiline="true">
<method event="onfocus" args="s">
<![CDATA[
if (parent.parent['onfocus']) parent.parent.onfocus.sendEvent(s);
]]>
</method>
<method event="onblur" args="s">
<![CDATA[
parent.parent.setText(parent.parent.getText());
if (parent.parent['onblur']) parent.parent.onblur.sendEvent(s);
]]>
</method>
</_scrollinputfield>
<scrollbar name="sb" axis="y" scrollattr="pos"
stepsize="${parent._textentry.lineheight}"
scrollmax="${parent._textentry.maxheight}" />
</view>
</class>
</library>
And how I've got it implemented:
<scrollinputtext name="treatment" multiline="true"
onfocus="util.valuePrep(this)"
onblur="util.valueEvaluateChange(this)"
datapath="treatment/text()" x="20" y="30" width="550"
height="300">
<method event="onconstruct">
this.datapath.setAttribute('dataControlsVisibility ','false');
</method>
</scrollinputtext>
Comments?