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 » U++ Widgets - General questions or Mixed problems » EditString validation
EditString validation [message #20065] Mon, 16 February 2009 00:10 Go to next message
Kajko is currently offline  Kajko
Messages: 14
Registered: December 2008
Location: Ireland, Serbia
Promising Member
Hi everybody...
I have interesting problem. Code:

class ccc : public TopWindow {
public:
typedef ccc CLASSNAME;

EditString str1;
EditString str2;
EditString str3;

ccc()
{
SetRect( 0, 0, HorzLayoutZoom(430), VertLayoutZoom(485) );

Add(str1.LeftPosZ(100, 300).TopPosZ(10, 20));
Add(str2.LeftPosZ(100, 300).TopPosZ(30, 20));
Add(str3.LeftPosZ(100, 300).TopPosZ(50, 20));

};
};


GUI_APP_MAIN
{
ccc().Run();
}


Is there anyway to validate string input BEFORE string lose focus and prohibit losing focus if valid fails ?
I will try to explain better...
Let say that only valid input in str2 is str1 + something. When user wants to leave str2 (K_ENTER, K_UP, K_DOWN, etc...) I would like to validate str2 and keep focus on str2 until text entered is not right.
I do not know did i make my self clear...

Cheers
Sasa


b78a07c7fb9b68436af9fd23f4e76cc5
Re: EditString validation [message #20066 is a reply to message #20065] Mon, 16 February 2009 08:17 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
IMO only via ChildLostFocus. Store the "last" focus in ChildGotFocus, then in ChildLostFocus do validation (dynamic_cast or comparison to find out which widget lost focus needed), then if validation fails, restore the focus to the "last".

Mirek
Re: EditString validation [message #20078 is a reply to message #20065] Mon, 16 February 2009 14:16 Go to previous messageGo to next message
Kajko is currently offline  Kajko
Messages: 14
Registered: December 2008
Location: Ireland, Serbia
Promising Member
Thanks for an answer...
now look at this if you please:

class ccc : public TopWindow {
public:
typedef ccc CLASSNAME;

EditString str1;
EditString str2;
EditString str3;

ccc()
{
SetRect( 0, 0, HorzLayoutZoom(430), VertLayoutZoom(485) );

Add(str1.LeftPosZ(100, 300).TopPosZ(10, 20));

Add(str2.LeftPosZ(100, 300).TopPosZ(30, 20));
str2.cbValid << THISBACK( validStr2 );

Add(str3.LeftPosZ(100, 300).TopPosZ(50, 20));

};

bool validStr2()
{
PromptOK( "ss" );
return true;
}

};


GUI_APP_MAIN
{
ccc().Run();
}


in CtrlCore.h i added:
class Ctrl : public Pte<Ctrl> {
public:
>>>>>>>>>THIS>>>>>>> Gate cbValid;
...

and in Ctrl.cpp i added this:
void Ctrl::LostFocus() {
>>>>>>>>>THIS>>>>>>> if( cbValid() )
>>>>>>>>>THIS>>>>>>> SetFocus();
}

so if cbValid() return true, stay where you are Smile)

BUT validStr2 HAS NEVER been called. Any idea why ?

Thanks,
Sasa


b78a07c7fb9b68436af9fd23f4e76cc5
Re: EditString validation [message #20079 is a reply to message #20078] Mon, 16 February 2009 15:37 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well....

first of all, it is BAD IDEA to alter U++ sources...

Anyway, in this case, the trouble is that LostFocus is overriden in EditString.

You might do it the right way, inheriting EditString class to some "EditStringWithGotFocusCallback" and overriding LostFocus again. Just do not forget to call inherited version (it does something important).

Mirek
Re: EditString validation [message #20080 is a reply to message #20065] Mon, 16 February 2009 16:09 Go to previous message
Kajko is currently offline  Kajko
Messages: 14
Registered: December 2008
Location: Ireland, Serbia
Promising Member
Thanks.

That worked...i was just thinking general approach Smile)

Thanks again
Sasa


b78a07c7fb9b68436af9fd23f4e76cc5
Previous Topic: What is ParentCtrl?
Next Topic: Help needed dealing with switch control
Goto Forum:
  


Current Time: Fri Mar 29 02:44:06 CET 2024

Total time taken to generate the page: 0.01389 seconds