View Source Code

It’s always handy to take a peek at the source code for a class you’re using, to see how it works. Of course, every attribute, method and event should be documented in detail, but sometimes they’re not, and you need access to the source code. With OpenLaszlo Lz components (e.g. button, edittext, etc.), that’s pretty straightforward. You just look at your local developer install of OpenLaszlo, under lps/components/lz/….

With Laszlo Foundation Classes, such as view, the source code is not present in the developer distribution. So unless you have an OpenLaszlo build environment, you won’t find it in your file system.

All is not lost, however, since the OpenLaszlo project uses Subversion for source control. That means that you can browse the source code via the web interface:

http://svn.openlaszlo.org/openlaszlo/

The very latest view code (from trunk) is located here. And the view code from OpenLaszlo 3.4 is located here. The Laszlo Foundation Class code is generally found in WEB-INF/lps/lfc/… of that particular version.

The Mouse Wheel in OpenLaszlo

In OpenLaszlo, scrollbars don’t automatically scroll with the mouse wheel. I guess the reason behind this is that scrollbars are very free-form. As a developer, you can make anything scroll, so it would be restrictive if the scrollbars were to respond to mouse wheel events in a predefined way.

To see how to use a scrollbar in OpenLaszlo, see my earlier post on the subject.

It’s really easy to trap mouse wheel events in OpenLaszlo. All you do is listen for the onmouswheeldelta event from the LzKeys service. That’s also the service that sends global keyboard events, by the way. The onmouswheeldelta event sends an argument, which tells you how much the wheel moved, and in what direction (it’s either a positive or a negative number).

To tie this to a scrollbar, you probably want to ensure that the mouse is actually overing above the view you want to scroll. Again, in OpenLaszlo, that’s really easy. There’s a containsPt() method on view, that tells you whether a given point (x,y) is within that view’s coordinate space. And to find the mouse position in a given views coordinate space, you simply call:

LzView.getMouse(“x”) and LzView.getMouse(“y”)

So here’s the application in action. Note that you might need to bring focus from the browser to the SWF by clicking once on the SWF:

Enjoy! (Here's the source to a Mouse Wheel Example).

OpenLaszlo 4.0.3 Released… stretches, and mini-me!

Last week, OpenLaszlo 4.0.3 was released (without much fanfair, since it’s a bugfix release). One little-noticed bug that I’m happy to see fixed is the stretches attribute.

The stretches attribute lets you stretch a resource to fit the view it’s attached to. The thing is, that stretches was always supposed to adjust the view’s entire coordinate space relative to the size of the image.

To see what I mean, play around with the larger window below:

Notice how the contents of that window - the resource and the smaller window - all resize simultaneously. I'm not sure of the practical applications of this yet, but it makes for a nice effect.

You can download the source for the above application if you like. Remember to compile in OpenLaszlo 4.0.3.