I experienced a strange behaviour with the TGMainFrame close button:
I create a class derived from TGMainFrame
I connect the “close button” from the window to a custom class function (I named it CloseButtonClicked() ) and I call the DontCallClose() function to prevent closing the window
Up to here, the behaviour seems ok: if the CloseButtonClicked() function does nothing, my window is not closed, and if I delete it (with DeleteWindow() function for example), this works.
Now I would like to request a closing confirmation in the CloseButtonClicked() function.
I defined a simple dialog, based on the TGTransientFrame class, with 2 buttons (namely “OK” and 'Cancel") for this confirmation, and depending on the selected answer, I want to close or not my
main window.
The situation is the following:
This simple dialog works fine and I retrieve a 0/1 value, depending on the button.
I test this value (in the CloseButtonClicked() function) - this is ok
Depending on the result, I call or not the closing function
But the main window is always closed, independently of the confirmation result.
I completely removed the closing function call, then doing nothing after the confirmation dialog, and the main window is closed anyway.
Could it be that creating (and closing) the dialog (TGTransientFrame) changes the behaviour for the main window ?
Since it is in a larger set of code, I will try to extract a minimal code.
I need a bit of time for that.
Before I can provide it, here are the main code elements.
In particular, the AGPage::CloseButtonClicked ( ) function, with detailed comments.
// header for the main application
class AGPage : public TGMainFrame
{
/*
.........
*/
virtual void CloseButtonClicked ( );
}
// code for the main application
AGPage::AGPage ()
: TGMainFrame ( gClient->GetRoot(), 100, 100 ),
{
Connect ("CloseWindow()", "AGPage", this, "CloseButtonClicked()");
DontCallClose();
/*
.........
*/
}
void AGPage::CloseButtonClicked ( )
{
cout << "AGPage::CloseButtonClicked ( )" << endl;
//================================================
// PART 1: confirmation
// delete confirmation dialog:
// the RGMessageRequester is a (personal) class that inherits
// from TGTransientFrame
// the dialog is closed by any button (OK or Cancel), and depending
// on the button, the req argument receives 0 or 1
int req = 0;
new RGMessageRequester ( gClient->GetRoot(), this, req,
"Warning", "\n Really delete the page ? \n\n",
kTextLeft, " 0K |Cancel" );
// I check the returned value is correct
cout << "AGPage::CloseButtonClicked ( ) req=" << req << endl;
//================================================
//================================================
// PART 2: close or not
if ( req != 0 ) // OK button selected
{
DeleteWindow();
gClient->WaitForUnmap ( this );
}
//================================================
// COMMENT:
// - removing (commenting) all function code: the window does not close (as expected)
// - removing only PART 2, the main window closes anyway !!!!
}