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 » Lost focus in edit fields
Lost focus in edit fields [message #22603] Thu, 30 July 2009 10:17 Go to next message
Zbych is currently offline  Zbych
Messages: 325
Registered: July 2009
Senior Member
Hi,

Is there a way to trigger a callback when edit filed loses its focus? Right now I added a callback (WhenLostFocus) to EditField::LostFocus, but maybe there is already some other method to do it?
Re: Lost focus in edit fields [message #22611 is a reply to message #22603] Sat, 01 August 2009 08:56 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
ChildLostFocus can be used sometimes... (but you have to store the pointer in ChildGotFocus).

Mirek
Re: Lost focus in edit fields [message #22615 is a reply to message #22611] Sat, 01 August 2009 10:43 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
HI,

Quote:

is already some other method to do it


I had the same problem some time ago and did something this:

template < class T >
class EnhancedEditField : public T
{
	public:
		typedef T BaseClass;
		EnhancedEditField() {};
		virtual ~EnhancedEditField() {};


		Callback whenFocusLost;
		
		virtual void LostFocus()
		{
			T::LostFocus();
			whenFocusLost();
		}
};

typedef EnhancedEditField<EditString> EnhancedEditString;
typedef EnhancedEditField<EditInt> EnhancedEditInt;
typedef EnhancedEditField<EditDouble> EnhancedEditDouble;



It adds a callback to the type <T> and does what you want while avoiding modifying upp src.

Since nobody asked for this feature before maybe our way of doing things is a little clumsy ? ? ?


Re: Lost focus in edit fields [message #22618 is a reply to message #22615] Sat, 01 August 2009 11:16 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
It is fine. I believe there is similar WithLostFocus template in the "extended universe". Note that the issue is not EditField related..

Mirek
Re: Lost focus in edit fields [message #22620 is a reply to message #22615] Sat, 01 August 2009 11:41 Go to previous messageGo to next message
Zbych is currently offline  Zbych
Messages: 325
Registered: July 2009
Senior Member
Didier wrote on Sat, 01 August 2009 10:43

It adds a callback to the type <T> and does what you want while avoiding modifying upp src.


I don't really mind modyfing upp src Smile, esspecially when it is just two lines (one in *.cpp and one in *.h):
EditField.cpp :

void EditField::LostFocus()
{
	if(autoformat && IsEditable() && !IsNull(text)) {
		Value v = convert->Scan(text);
		if(!v.IsError()) {
			const Convert * cv = inactive_convert ? inactive_convert : convert;
			WString s = cv->Format(v);
			if(s != text) text = s;
		}
	}
	if(!keep_selection) {
		anchor = -1;
		cursor = sc = 0;
		WhenLostFocus();//<--here
	}
	Refresh();
	SyncEdge();
}

[Updated on: Sat, 01 August 2009 11:42]

Report message to a moderator

Re: Lost focus in edit fields [message #22622 is a reply to message #22620] Sat, 01 August 2009 12:25 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
I can't find the 'WithLostFocus' template.

What is the "extended universe" ???

Re: Lost focus in edit fields [message #22625 is a reply to message #22620] Sat, 01 August 2009 14:28 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Zbych wrote on Sat, 01 August 2009 05:41

Didier wrote on Sat, 01 August 2009 10:43

It adds a callback to the type <T> and does what you want while avoiding modifying upp src.


I don't really mind modyfing upp src Smile, esspecially when it is just two lines (one in *.cpp and one in *.h):



That is really bad idea. Over long time, you will not be able to keep your U++ sources merged..

Mirek
Re: Lost focus in edit fields [message #22626 is a reply to message #22622] Sat, 01 August 2009 14:30 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Didier wrote on Sat, 01 August 2009 06:25

I can't find the 'WithLostFocus' template.

What is the "extended universe" ???




Well, what is in upp.src is a selection of sources usually originated in development of some "real" apps.

I know that WithLostFocus exists in some of Tom's sources, which are not part of uppsrc now (yet?).
Re: Lost focus in edit fields [message #22629 is a reply to message #22626] Sat, 01 August 2009 16:23 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hi Milek,

Maybe this 'WithLostFocus' template could be put int 'CtrlUtil.h'

Re: Lost focus in edit fields [message #27676 is a reply to message #22603] Thu, 29 July 2010 11:42 Go to previous messageGo to next message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
What's the status of WithLostFocus? I also want to trigger a few actions when a widget (EditField in my case) looses focus.

Jeremy
Re: Lost focus in edit fields [message #27677 is a reply to message #27676] Thu, 29 July 2010 12:57 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
Just use the one from this thread in your own code, though it doesn't need as much code as above:
template <class T>
struct WithLostFocus : public T {
		Callback WhenLostFocus;
		
		virtual void LostFocus() {
			T::LostFocus();
			WhenFocusLost();
		}
};

[Updated on: Thu, 29 July 2010 12:58]

Report message to a moderator

Re: Lost focus in edit fields [message #27683 is a reply to message #27677] Thu, 29 July 2010 14:54 Go to previous messageGo to next message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
Thanks. A slight typo fix though:

template <class T>
struct WithLostFocus : public T {
		Callback WhenLostFocus;
		
		virtual void LostFocus() {
			T::LostFocus();
			WhenLostFocus();
		}
};


i.e. WhenFocusLost() changed to WhenLostFocus();

Jeremy
Re: Lost focus in edit fields [message #45067 is a reply to message #22615] Thu, 27 August 2015 09:05 Go to previous message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
Hi there,
my very first message so excuse the dumb question.

I am a little noob and not really experienced with C++ programming. I am trying to do the same as in this thread: add an action when focus is lost on an EditString field. I think that your solution is what I am looking for, but I do not know how to make it work. I could really use an example i.e. where to put your code and how to "connect" the lost focus event with my procedure.

Thanks in Advance.
Giorgio
Previous Topic: How to add a currency symbol to an EditDoubleSpin?
Next Topic: What do you think about this approach to making CodeEditor more user extendable?
Goto Forum:
  


Current Time: Thu Mar 28 16:53:27 CET 2024

Total time taken to generate the page: 0.01679 seconds