wxTextCtrl Incorrect Focus Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Tapsa
Earned some good credits
Earned some good credits
Posts: 147
Joined: Tue Dec 06, 2011 5:52 pm
Location: Helsinki

wxTextCtrl Incorrect Focus

Post by Tapsa »

The following customized wxTextCtrl did work with wxWidgets 2.8.12 but not with 2.9.3. I need it for checking wxTextCtrl values.
Whenever I click on some customized wxTextCtrl then click somewhere else, I can't click back to once clicked customized wxTextCtrl.
The focus stays where it was before re-clicking.
The cursor position also mimics the box which should be focused.
What could cause this problem?

Code: Select all

#ifndef TextCtrl_Short_h
#define TextCtrl_Short_h

class TextCtrl_Short : public wxTextCtrl
{
	public:

	TextCtrl_Short(wxWindow*, string, short*);

	/* Events */

	void OnKillFocus(wxFocusEvent& Event);

	/* Member Variables */

	short * Container;
	void * ParentContainer;
	bool NoLoadList;
};

#endif

TextCtrl_Short::TextCtrl_Short(wxWindow * parent, string InitValue, short * Pointer)
: wxTextCtrl(parent, wxID_ANY, InitValue, wxDefaultPosition, wxSize(0, 20), 0, wxDefaultValidator)
{
	Container = Pointer;
	this->SetBackgroundColour(wxColour(210, 230, 255));
	Connect(this->GetId(), wxEVT_KILL_FOCUS, wxFocusEventHandler(TextCtrl_Short::OnKillFocus));
}
Last edited by DavidHart on Mon Dec 19, 2011 9:00 pm, edited 1 time in total.
Reason: Moderator: Adding code tags
DavidHart
Site Admin
Site Admin
Posts: 4254
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: wxTextCtrl Incorrect Focus

Post by DavidHart »

Hi,

(Please use code-tags; they make source-code much easier to read. I've done it for you this time.)

One possibility, since you catch wxEVT_KILL_FOCUS: make sure you call event.Skip() in the handler, otherwise strange things may happen.

Regards,

David
Tapsa
Earned some good credits
Earned some good credits
Posts: 147
Joined: Tue Dec 06, 2011 5:52 pm
Location: Helsinki

Re: wxTextCtrl Incorrect Focus

Post by Tapsa »

Do you mean in TextCtrl_Short::OnKillFocus in my case?
HUGE thanks! It works now!
Post Reply