Home » Community » Newbie corner » Action on exit from an EditString field
Re: Action on exit from an EditString field [message #45108 is a reply to message #45107] |
Wed, 02 September 2015 15:46 |
Sender Ghost
Messages: 301 Registered: November 2008
|
Senior Member |
|
|
Hello, Giorgio.
Giorgio wrote on Wed, 02 September 2015 08:30I need to execute an action when I exit from an EditString field.
According to the mentioned topic, you could override LostFocus virtual function or just use proposed C++ template(s), e.g.:
// Create an object of EditString with WithLostFocus template
WithLostFocus<EditString> text;
// Assign some function to WhenLostFocus callback
text.WhenLostFocus = callback1(PromptOK, "LostFocus");
The more complete example follows:
Toggle example#include <CtrlLib/CtrlLib.h>
using namespace Upp;
template <class T>
struct WithFocusCallbacks : public T {
Callback WhenGotFocus, WhenLostFocus;
virtual void GotFocus() {
T::GotFocus();
WhenGotFocus();
}
virtual void LostFocus() {
T::LostFocus();
WhenLostFocus();
}
};
class App : public TopWindow {
public:
typedef App CLASSNAME;
App();
WithFocusCallbacks<EditString> text;
EditString otherText;
void ChangeNullText(const String& data);
};
App::App()
{
Title("Focus callbacks example");
CenterScreen().MinimizeBox().Sizeable();
const Size sz(320, 240);
SetRect(sz); SetMinSize(sz);
text.WhenGotFocus = THISBACK1(ChangeNullText, "GotFocus");
text.WhenLostFocus = THISBACK1(ChangeNullText, "LostFocus");
Add(text.TopPosZ(4, 19).HSizePosZ(4, 4));
Add(otherText.TopPosZ(27, 19).HSizePosZ(4, 4));
}
void App::ChangeNullText(const String& data)
{
static int count = 0;
text.NullText(Format("%s (%d)", data, ++count));
}
GUI_APP_MAIN
{
App app;
app.Run();
}
[Updated on: Wed, 02 September 2015 16:01] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Wed May 15 07:45:26 CEST 2024
Total time taken to generate the page: 0.02476 seconds
|