LinkButton

Update 23rd Feb 2006: Ted Bracht has kindly ported the LinkButton and DropContainer packages to Dolphin 6. The download is here. Thanks Ted!

By: Steve Waring
Home Pages: Journal Dolphinharbor
Created: 20030118
Last Update: 20030118

Overview

This package contains a View class for Dolphin Smalltalk, that implements a commandSource that looks and feels like a web link. It can be used in place of a PushButton or other commandSource.

linkButton

The above screenshot is from the sample application that can be used to explore the various styles.

Implementation

There are three aspects in understanding how the SWLinkButton class works;

1) State - onMouseMove

An instance will move from the #out state to the #in state when it is sent the #onMouseMove: message. At this point it asks windows to start sending WM_TIMER messages every 150ms. It will move from the #out state to the #hover state if it is sent an #onTimerTick message and the cursor is still over the view. If it is in either the #hover or #in states, and it is sent an #onTimerTick message and the the cursor is not over the view, it goes back to the #out state.

2) Painting - ImageList

SWLinkButton includes various styles that control padding/icon justification, and how to display that the view is 'hot', including whether the text should be underlined, text colors and if/how to blend the icon.

Only Icon images are supported at this stage because the view uses an ImageList to draw onto the PaintEvent's canvas. This makes the implementation very efficient in terms of External Resources used, and the ImageList functions can be used to apply the various effects as it draws the icon.

3) Command Framework

Before an instance asks windows to re-paint it (ie #invalidate) it firstly validates the UserInterface (#validateUserInterface). This hooks into Dolphin's powerful command framework, which sends a query along the presenter chain, and allows any presenter to update the commandDescription. This updated information is what is painted into the view.

Background

I have been using various techniques for tracking whether the mouse is hovering over a view, but all my previous implementations were presenter based.

I thought I need the flexibility of a Container presenter that could contain any number of subViews, that would somehow change when the cursor moved into the parent container. This involved hacking into the subView's interactors, and could get heavy on resource usage; each typical link needed a Container view/presenter and image view/presenter and a StaticText view.

I have seen some complaints that #queryCommand: methods are ugly ... if you want to see ugly, try implementing your own dynamic commands!. When I changed some of my main presenters from using (the mouse-over) presenters to (the SWLinkButton) commandSource views, the code just melted away. The command framework and #queryCommand: started doing all the work.

The SWLinkButtonSampleShell presenter, which implements the Shell in the above screenshot, contains only 8 methods, and only one is more than one line long. If I had done that same Shell using my mouse-over container presenters ... arg, not even worth thinking about!

This project has certainly further increased my respect for the power of Dolphin's commands.

ToDo

I am thinking of adding a fourth state that is entered if two timer ticks are received and the cursor is still over the view, and using this to trigger an event to popup some tooltip help.

Downloads

The packages are released under the OpenBSD license (ie free). The "SW LinkButton.pac" package contains the view class. The "SW LinkButton Sample.pac" contains the Sample shell and the SessionManager that was used to deploy the test ToGo.

The ToGo is released as TestWare ... if you have a problem with the code or technique in your environment, you will be doing me a favor by letting me know about it.

Notes:



Copyright Steve Waring 2003.