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 » TabCtrl » TabCtrl.WhenSet is called when app closes
TabCtrl.WhenSet is called when app closes [message #60483] Tue, 05 March 2024 07:40 Go to next message
pvictor is currently offline  pvictor
Messages: 67
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 #60496 is a reply to message #60483] Sun, 10 March 2024 22:01 Go to previous messageGo to next message
koldo is currently online  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Hi Victor

I am surprised. I have reduced your sample to the minimum, but I cannot answer why TabCtrl::WhenSet() is called when the window is closed.
I would be grateful if someone could lend a hand.

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

struct Test: TopWindow {
	TabCtrl tabs;
	StaticRect tab0, tab1;
	Test() {
		Add(tabs.SizePos());
		tabs.Add(tab0.SizePos(), "Tab 0");
		tabs.Add(tab1.SizePos(), "Tab 1");
		tabs.WhenSet = [&] {PromptOK(Format("Tab %d set", tabs.Get()));};
	}
};

GUI_APP_MAIN {
	Test().Run();
}


Best regards
Iñaki
Re: TabCtrl.WhenSet is called when app closes [message #60497 is a reply to message #60496] Mon, 11 March 2024 08:45 Go to previous message
koldo is currently online  koldo
Messages: 3357
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
Previous Topic: tabctrl contents not visible
Goto Forum:
  


Current Time: Sun Apr 28 18:38:12 CEST 2024

Total time taken to generate the page: 0.04482 seconds