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
|
|
|
Re: Action on exit from an EditString field [message #45112 is a reply to message #45108] |
Thu, 03 September 2015 12:21  |
Giorgio
Messages: 218 Registered: August 2015
|
Experienced Member |
|
|
Hi Ghost,
thank you for your reply. Your example was indeed detailed and I got it working. I also got to extend a window on my own application. The only problem is that I can reproduce the example when I build the window layout by myself, but I do not know how to add it to a window designed with the designer. I tried to add it using the "user class" function, but it throws an error when compiling. I tried also to use the instruction Add but I do not see the control in the window.
Regards,
Giorgio
--- Edit ---
Well, I did it, it was not so difficult
[Updated on: Thu, 03 September 2015 12:52] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Tue Apr 29 15:03:20 CEST 2025
Total time taken to generate the page: 0.03645 seconds
|