wxSpinCtrl is very convenient, but it does lack one feature: it
doesn't prevent the user from typing non-numeric characters into the
text box. What would the developers think about adding a style flag to
wxSpinCtrl that causes it to drop non-numeric WM_CHAR events? I've
looked at the wxSpinCtrl code and I don't think it should be very hard
to do, but I want a second opinion.
If anyone agrees this would be a good thing and wouldn't cause any
problems, I would like to work on this and submit a patch, as I need
this ability in a program I'm writing.
I also found, in the wx-users archive, that someone has written a
"wxIntCtrl" that apparently does exactly this. Is anyone using this?
If I do work on adding this style to the mainstream wxSpinCtrl, is
there anything else neat about the wxIntCtrl that I should keep in
mind?
Thanks,
--
David Norris
dano...@gmail.com
Is there any reason why it is not included in official distribution?
It sounds to me that it should replace wxSpinCtrl.
I also don't understand why is text in wxSpinCtrl left aligned? The
control is showing numbers, so right-alignment seems like only
reasonable option.
--
Milan Babuskov
http://fbexport.sourceforge.net
http://www.flamerobin.org
David,
Thanks! I haven't had a chance to take a look at it yet but I'll let
you know when I do... it sounds like exactly what I was wanting.
Gratefully,
--
David Norris
dano...@gmail.com
> David Elliott wrote:
>> No problem! On account of "popular" demand I've put this up on
>> tgwbd.org.
>> http://www.tgwbd.org/downloads/wxSpinTextCtrl/
>> so I'm interested to know if it still works, particularly with all
>> the sizing changes.
>
> I tried to add it to my project as one of the files. Is that possible?
>
> Using wxMSW 2.5.4 I get:
>
> Error E2321 .\src\spintext.h 105:
> Declaration does not specify a tag or an identifier
>
> Line 105 is:
> DECLARE_DYNAMIC_CLASS(wxSpinTextCtrl);
>
> Do I have to do something special to add it to project, or I have to
> somehow compile it with wx sources? And how would I go about that?
>
No, I think you just have to remove the semicolon. I use gcc and it
doesn't complain about this.
-Dave
David,
I got it to build in CVS HEAD; I just had to wrap all the strings in
wxT() to make the Unicode build work. However, there are some quirks,
at least in GTK:
- up/down arrow keys don't work
- the spinner is too tall and gets clipped at the bottom edge, only a
few pixels of the down button are visible
But otherwise it works great. I imagine both of these problems are
easy to fix and I'll see what I can do. If I get them fixed I'll
return the modified sources to you.
To clarify the license, can I put your source files into a GPL'd app
I'm writing (assuming I can fix those two quirks)?
In any case, thank you very much for the code :)
--
David Norris
dano...@gmail.com
Ah hah, I see a /* TODO */ in OnChar() :-) I'll fill it in...
> - the spinner is too tall and gets clipped at the bottom edge, only a
> few pixels of the down button are visible
I think I have this fixed. Seems to be working in GTK. I'll test it on
MSW this evening and send you the changes.
Thanks again!!
--
David Norris
dano...@gmail.com
That was the problem (I use Borland). So, it does work with wx2.5.4.
Beside removing the semicolon I didn't have to touch anything.
It works very good. Only numbers can be entered, and what I like the
most, wxTextCtrl is the main control, so when I set the tooltip for
wxSpinTextCtrl user does not have to go to Spin to see the tip.
Although, I believe the correct behaviour would be to set the tooltip
for both controls.
If it would have option to right-align it, it would be perfect :)
I can add this for you. I'll also make the tooltips set for both
controls. David, I'm afraid that I've gone and changed quite a bit in
the process of adding a couple of features... I hope you won't be
offended at what I've done to your code... :-/
I'll post it as soon as I test on MSW.
--
David Norris
dano...@gmail.com
It works :)
Great, thanx.
I wasn't talking about validators, that is fine. I was talking about
initial value. I can't use wxSpinTextCtrl constructor with doubles.
Anyway, it's really no big deal, so you may just as well forget I
wrote anything :)
>>- where do we have to apply so that this goes in main wx tree, and
>>replace (now obsolete?) wxSpinCtrl?
>
> Another issue is that this wxSpinTextCtrl is a generic control.
I wasn't aware of this.
> wxSpinCtrl has native definitions on a few platforms (notably GTK). So
> a really correct fix would need to keep those native controls around,
> not replace them. The right thing to do IMHO is to work on the
> existing wxSpinCtrl to add the validator support. Then it's backward
> compatible and uses native controls when applicable.
Makes sense.
> Thoughts?
I hope someone else is reading this discussion too.
Well, until (if at all) changes are made to wx lib, I think I'll
simply include wxSpinTextCtrl in my project and use it. I might even
add some features like support for floating-point numbers with
properties like "number of decimals".
You're right, in your original version you can pass in any validator
that a wxTextCtrl will accept. But I don't think it will behave
correctly if you use a float validator. The current code expects
everything to be an integer. ToLong() will fail for e.g. "3.14159,"
and anytime you press the spin button it will be reset to the last
known good integer plus or minus one. Wouldn't be too terribly hard to
fix this though.
I changed the validators around because it was more convenient (for me
at least) to be able to use wxGenericValidator(int) for the
wxSpinTextCtrl as a whole. I don't think wxTextCtrl will accept a
wxGenericValidator, will it?
Clearly there's a lot of room for improvement here. Again I think the
right way to do it is for the control to handle the validator directly
instead of passing it through to either of the two subcontrols. (Also
remember that there may only be one subcontrol if native controls are
used, like in GTK). The controller code in wxSpinTextCtrl would then
need to be smart enough to do the right thing with the subcontrols
depending on which validator (int, float, etc.) is used. Or maybe it
would be useful to create a new validator for this purpose?
Other potential additions could be support for other bases (hex,
octal, binary), although I'm not sure how many people would actually
need this. Probably not worth the time up front, but it might be worth
thinking about so that it can be designed in a way that allows this to
be added later.
--
David Norris
dano...@gmail.com
Ah, true. Well, I can't think of any cases where you'd need to
override an intelligent default then, but it can't hurt to make the
virtual method just in case!
> > Was it possibly because of ints vs. shorts? I noticed in your code
> > that the range was set in one place to be [min int, max int] but in
> > another place to be [min short, max short]. Maybe at one time in the
> > past wxSpinButton only used shorts for the range
>
> It still does for people who have older versions of comctl32.dll, like on
> Windows98?
Really? I know the default GETPOS/SETPOS messages took shorts, but I
thought the GETPOS32 variants were always available. MSDN documents it
as being available since Win95, although it's been known to lie. I do
see that there are #ifdefs in the wxSpinButton source to fall back to
GETPOS if the 32-bit variant isn't defined. I wonder if it's
necessary.
> I'm not so sure, but I did try now on Windows98 SE, and it works.
But in any case, even if it does only support shorts, you'd only see
errors if you tried to get/set a value above 32767 or below -32768. In
other words it should work fine within the intersection of the
interval [minint, maxint] and the interval supported by the native
control. Should be sufficient for *most* apps.
--
David Norris
dano...@gmail.com
Any-one ;)
> I don't personally have time to
> work on it anymore right now (I've overcommitted myself to some other
> things) but I do want to do it at some point. Hopefully next week I'll
> have a bit more time to play around.
>
> Until then there's nothing stopping anyone else from making more changes!
Well, I don't need it right now, since my project is far from release time,
but I might add it later if nobody does in the meantime.