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 » What way is best to implement Callback for GotFocus/LostFocus?
What way is best to implement Callback for GotFocus/LostFocus? [message #11006] Mon, 13 August 2007 22:48 Go to next message
jlfranks is currently offline  jlfranks
Messages: 57
Registered: May 2007
Location: Houston, TX, USA
Member
We are solving the problem of editing a control in a touchschreen application.

For example, when EditString gets focus, we want to show a keyboard and be able to press buttons in order to modify the content of the control.

The first issue is generalizing the solution so that we can apply this to multiple EditString controls, or even EditDouble, EditInt.

One way is to derive from EditString and over-ride GotFocus() and LostFocus (), along with supporting API to set the callbacks for each.

A different approach is to hook the mouse event, check for the control of interest and with additional API and call the appropriate callbacks for various events/controls.

Which way is more desirable from a design viewpoint? Or, is there
another approach different from these?

--jlf
Re: What way is best to implement Callback for GotFocus/LostFocus? [message #11014 is a reply to message #11006] Tue, 14 August 2007 10:58 Go to previous message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
You can actually implement this in a general way quite easily, and without having to derive anything.

Ctrl has two methods, ChildGotFocus and ChildLostFocus, that you can overload in the parent window to catch the event. Then you just have to see if an edit ctrl has the focus:
	virtual void ChildGotFocus() {
		Ctrl *c = GetFocusChild();
		if (!c || !c->IsEditable()) return;
		 
		if (dynamic_cast<EditField *>(c) || dynamic_cast<TextCtrl *>(c)) {
			// Show keyboard
		}
	}

	virtual void ChildLostFocus() {
		// Unless focus has moved to the keyboard, hide it here
	}

You may need to add some other control types, or use
GetFocusChildDeep if you use ArrayCtrls. This is not the only other solution though.

James
Previous Topic: "ScrollArea"...
Next Topic: Is there an equivalent of win32 API "SendMessage" in U++
Goto Forum:
  


Current Time: Sat Apr 27 23:52:32 CEST 2024

Total time taken to generate the page: 0.03177 seconds