Hi,
I have a class ICoolMainFrame derived from TGMainFrame, which has several TRootEmbeddedCanvas member variables like so:
class ICoolMainFrame : public TGMainFrame {
private:
TRootEmbeddedCanvas *fCanvas;
TRootEmbeddedCanvas *fCanvas1;
...
I set up a TClassMenuItem like so:
TClass *cl=fCanvas->GetCanvas()->IsA();
TList *l;
TClassMenuItem *n;
l=cl->GetMenuList();
n= new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
"Remove Canvas","RemoveCanvas",this,"TObject*",1);
l->AddFirst(n);
I want my function RemoveCanvas, to be able to hide the canvas that the user clicked on when selecting RemoveCanvas. RemoveCanvas
void ICoolMainFrame::RemoveCanvas(TObject *obj)
{
printf("\nRemoveCanvas\n");
printf("TCanvas : %lx\n",(Long_t)obj);
printf("title of the canvas : %s\n",obj->IsA()->GetTitle());
HideFrame((TGFrame*)obj->IsA());
}
However this doesn’t seem to work. How do I actually pass the object to a function associated with a TClassMenuItem so that I can perform actions on that object itself?
Any help would be greatly appreciated.
Thanks.
-Jon
In the example I’ve sent you a week ago, I had a special check:
//_____________________________________________________________
void TestFrame::Action(const TObject *clickedOn) const
{
if (clickedOn == embCnv->GetCanvas())
std::cout<<"clicked in embedded canvas ... the object is "<<clickedOn->IsA()->GetName()<<std::endl;
else
std::cout<<"Method was called, but ...\n";
}
So it looks like you’ve completely ignored my code. If you know that clickedOn is a TCanvas from embCnv, you know now where a click happened … in embCnv (or it will be fCanvas1/fCanvas2 in your case), so you hide/remove the corresponding embedded canvas now.
void MyNotSoCoolMainFrame::HideCanvas(TObject *obj)
{
if (obj == fCanvas->GetCanvas())
HideFrame(fCanvas);
else if (obj == fCanvas1->GetCanvas())
HideFrame(fCanvas1);
}
Before doing wild type casts, be sure you understand what you are casting.
TCanvas is not a TGFrame, so such a cast is illegal and gives you nothing.
Even worse obj->IsA() returns TClass * which has nothing to do with TGFrame.
You can not cast TClass * to TGFrame *.
And even more obj->IsA()->GetTitle() is not a title for TCanvas.
Have a look at classes/methods declarations to check how to use them.
For example, TCanvas itself is not a window, it has a “canvas imp” - a pointer to a window (either TRootCanvas or TRootEmbeddedCanvas). TRootCanvas/TRootEmbeddedCanvas are already GUI (window) classes.
Best regards,
Timur.