Message-ID: <31D4038B.2D95@3-cities.com>
Date: Fri, 28 Jun 1996 09:08:43 -0700
From: Travis Griggs <tkc@3-cities.com>
Reply-To: tkc@3-cities.com
X-Mailer: Mozilla 2.01 (Macintosh; U; PPC)
MIME-Version: 1.0
Newsgroups: comp.lang.smalltalk
Subject: Re: Q: VW2.5 with actionbutton that behaves like a radiobutton?
References: <31D3DA5F.38E2@rt.el.utwente.nl>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: bigtca106.3-cities.com
Lines: 50
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!nntp.sei.cmu.edu!news.cis.ohio-state.edu!math.ohio-state.edu!usc!elroy.jpl.nasa.gov!decwrl!news.PBI.net!news.mathworks.com!newsfeed.internetmci.com!netnews.nwnet.net!204.203.224.159!

P.B.T.Weustink wrote:
> 
> Hello,
> 
> Is there anyone that can inform me on an easy way to create
> an actionbutton that behaves like a radiobutton in VisualWorks 2.5?
> 
> I subclassed RadioButtonView and wrote my own displayOn: method to
> get an actionbutton look, but somehow I have the idea that there
> must be an easier way to archieve this...
> 
> My approach also fails when a different UI-Look is selected
> (Mac instead of Motif for instance).
> 

You can do what you're trying to do with no subclassing or anything.

Normally, what the UI builder does is take the aspect you define for an 
action button and wrap it up in a block. Then when you're button goes 
down, a block that looks something like

[appModel perform: #actionButtonAspect]

gets evaluated. But you can also hook buttons up to true/false value 
models that return whether the button is up or down. Given such, you can 
make normal buttons work like both check buttons or radio buttons. The 
trick is two fold: 1) you have to beat the UIBuilder to the process of 
doing what he does  by default (as above); 2) you have to provide the 
actual work of figuring out the state of the button.

My approach to this has been as follows:

1) Define you're radioValueModel in your application model (probably in 
an initialize method):

	initialize
		super initialize.
		radioModel := #option1 asValue.

2) In your property tool for your button you still have to give it an 
aspect, in this case, #option1Plug would be a good idea.

3) Add a preBuildWith: method to your application model that looks 
something like:

	preBuildWith: aBuilder
		| plug |
		super preBuildWith: aBuilder.
		"create a pluggable adaptor that queries the state of the radio model"
		plug := (PluggableAdaptor on: radioModel)
												getBlock: [:m | m value == #option1 ]
												putBlock: [:m :v | m value: v ]
												updateBlock: [:m :v :a | true ].
		aBuilder bindingAt: #option1Plug put: plug.

And now you're all ready. Your button will go down and stay down when 
you press it. The value held by radioModel will indicate that it option1 
is selected. As well, if something else changes the value of the 
radioModel, then your button will pop up, just like a radio.

Travis Griggs
tkc@3-cities.com
