Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 14297

Summary: Add a Spinner widget to the SWT toolkit
Product: [Eclipse Project] Platform Reporter: Colin Sharples <sharples>
Component: SWTAssignee: Felipe Heidrich <eclipse.felipe>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: djspiewak, eclipse.felipe, jeff.myers, Konstantin.Scheglov, Mike_Wilson, nick, ovidr, ric.almeida, schtoo, sdavids, snorthov
Version: 2.0Keywords: helpwanted
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 76713    
Attachments:
Description Flags
Spinner for Linux GTK Preview
none
gtk c code - spin button example
none
motif c code - spin button example
none
win32 c code - spin button example none

Description Colin Sharples CLA 2002-04-21 23:54:19 EDT
One widget I am surpised is not in the standard set of SWT widgets is a Spinner. 
I'm sure you know what a spinner is, but to be absolutely clear, I am referring 
to a widget with a text area and two buttons (usually with up and down arrows), 
that is designed to allow easy input of (usually) numeric values, or to iterate 
over an ordered list. Spinners are certainly very common on Windows (I don't 
know if they are native widgets or not), and are a common enough GUI concept to 
have made it into Swing (as of JDK1.4 - javax.swing.JSpinner).
It would be useful if SWT provided an implementation of a Spinner - at the very 
least one that operates on numeric values, although the ability to handle times 
and dates would be nice as well.
Comment 1 Mike Wilson CLA 2002-04-22 10:55:15 EDT
This is not in plan for R2.0, but is something which could be contributed by 
the community.
Comment 2 Veronika Irvine CLA 2002-09-11 14:06:49 EDT
Moving from Later.
Comment 3 Steve Northover CLA 2002-09-12 09:36:14 EDT
*** Bug 4749 has been marked as a duplicate of this bug. ***
Comment 4 Sebastian Davids CLA 2004-02-09 14:21:11 EST
Is there a chance we see this in 3.0?
Comment 5 Steve Northover CLA 2004-02-10 14:12:49 EST
Sorry, it's not on the 3.0 plan.
Comment 6 Anthony Bennis CLA 2004-02-25 10:24:19 EST
Need for a spinner.

This comment is a "vote" for a spinner object in the next release. It's a
useful, common enough widget. I need one at any rate.

Regards,
Anthony Bennis.



Note:

There is code for an example implentation of an SWT spinner at:
http://www.eclipse.org/articles/Article-Writing%20Your%20Own%20Widget/Writing%20Your%20Own%20Widget_files/AppendixE.htm
Comment 7 Daniel Spiewak CLA 2004-06-11 21:56:12 EDT
If we (the eclipse community) wrote an implementation of a Spinner class, could
it be included in the main SWT distro?  That's a big issue for me, not having to
distribute a separate class library.  My thought is that we could start up a new
project (probably on sourceforge, but anywhere else if the eclipse team
prefers), license it under the CPL (I think that's the license SWT uses), all
bug reports, testing and such would be relayed to the project.  And how many
programmers out that are interested in working on such a project?  It's a simple
enough widget.
Comment 8 Steve Northover CLA 2004-06-14 09:40:35 EDT
Yes, it is a simple widget.  It has a few gottchas.  The biggest problem is 
that it doesn't exist on the Mac.  We have an emulated version but might want 
to use Mac specific arrow controls to better match the platform.  I'd like to 
see this control added to SWT post 3.0.  

We certainly welcome any contributions from the community.  If you are 
planning to work on it, put the code here.  Try to keep the API and 
implementation as minimal as possible, in keeping with the philosophy of the 
rest of SWT.  You never know what you might find on the other platforms!
Comment 9 Daniel Spiewak CLA 2004-07-02 23:46:11 EDT
Actually, the control does exist in native form on Mac.  However, it took me
about three *hours* of digging through non-existing cocoa docs to find it.  It
does exist, but under a different name.  Anyone interested in developing this
widget contact me at daniel.spiewak (at) gawab.com.  I intend to use as much
already written code as we can.  I.E. we're going to use the Motif and Win32
code provided in the 'Create New Widgets in SWT' tutorial (thanks Steve) and
base our implementation off that.  We need a C developer familiar with GTK, and
a C developer familiar with Cocoa.  And, if it's not too much to ask, a C
developer and Java developer (testor) familiar with Photon (since I don't have
that system).  Anyone interested contact me directly, and we'll get started.
Comment 10 Daniel Spiewak CLA 2004-09-05 00:24:48 EDT
Created attachment 14407 [details]
Spinner for Linux GTK Preview

I've finished writing and testing the preview form of the GTK Spinner widget. 
It's based on the widget written by Steve in his excelent article on writing
custom widgets.  The only problem I had was porting the widget from a subclass
of Composite, to a subclass of Control.  I was dissappointed that the article
had not addressed the issues and hacks nessisary to do this, but it's still a
great article.	Anyway, I digress.  The code I'm attaching is perfectly usable
on GTK (I'm not attaching the emulated form or the Win32 or Motif versions
since they're available for download (actually copy/paste) elsewere on the
site) and I'm actually using it in an app I'm developing.  The native methods
are contained in the Spinner class itself.  However, it shouldn't be too hard
to move them to the OS class.  There really aren't any inter-dependancies.  I'm
hoping to get the Motif version to work soon.  I don't have a compiler or a
version of 'make' for Windows yet nor consistant access to a machine running
said OS, so it will probably be at least another month before the Spinner on
Windows is published.  As far as Mac, I'm sticking with the emulated form until
I can sit down and find some documentation on the arrow control used on Mac and
how to write JNI libs for Mac; two subjects about which I haven't a clue. 
Anyway, enjoy what I've got, and let me know what you think!!
Comment 11 Felipe Heidrich CLA 2004-09-15 17:05:32 EDT
Created attachment 14561 [details]
gtk c code - spin button example

The problem with GtkSpinButton is that it does not allow you to have a strings
list, it is only numeric.
Doc:
http://www.gtk.org/tutorial/sec-spinbuttons.html
http://developer.gnome.org/doc/API/2.0/gtk/GtkSpinButton.html
Comment 12 Felipe Heidrich CLA 2004-09-15 17:06:57 EDT
Created attachment 14562 [details]
motif c code - spin button example

Motif API is very good, support numeric (int and float) and strings, easy to
use.
http://www.ist.co.uk/motif/books/vol6A/ch-15.fm.html
Comment 13 Felipe Heidrich CLA 2004-09-15 17:09:38 EDT
Created attachment 14563 [details]
win32 c code - spin button example

Win32 provides UpDown and Edit Control, it gives you a little bit of work but
you can do whatever you need (int, floats, strings).

http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/updown/updown.asp
Comment 14 Felipe Heidrich CLA 2004-09-15 17:10:59 EDT
I have no idea what photon provides.
I didn't implement a Mac example but it looks similar with Win32.
Comment 16 Steve Northover CLA 2004-09-15 17:38:05 EDT
Looks like the API better only accept numbers then.
Comment 17 Daniel Spiewak CLA 2004-09-17 10:29:05 EDT
The (unstated) goal of this project is to provide a Spinner widget which
supports integer values.  I have considered float values, but I don't intend to
implement it just yet.  Let's get the API off the ground first, and then we can
expand before the final release.  Text lists I never considered seeing as SWT
has two excelent text list tools (List and Combo) and I didn't see the need for
a third.  Also, to be quite honest, I've never even seen a combo with a text
list.  Steve has pretty much summed up the answer to the difficulties you
presented, the API had better only accept numerical input.
Comment 18 Felipe Heidrich CLA 2004-11-17 17:28:09 EST
Fixed > 20041117.
Spinner added to all platforms.
Comment 19 Felipe Heidrich CLA 2004-11-17 17:29:21 EST
Fixed > 20041117.
Spinner added to all platforms.
Comment 20 L.M. Fridael CLA 2004-12-08 05:45:39 EST
The problem with the current Spinner implementation on Windows is that the
visual appearance does not reflect the Enabled status. More to the point, when
the widget is disabled, it is not "greyed out" as other widgets are.

A quick hack for Windows is to override setEnabled() and use the Text and UpDown
handles to disable the controls.

public void setEnabled(boolean enabled) {
  checkWidget();
  OS.EnableWindow(hwndText, enabled);
  OS.EnableWindow(hwndUpDown, enabled);
}

I'm not sure if this has any serious side-effects, but it works for me.
Comment 21 Steve Northover CLA 2004-12-08 10:32:43 EST
Good catch.  I just fixed Windows.  Checking the other platforms.  FYI:  The 
real fix on Windows is:

void enableWidget (boolean enabled) {
	super.enableWidget (enabled);
	OS.EnableWindow (hwndText, enabled);
	OS.EnableWindow (hwndUpDown, enabled);
}