Home » U++ Library support » TabCtrl » TabCtrl.WhenSet is called when app closes
TabCtrl.WhenSet is called when app closes [message #60483] |
Tue, 05 March 2024 07:40  |
pvictor
Messages: 75 Registered: December 2015
|
Member |
|
|
Hi!
Here's a testcase:
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
struct Tab0: ParentCtrl {
Button bt;
Tab0() { Add(bt.SetLabel("Bt 0").LeftPos(10,100).TopPosZ(10,20)); }
};
struct Tab1: ParentCtrl {
Button bt;
Tab1() { Add(bt.SetLabel("Bt 1").LeftPos(10,100).TopPosZ(10,20)); }
};
struct Tab2: ParentCtrl {
Button bt;
Tab2() { Add(bt.SetLabel("Bt 2").LeftPos(10,100).TopPosZ(10,20)); }
};
struct Test: TopWindow {
TabCtrl Tabs;
Tab0 tab0;
Tab1 tab1;
Tab2 tab2;
Test() {
SetRect(0, 0, 640, 480);
Add(Tabs.SizePos());
Tabs.Add(tab0.SizePos(), "Tab 0");
Tabs.Add(tab1.SizePos(), "Tab 1");
Tabs.Add(tab2.SizePos(), "Tab 2");
Tabs.WhenSet = [this] {
switch (Tabs.Get()) {
case 0: ErrorOK("Tab 0"); break;
case 1: ErrorOK("Tab 1"); break;
case 2: ErrorOK("Tab 2");
}
};
// WhenClose = [this] { Tabs.WhenSet=Null; Close(); }; // this helps to prevent unwanted events
}
};
GUI_APP_MAIN {
Test().Run();
}
When closing the window, I at first get three WhenSet events (one for each tab).
This happens both on Windows and Linux.
Best regards,
Victor
|
|
|
|
Re: TabCtrl.WhenSet is called when app closes [message #60497 is a reply to message #60496] |
Mon, 11 March 2024 08:45  |
 |
koldo
Messages: 3435 Registered: August 2008
|
Senior Veteran |
|
|
Hi Victor
As I didn't understand what was going on, I looked at what I had done in my programmes. The trick is to add the RejectBreak() as indicated in your Close():
virtual void Close() {
RejectBreak(IDOK);
TopWindow::Close();
}
I always do this, to prevent a blank field (an EditInt for example) from blocking the program from closing.
To Mirek: The problem with the program is that in TopWindow::Close(), Ctrl::InLoop() returns true, and then, TopWindow::DefaultBreak() calls AcceptBreak(IDOK). THis calls TopWindow::Accept() of all children. And as TabCtrl::Accept() calls the Set() of all children, the WhenSet is activated...
Best regards
Iñaki
|
|
|
Goto Forum:
Current Time: Tue May 13 23:03:46 CEST 2025
Total time taken to generate the page: 0.04910 seconds
|