PDA

View Full Version : scrollinputtext changes


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?

max
04-05-2005, 10:03 AM
I'd love to ship your component with the next release, but I'm afraid the license conflicts with the Laszlo BSD license. Also, I'm not sure if you can change the license from BSD to GNU, can you? Anyhow - great work!

-Max

bfagan
04-05-2005, 11:17 AM
You'd have to check with gbevin. It's his original code. I just made a bunch of changes.

gbevin
04-05-2005, 12:42 PM
I hereby make this fully public domain, available under any license you like. Want me to send a confirmation email about it somewhere?

jrrobles
04-21-2006, 10:06 AM
are you sure this work?, I got 4 warnings when I was trying to use it:

test.lzx:10:15: attribute "multiline" not allowed at this point; ignored
test.lzx:10:15: found an unknown attribute named "multiline" on element scrollinputtext, check the spelling of this attribute name

newscrolltext.lzx:94:23: The resource named 'lzedittext_bezel_inner_rsc' has not been declared
newscrolltext.lzx:91:23: The resource named 'lzedittext_bezel_outer_rsc' has not been declared

bytebodger
05-22-2006, 10:09 AM
This seems to work great for adding new data into a blank form field, but I can't get this to work with pre-existing values. When I run your code and try to call the class, I get a blank input field. The problem is that I can't find any way to prepopulate the value of the field. For example, I am using this to call the class:


<scrollinputtext name="treatment" multiline="true"
x="20" y="30" width="550"
height="300"
text="hello">
</scrollinputtext>


However, when I load the program, "hello" is NOT in the input field.

I have also tried this:


<scrollinputtext name="treatment" multiline="true"
x="20" y="30" width="550"
height="300">HELLO
</scrollinputtext>


But again, when I load the program, "HELLO" is NOT in the input field.

What am I doing wrong???

bytebodger
05-22-2006, 10:23 AM
OK, I've played around with it some more and I've added an "oninit" method when you call <_scrollinputfield> so that it sets the value of the field to whatever was passed into it. See bolded/underlined section below:


<!--
- 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="oninit">
this.setAttribute("text", parent.parent.text);
</method>
<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>

perspolis
08-02-2007, 02:57 AM
hi,

I am using version 4.0.3. the scrollbar is not working.

thanks

mjessup
01-08-2009, 04:50 AM
I added a post for using the standard components to make a scrolling text. It is the thread
http://forum.openlaszlo.org/showthread.php?p=41520