How to Make subclassed TGTransientFrame object Top Most/Foreground Window

Hi,

Sorry, but I haven’t found a clear way to make my subclassed TGTransientFrame class to be the topmost/foreground window of my may TRoot application.

I a TRoot application which has a button. when the button is pressed it creates my subclassed TGTransientFrame object. It does pop up, but if I navigate away, the window goes to the background. How can I always keep it in the foreground?

Could you also please explain what is the differences between the following input modes?

I know what a modal and modeless dialog is, I just can see visibly what changing the input modes do?

// input mode from TGFame.h
kMWMInputModeless = 0,
kMWMInputPrimaryApplicationModal = 1,
kMWMInputSystemModal = 2,
kMWMInputFullApplicationModal = 3,

Thank you,
Angel

I don’t know if this is a good solution, but, I ended up implementing the HandleFocusChange() event handler in my subclassed class.

Within the class I just did:
MapWindow()
return false;

Please let me know if I’m correct.

Hi Angel,

[quote=“aortiz@stgen.com”]I don’t know if this is a good solution, but, I ended up implementing the HandleFocusChange() event handler in my subclassed class.

Within the class I just did:
MapWindow()
return false;

Please let me know if I’m correct.[/quote]
This is not the right solution (even if it may work). A TGTransientFrame should stay on top by default like for example in $(ROOTSYS)/tutorials/gui/guitest.C (and as TGMsgBox inherits from it). This might be due to a wrong TGTransientFrame creation (e.g. wrong parent). Could you post your code, or a running macro showing the issue?

Cheers, Bertrand.

Hi Bertrand,

Here is my creation call for my TGTransientFrame derived class GTMsgDlg.
class GTMsgDlg : public TGTransientFrame

GTMsgDlg *pmsgDlg = new GTMsgDlg(gClient->GetDefaultRoot(), // TGWindow
						gClient->GetRoot(),			// TGWindow (main)
						strTitle.c_str(),				// Dialog Title
						strText.c_str(),				// Dialog message (can be updated on the fly (fLabel)
						kMBIconAsterisk,			// Type of warning/icon to display
						kFlags);					// Types of buttons to create.

Hi Angel,

The second argument should a main frame (and not gClient->GetRoot())

Cheers, Bertrand.

Hi Bertrand,

Does not seem to work for me, so I must be missing something. Here is a bit of information on our application.

We have:
TApplication *pTAP = NULL;
MyMainFrame *MainFrame = NULL;

class MyMainFrame : public TGMainFrame
{

// Set our MainFrame = NULL to this
// This is what I am now using for my 2nd argument to my
// class GTMsgDlg : public TGTransientFrame
MainFrame = this;

};

Now I create my TGTransientFrame Object by calling the following
GTMsgDlg::GTMsgDlg(const TGWindow *p, const TGWindow *main,
const char *title, const char *msg, EMsgBoxIcon icon,
Int_t buttons, Int_t *ret_code, UInt_t options,
Int_t text_align) :
TGTransientFrame(p, MainFrame, 10, 10, options)

At this point I can click on my MainFrame application and my GTMsgDlg goes to the background.

BTW, could you explain the diff between
GetRoot() and GetDefaultRoot()?

Regards,
Angel

Bertrand,

I think I figured it out. In our class MyMainFrame : public TGMainFrame, there was another variable called:

TGMainFrame *pMainFrame;

The other variable below was not the object I needed to use. I thought it was my TGMainFrame() pointer, but it was only the object containing my pointer to the TGMainFrame.

MyMainFrame *MainFrame = this

The actual TGMainFrame window is “pMainFrame”.
pMainFrame = new TGMainFrame(gClient->GetRoot(), 2000, 1100, kHorizontalFrame | kRaisedFrame | kDoubleBorder);

I then changed my subclassed class GTMsgDlg : public TGTransientFrame as such and my Dialog remains on top.

GTMsgDlg *pmsgDlg = new GTMsgDlg(gClient->GetRoot(), // TGWindow
MainFrame->pMainFrame, // TGWindow (main)
strTitle.c_str(), // Dialog Title
strText.c_str(), // Dialog message (can be updated on the fly (fLabel)
kMBIconAsterisk, // Type of warning/icon to display
kFlags); // Types of buttons to create.

Thank you!!!

But, you can still help me understand when to use GetDefaultRoot() and GetRoot().

Regards,
Angel

[quote=“aortiz@stgen.com”]But, you can still help me understand when to use GetDefaultRoot() and GetRoot().
[/quote]
GetRoot() normally returns the desktop Window, but might also return another window used as parent (needed when re-parenting windows, for example in the Gui Buidler) and GetDefaultRoot() always returns the desktop Window