Hello,
I’m having two issues with TGCanvas that I have been unable to solve:
The first is that the TGCanvas does not seem to resize in the x direction when using kLHintsExpandX. From a class that is a TGTransientFrame window, I’m trying to embed a canvas (so that I’ll have access to scroll bars) and then embed one or more graphs. I create the necessary frames and canvas as so:
void RTDWindow::AddEmbeddedCanvas()
{
fCanvasWindow = new TGCanvas(this, 900, 400);
fMainFrame = new TGCompositeFrame(fCanvasWindow->GetViewPort(),
900, 400,
kLHintsExpandX | kLHintsExpandY | kVerticalFrame);
fCanvasWindow->SetContainer(fMainFrame);
// The remaining space I want to be a frame.
// Inside this frame I will embed a canvas for drawing the profile.
fGraphicsFrame = new TGCompositeFrame(fMainFrame, 900, 400,
kLHintsExpandX | kLHintsExpandY | kVerticalFrame);
fEmbeddedCanvas = new TRootEmbeddedCanvas("ec1", fGraphicsFrame,
900, 400);
fL3 = new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY,
2, 2, 0, 0);
fL4 = new TGLayoutHints(kLHintsTop | kLHintsLeft |
kLHintsExpandX | kLHintsExpandY,
5, 5, 5, 5);
fGraphicsFrame->AddFrame(fEmbeddedCanvas, fL4);
fMainFrame->AddFrame(fGraphicsFrame, fL3);
TCanvas *c1 = fEmbeddedCanvas->GetCanvas();
c1->SetBit(kNoContextMenu);
c1->SetBorderMode(0);
c1->SetGrid();
c1->cd();
this->AddFrame(fCanvasWindow, new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY,
0, 0, 0, 0));
fMainFrame->Resize();
fCanvasWindow->Resize();
fGraphicsFrame->Resize();
fEmbeddedCanvas->Resize();
}
The graph is able to be drawn correctly and both the vertical and horizontal scrollbars appear as desired. As you can see, I specify both kLHintsExpandX and kLHintsExpandY. When resizing the window and making it larger, the Y direction works fine but the X direction does not (attached no_x_resize.png). There is a white space where the main frame and canvas do not expand.
The second issue comes when trying to remove a frame from the TGCanvas (maybe will be resolved by fix to the first problem?):
Again, I’d like to put several graphs in the TGCanvas and have the scrollbars appear as necessary. This works almost perfectly with the exception of the problem described above (attached multi_panes.png). However, when the user selects from the menu to remove a graph, I have the problem where the TGCanvas does not seem to be re-drawn correctly after the frame and canvas containing the graph are removed. I add a frame and a canvas for an additional graph as follows:
TRootEmbeddedCanvas* RTDWindow::AddNewPane()
{
TCanvas *c1;
TGCompositeFrame *newGraphicsFrame;
TRootEmbeddedCanvas *newEmbeddedCanvas;
newGraphicsFrame = new TGCompositeFrame(fMainFrame, 900, 400,
kLHintsExpandX | kLHintsExpandY | kVerticalFrame);
newEmbeddedCanvas = new TRootEmbeddedCanvas("0", newGraphicsFrame,
900, 400);
newGraphicsFrame->AddFrame(newEmbeddedCanvas, fL4);
fMainFrame->AddFrame(newGraphicsFrame, fL3);
c1 = newEmbeddedCanvas->GetCanvas();
c1->SetBit(kNoContextMenu);
c1->SetBorderMode(0);
c1->SetGrid();
c1->cd();
newEmbeddedCanvas->Resize();
newGraphicsFrame->Resize();
fCanvasWindow->Resize();
fMainFrame->Resize();
newEmbeddedCanvas->GetCanvas()->Modified();
newEmbeddedCanvas->GetCanvas()->Update();
this->MapSubwindows();
this->Resize();
this->MapWindow();
return newEmbeddedCanvas;
}
When the user wants to remove a graph, I do:
// curPaneData->GetFrame() is the newGraphicsFrame from above
// curPaneData->GetCanvas() is the newEmbeddedCanvas from above
curPaneData->GetFrame()->RemoveFrame(curPaneData->GetCanvas());
fMainFrame->RemoveFrame(curPaneData->GetFrame());
// followed by all sorts of attempts to try to get the window to display correctly
fCanvasWindow->Layout();
fCanvasWindow->MapSubwindows();
fCanvasWindow->Resize();
fCanvasWindow->MapWindow();
fMainFrame->Layout();
fMainFrame->MapSubwindows();
fMainFrame->Resize();
fMainFrame->MapWindow();
this->Layout();
this->MapSubwindows();
this->Resize();
this->MapWindow();
At first glance, this almost works. The vertical scroll bar size decreases, indicating that the frame has been removed, and depending on the position of the vertical scrollbar the window size decreases. However, if I resize the window, or if the vertical scrollbar is somewhere in the middle when removing the frame, the window is not redrawn correctly - the removed frame is still there and covers the top remaining graph (attached bad_remove_frame.png).
Any help to get my window to function better would be greatly appreciated as I have run out of ideas to try.
Thanks very much!
Tim