#include "TRootEmbeddedCanvas.h"
#include "TCanvas.h"
#include "TROOT.h"
#include "Riostream.h"
class TRootEmbeddedContainer : public TGCompositeFrame {
private:
TRootEmbeddedCanvas *fCanvas;
public:
TRootEmbeddedContainer(TRootEmbeddedCanvas *c, Window_t id, const TGWindow *parent);
Bool_t HandleButton(Event_t *ev)
{ return fCanvas->HandleContainerButton(ev); }
Bool_t HandleDoubleClick(Event_t *ev)
{ return fCanvas->HandleContainerDoubleClick(ev); }
Bool_t HandleConfigureNotify(Event_t *ev)
{ TGFrame::HandleConfigureNotify(ev);
return fCanvas->HandleContainerConfigure(ev); }
Bool_t HandleKey(Event_t *ev)
{ return fCanvas->HandleContainerKey(ev); }
Bool_t HandleMotion(Event_t *ev)
{ return fCanvas->HandleContainerMotion(ev); }
Bool_t HandleExpose(Event_t *ev)
{ return fCanvas->HandleContainerExpose(ev); }
Bool_t HandleCrossing(Event_t *ev)
{ return fCanvas->HandleContainerCrossing(ev); }
void SetEditable(Bool_t) { }
};
TRootEmbeddedContainer::TRootEmbeddedContainer(TRootEmbeddedCanvas *c, Window_t id,
const TGWindow *p) : TGCompositeFrame(gClient, id, p)
{
fCanvas = c;
gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
kButtonPressMask | kButtonReleaseMask |
kPointerMotionMask, kNone, kNone);
AddInput(kKeyPressMask | kKeyReleaseMask | kPointerMotionMask |
kExposureMask | kStructureNotifyMask | kLeaveWindowMask);
fEditDisabled = kEditDisableGrab;
}
ClassImp(TRootEmbeddedCanvas)
TRootEmbeddedCanvas::TRootEmbeddedCanvas(const char *name, const TGWindow *p,
UInt_t w, UInt_t h, UInt_t options, ULong_t back)
: TGCanvas(p, w, h, options, back)
{
fCanvas = 0;
fButton = 0;
fAutoFit = kTRUE;
fEditDisabled = kEditDisableLayout;
fCWinId = gVirtualX->InitWindow((ULong_t)GetViewPort()->GetId());
Window_t win = gVirtualX->GetWindowID(fCWinId);
fCanvasContainer = new TRootEmbeddedContainer(this, win, GetViewPort());
SetContainer(fCanvasContainer);
fCanvas = new TCanvas(name ? name : Form("%s_canvas", GetName()), w, h, fCWinId);
if (!p) {
fCanvas->SetBorderMode(0);
MapSubwindows();
Resize(100, 100);
}
}
TRootEmbeddedCanvas::TRootEmbeddedCanvas(const TRootEmbeddedCanvas& ec) :
TGCanvas(ec),
fCWinId(ec.fCWinId),
fCanvasContainer(ec.fCanvasContainer),
fCanvas(ec.fCanvas),
fAutoFit(ec.fAutoFit),
fButton(ec.fButton)
{
}
TRootEmbeddedCanvas& TRootEmbeddedCanvas::operator=(const TRootEmbeddedCanvas& ec)
{
if(this!=&ec) {
TGCanvas::operator=(ec),
fCWinId=ec.fCWinId;
fCanvasContainer=ec.fCanvasContainer;
fCanvas=ec.fCanvas;
fAutoFit=ec.fAutoFit;
fButton=ec.fButton;
}
return *this;
}
TRootEmbeddedCanvas::~TRootEmbeddedCanvas()
{
if (!MustCleanup()) {
delete fCanvas;
delete fCanvasContainer;
}
}
void TRootEmbeddedCanvas::AdoptCanvas(TCanvas *c)
{
if(c == 0) return;
c->EmbedInto(fCWinId, fWidth, fHeight);
fCanvas = c;
}
Bool_t TRootEmbeddedCanvas::HandleContainerButton(Event_t *event)
{
if (!fCanvas) return kTRUE;
Int_t button = event->fCode;
Int_t x = event->fX;
Int_t y = event->fY;
if (event->fType == kButtonPress) {
fButton = button;
if (button == kButton1)
fCanvas->HandleInput(kButton1Down, x, y);
if (button == kButton2)
fCanvas->HandleInput(kButton2Down, x, y);
if (button == kButton3) {
fCanvas->HandleInput(kButton3Down, x, y);
fButton = 0;
}
} else if (event->fType == kButtonRelease) {
if (button == kButton1)
fCanvas->HandleInput(kButton1Up, x, y);
if (button == kButton2)
fCanvas->HandleInput(kButton2Up, x, y);
if (button == kButton3)
fCanvas->HandleInput(kButton3Up, x, y);
fButton = 0;
}
return kTRUE;
}
Bool_t TRootEmbeddedCanvas::HandleContainerDoubleClick(Event_t *event)
{
if (!fCanvas) return kTRUE;
Int_t button = event->fCode;
Int_t x = event->fX;
Int_t y = event->fY;
if (button == kButton1)
fCanvas->HandleInput(kButton1Double, x, y);
if (button == kButton2)
fCanvas->HandleInput(kButton2Double, x, y);
if (button == kButton3)
fCanvas->HandleInput(kButton3Double, x, y);
return kTRUE;
}
Bool_t TRootEmbeddedCanvas::HandleContainerConfigure(Event_t *)
{
if (fAutoFit && fCanvas) {
fCanvas->Resize();
fCanvas->Update();
}
return kTRUE;
}
Bool_t TRootEmbeddedCanvas::HandleContainerKey(Event_t *event)
{
if (!fCanvas) return kTRUE;
if (event->fType == kGKeyPress) {
fButton = event->fCode;
UInt_t keysym;
char str[2];
gVirtualX->LookupString(event, str, sizeof(str), keysym);
if (str[0] == 3)
gROOT->SetInterrupt();
fCanvas->HandleInput(kKeyPress, str[0], keysym);
} else if (event->fType == kKeyRelease)
fButton = 0;
return kTRUE;
}
Bool_t TRootEmbeddedCanvas::HandleContainerMotion(Event_t *event)
{
if (!fCanvas) return kTRUE;
Int_t x = event->fX;
Int_t y = event->fY;
if (fButton == 0)
fCanvas->HandleInput(kMouseMotion, x, y);
if (fButton == kButton1)
fCanvas->HandleInput(kButton1Motion, x, y);
return kTRUE;
}
Bool_t TRootEmbeddedCanvas::HandleContainerExpose(Event_t *event)
{
if (!fCanvas) return kTRUE;
if (event->fCount == 0)
fCanvas->Flush();
return kTRUE;
}
Bool_t TRootEmbeddedCanvas::HandleContainerCrossing(Event_t *event)
{
if (!fCanvas) return kTRUE;
Int_t x = event->fX;
Int_t y = event->fY;
if (event->fType == kLeaveNotify && event->fCode == kNotifyNormal)
fCanvas->HandleInput(kMouseLeave, x, y);
return kTRUE;
}
void TRootEmbeddedCanvas::SavePrimitive(ostream &out, Option_t *option )
{
if (!GetCanvas()) return;
if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
char quote ='"';
out << endl << " << endl;
out << " TRootEmbeddedCanvas *";
out << GetName() << " = new TRootEmbeddedCanvas(0" << "," << fParent->GetName()
<< "," << GetWidth() << "," << GetHeight();
if (fBackground == GetDefaultFrameBackground()) {
if (GetOptions() == (kSunkenFrame | kDoubleBorder)) {
out <<");" << endl;
} else {
out << "," << GetOptionString() <<");" << endl;
}
} else {
out << "," << GetOptionString() << ",ucolor);" << endl;
}
out << " Int_t w" << GetName() << " = " << GetName()
<< "->GetCanvasWindowId();" << endl;
static int n = 123;
TString cname = Form("c%d", n);
out << " TCanvas *";
out << cname << " = new TCanvas(";
out << quote << cname.Data() << quote << ", 10, 10, w"
<< GetName() << ");" << endl;
out << " " << GetName() << "->AdoptCanvas(" << cname
<< ");" << endl;
n++;
}
ROOT page - Class index - Class Hierarchy - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.