Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » LineEdit, EditFields, DocEdit » EditMinMax ctrl implementation
EditMinMax ctrl implementation [message #1032] Wed, 15 February 2006 20:52 Go to next message
pivica is currently offline  pivica
Messages: 57
Registered: November 2005
Location: Belgrade, Serbia
Member
I have next problem. I'm using EditDouble ctrl with min and max limits. Current implementation of checking min/max boundaries isn't good for me. For example, boundary checking is done when window with EditDouble ctrl is closing. It would be much better to check limits when EditDouble ctrl lost its focus.
Well after couple of hours trying to implement some good solution in CtrlLib\EditField.cpp I give up. Problem is that I couldn't effectivly implement LostFocus() in EditValue class because EditString is inherit from it, too. In the end, here is something I've manage to implement:

template <class DataType, class Cv>
class EditMinMax : public EditValue<DataType, Cv> {
public:
	virtual void  LostFocus();

	// rest of class EditMinMax...
};

template <class DataType, class Cv>
void EditMinMax<DataType, Cv>::LostFocus()
{
	DataType dt;
	
	if (!EditMinMax<DataType, Cv>::text.IsEmpty() && IsNumber(dt)) { // Checking int and double.
		String s = EditMinMax<DataType, Cv>::text.ToString();
		
		CParser p(s);
		if (p.IsDouble())
			dt = p.ReadDouble();	// gcc warning: converting to `int' from `double'?
		else if (p.IsInt())	// Not doing well for doubles - returns true in 602b version?
			dt = p.ReadInt();
		
		if (dt < Cv::GetMin())
			s = AsString(Cv::GetMin());
		else if (dt > Cv::GetMax())
			s = AsString(Cv::GetMax());
		
		WString text1(s);
		EditMinMax<DataType, Cv>::text = text1;
	}

	EditField::LostFocus();
}


Anyway I don't like how EditMinMax ctrls are working. My opinion is that it would be much better to check limits when EditMinMax lost its focus. But if this can't be done in U++ level, I guess I will have to implement my own EditMinMax ctrl.
Re: EditMinMax ctrl implementation [message #1036 is a reply to message #1032] Wed, 15 February 2006 21:19 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Personally, I find idea of always screaming programs not very palatable (it is not unlikely that I notice problem in another field, but I am not allowed to fix it until I fix the current - I do not like this).

Also, think about pressing the Cancel button... (I know, it can be resolved to a degree, OTOH it would not be possible in normal Win32 where pressing button moves the focus). I do not like the idea of not being able to cancel dialog until I fix values in it....

However, I think that it is worth considering adding "CheckOnFocus" or something like that in EditField - it is not that hard to do.

(But you will have to wait, I do not want to compromise new release...)

Mirek
Re: EditMinMax ctrl implementation [message #1039 is a reply to message #1036] Wed, 15 February 2006 21:46 Go to previous messageGo to next message
pivica is currently offline  pivica
Messages: 57
Registered: November 2005
Location: Belgrade, Serbia
Member
> Personally, I find idea of always screaming programs not very palatable (it is not unlikely that I notice problem in another field, but I am not allowed to fix it until I fix the current - I do not like this).

I agree with you. Better would be to allow ctrl to automaticly fix wrong value.
So for example there is EditDouble with min -15 and max 145. If a user enter -20 then on lost focus ctrl should correct value to -15. Also when user enter 1000, on lost focus there would be 145.
Re: EditMinMax ctrl implementation [message #1041 is a reply to message #1039] Wed, 15 February 2006 22:12 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
IMO, this could lead into silently ignored problems...

Mirek
Re: EditMinMax ctrl implementation [message #1046 is a reply to message #1041] Thu, 16 February 2006 07:44 Go to previous messageGo to next message
pivica is currently offline  pivica
Messages: 57
Registered: November 2005
Location: Belgrade, Serbia
Member
Yes, but in some situations it would be nice behavior. Best would be to have something like CheckOnFocus, as you wrote, and with that method to tell control should it fire pop up dialog or auto correct value.
Re: EditMinMax ctrl implementation [message #1052 is a reply to message #1046] Thu, 16 February 2006 17:17 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Would need changes to Convert (something that did not happen for 5 years). Possible, but I am always reluctant to change core classes...

Meditate about this I will Smile

Mirek
Re: EditMinMax ctrl implementation [message #1053 is a reply to message #1052] Thu, 16 February 2006 17:19 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
BTW, with the right Convert, you should be able to achieve this now (just implement adjusting in Scan).

Mirek
Re: EditMinMax ctrl implementation [message #1057 is a reply to message #1053] Thu, 16 February 2006 17:40 Go to previous messageGo to next message
pivica is currently offline  pivica
Messages: 57
Registered: November 2005
Location: Belgrade, Serbia
Member
Will try..
Re: EditMinMax ctrl implementation [message #1059 is a reply to message #1057] Sat, 18 February 2006 23:36 Go to previous messageGo to next message
hojtsy is currently offline  hojtsy
Messages: 241
Registered: January 2006
Location: Budapest, Hungary
Experienced Member
Let me add one more viewpoint. I think it is good to show visual clues if some fields contain invalid values, but popup windows are too annoying. How about adding a reddish tint to the background color of EditFields which contain an invalid data? I made the implementation in EditField::Paint, by adding these two lines:
if(convert && convert->Scan(text).IsError()) 
		paper = Blend(paper, Color(255, 0, 0), 32);

It shows if the data is valid while you are typing it. I attach the modified file.
  • Attachment: EditField.zip
    (Size: 3.27KB, Downloaded 2006 times)
Re: EditMinMax ctrl implementation [message #1060 is a reply to message #1059] Sat, 18 February 2006 23:53 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, not a bad idea either, however, original idea was to "accept" the value(s) when user makes an action to "commit" data - either by pressing "OK" button or e.g. in ArrayCtrl when pressing Enter.

I am not sure whether when pressing "OK", the dialog should just make invalid fields red (also, the current protocol would make just one red...).

However, as an option, why not?

Mirek

Re: EditMinMax ctrl implementation [message #1061 is a reply to message #1060] Sat, 18 February 2006 23:54 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
OOps misinterpreted you. Well, when typing, it would look really nice Smile

Mirek
Re: EditMinMax ctrl implementation [message #1062 is a reply to message #1061] Sun, 19 February 2006 00:15 Go to previous messageGo to next message
hojtsy is currently offline  hojtsy
Messages: 241
Registered: January 2006
Location: Budapest, Hungary
Experienced Member
luzr wrote on Sat, 18 February 2006 17:54

OOps misinterpreted you. Well, when typing, it would look really nice Smile

That's it! Try it out and see what I mean. This is not a replacement for the popup which comes when the window is closed, but an early clue so the user can avoid errors. By the way it does not only work for min-max ranges. Just try out a DateEdit after this modification: if you enter an invalid date it is displayed with red background.
Re: EditMinMax ctrl implementation [message #1064 is a reply to message #1062] Sun, 19 February 2006 07:11 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Yes, that is how Convert was designed, is not it? Smile

Mirek
Re: EditMinMax ctrl implementation [message #1078 is a reply to message #1064] Sun, 19 February 2006 19:46 Go to previous messageGo to next message
pivica is currently offline  pivica
Messages: 57
Registered: November 2005
Location: Belgrade, Serbia
Member
I like hojtsy idea and I hope that something of all this will be in next upp version:)
Re: EditMinMax ctrl implementation [message #1081 is a reply to message #1078] Sun, 19 February 2006 22:56 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
if(convert && convert->Scan(text).IsError()) 
		paper = Blend(paper, Color(255, 0, 0), 32);


is now part of uppsrc. And indeed, it looks very nice.

I just resrve the right to remove it if during next week my users complain about it Wink

Mirek
Next Topic: Limited EditString...- MaxChars [SOLVED AND FIXED...]
Goto Forum:
  


Current Time: Thu Mar 28 20:45:09 CET 2024

Total time taken to generate the page: 0.01640 seconds