Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MINFEmbeddedCanvas.cxx

Go to the documentation of this file.
00001 //*CMZ :  2.21/08 11/03/99  16.36.20  by  Fons Rademakers
00002 //*CMZ :  2.20/00 03/11/98  19.52.59  by  Fons Rademakers
00003 //*CMZ :  2.00/10 16/07/98  18.50.45  by  Fons Rademakers
00004 //*-- Author :    Fons Rademakers   15/07/98
00005 
00006 //*KEEP,CopyRight,T=C.
00007 /*************************************************************************
00008  * Copyright(c) 1995-1999, The ROOT System, All rights reserved.         *
00009  * Authors: Rene Brun, Fons Rademakers.                                  *
00010  * For list of contributors see $ROOTSYS/AA_CREDITS.                     *
00011  *                                                                       *
00012  * Permission to use, copy, modify and distribute this software and its  *
00013  * documentation for non-commercial purposes is hereby granted without   *
00014  * fee, provided that the above copyright notice appears in all copies   *
00015  * and that both the copyright notice and this permission notice appear  *
00016  * in the supporting documentation. The authors make no claims about the *
00017  * suitability of this software for any purpose. It is provided "as is"  *
00018  * without express or implied warranty.                                  *
00019  *************************************************************************/
00020 //*KEND.
00021 
00023 //                                                                      //
00024 // MINFEmbeddedCanvas                                                  //
00025 //                                                                      //
00026 // This class creates a TGCanvas in which a TCanvas is created. Use     //
00027 // GetCanvas() to get a pointer to the TCanvas.                         //
00028 //                                                                      //
00030 
00031 // MINF includes which need to be gotten rid of.
00032 #include "MINF_Classes/MINFDisplayFrame.h"
00033 #include "MINF_Classes/MINFEmbeddedCanvas.h"
00034 
00035 #include "TCanvas.h"
00036 #include "TROOT.h"
00037 
00039 //                                                                      //
00040 // MINFEmbeddedContainer                                               //
00041 //                                                                      //
00042 // Utility class used by MINFEmbeddedCanvas. The MINFEmbeddedContainer//
00043 // is the frame embedded in the TGCanvas widget. The ROOT graphics goes //
00044 // into this frame. This class is used to enable input events on this   //
00045 // graphics frame and forward the events to the MINFEmbeddedCanvas     //
00046 // handlers.                                                            //
00047 //                                                                      //
00049 
00050 class MINFEmbeddedContainer : public TGCompositeFrame {
00051 private:
00052    MINFEmbeddedCanvas  *fCanvas;    // pointer back to embedded canvas
00053 public:
00054    MINFEmbeddedContainer(MINFEmbeddedCanvas *c, Window_t id, const TGWindow *parent);
00055 
00056    Bool_t HandleButton(Event_t *ev) {
00057      return fCanvas->HandleContainerButton(ev);
00058    }
00059    Bool_t HandleDoubleClick(Event_t *ev) {
00060      return fCanvas->HandleContainerDoubleClick(ev);
00061    }
00062    Bool_t HandleConfigureNotify(Event_t *ev) {
00063      TGFrame::HandleConfigureNotify(ev);
00064      return fCanvas->HandleContainerConfigure(ev);
00065    }
00066    Bool_t HandleKey(Event_t *ev) {
00067      return fCanvas->HandleContainerKey(ev);
00068    }
00069    Bool_t HandleMotion(Event_t *ev) {
00070      return fCanvas->HandleContainerMotion(ev);
00071    }
00072    Bool_t HandleExpose(Event_t *ev) {
00073      return fCanvas->HandleContainerExpose(ev);
00074    }
00075    Bool_t HandleCrossing(Event_t *ev) {
00076      return fCanvas->HandleContainerCrossing(ev);
00077    }
00078 };
00079 
00080 //______________________________________________________________________________
00081 MINFEmbeddedContainer::MINFEmbeddedContainer(MINFEmbeddedCanvas *c, Window_t id,
00082    const TGWindow *p) : TGCompositeFrame(gClient, id, p)
00083 {
00084    // Create a canvas container.
00085 
00086    fCanvas = c;
00087 
00088    gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
00089                     kButtonPressMask | kButtonReleaseMask,
00090                     kNone, kNone);
00091 
00092    gVirtualX->SelectInput(fId, kKeyPressMask | kKeyReleaseMask | kExposureMask |
00093                      kPointerMotionMask | kStructureNotifyMask | kLeaveWindowMask);
00094 }
00095 
00096 ClassImp(MINFEmbeddedCanvas)
00097 
00098 //______________________________________________________________________________
00099 MINFEmbeddedCanvas::MINFEmbeddedCanvas(const char *name, const TGWindow *p,
00100             UInt_t w, UInt_t h, UInt_t options, ULong_t back)
00101    : TGCanvas(p, w, h, options, back)
00102 {
00103    // Create an TCanvas embedded in a TGFrame. A pointer to the TCanvas can
00104    // be obtained via the GetCanvas() member function.
00105 
00106    fButton  = 0;
00107    fAutoFit = kTRUE;
00108    fShowEventStatus = kFALSE;
00109 
00110    Int_t wid = gVirtualX->InitWindow((ULong_t)GetViewPort()->GetId());
00111    Window_t win = gVirtualX->GetWindowID(wid);
00112    fCanvasContainer = new MINFEmbeddedContainer(this, win, GetViewPort());
00113    SetContainer(fCanvasContainer);
00114 
00115    fCanvas = new TCanvas(name, 10, 10, wid);
00116 }
00117 
00118 //______________________________________________________________________________
00119 MINFEmbeddedCanvas::~MINFEmbeddedCanvas()
00120 {
00121    // Delete embedded ROOT canvas.
00122 
00123    delete fCanvas;
00124    delete fCanvasContainer;
00125 }
00126 
00127 //_______________________________________________________________________
00128 void MINFEmbeddedCanvas::DrawEventStatus(Int_t event, Int_t px, Int_t py, TObject *selected)
00129 {
00130 
00131 //*-*-*-*-*-*-*Report name and title of primitive below the cursor*-*-*-*-*-*
00132 //*-*          ===================================================
00133 //
00134 //    This function is called when the option "Event Status"
00135 //    in the canvas menu "Options" is selected.
00136 //
00137 
00138    const Int_t kTMAX=256;
00139    static char atext[kTMAX];
00140 
00141    if (!selected) return;
00142 
00143 //#ifndef WIN32
00144 #if 0
00145    static Int_t pxt, pyt;
00146    gPad->SetDoubleBuffer(0);           // Turn off double buffer mode
00147    gVirtualX->SetTextColor(1);
00148    gVirtualX->SetTextAlign(11);
00149 
00150    pxt = gPad->GetCanvas()->XtoAbsPixel(gPad->GetCanvas()->GetX1()) + 5;
00151    pyt = gPad->GetCanvas()->YtoAbsPixel(gPad->GetCanvas()->GetY1()) - 5;
00152 
00153    sprintf(atext,"%s / %s ", selected->GetName()
00154                            , selected->GetObjectInfo(px,py));
00155    for (Int_t i=strlen(atext);i<kTMAX-1;i++) atext[i] = ' ';
00156    atext[kTMAX-1] = 0;
00157    gVirtualX->DrawText(pxt, pyt, 0, 1, atext, TGXW::kOpaque);
00158 #else
00159 //gmi   if (!fCanvasImp) return; //this may happen when closing a TAttCanvas
00160    SetStatusText((Text_t *)(selected->GetTitle()),0);
00161    SetStatusText((Text_t *)(selected->GetName()),1);
00162    if (event == kKeyPress)
00163       sprintf(atext, "%c", (char) px);
00164    else
00165       sprintf(atext, "%d,%d", px, py);
00166    SetStatusText(atext,2);
00167    SetStatusText((Text_t *)(selected->GetObjectInfo(px,py)),3);
00168 #endif
00169 }
00170 
00171 //______________________________________________________________________________
00172 Bool_t MINFEmbeddedCanvas::HandleContainerButton(Event_t *event)
00173 {
00174    // Handle mouse button events in the canvas container.
00175 
00176    Int_t button = event->fCode;
00177    Int_t x = event->fX;
00178    Int_t y = event->fY;
00179 
00180    if (event->fType == kButtonPress) {
00181       fButton = button;
00182       if (button == kButton1)
00183          fCanvas->HandleInput(kButton1Down, x, y);
00184          if (fShowEventStatus) DrawEventStatus(event->fType, x, y, fCanvas->GetSelected());
00185       if (button == kButton2)
00186          fCanvas->HandleInput(kButton2Down, x, y);
00187          SetUnZoomPad(fCanvas->GetSelectedPad());
00188       if (button == kButton3) {
00189          fCanvas->HandleInput(kButton3Down, x, y);
00190          fButton = 0;  // button up is consumed by TContextMenu
00191       }
00192 
00193    } else if (event->fType == kButtonRelease) {
00194       if (button == kButton1)
00195          fCanvas->HandleInput(kButton1Up, x, y);
00196          if (fShowEventStatus) DrawEventStatus(event->fType, x, y, fCanvas->GetSelected());
00197       if (button == kButton2)
00198          fCanvas->HandleInput(kButton2Up, x, y);
00199       if (button == kButton3)
00200          fCanvas->HandleInput(kButton3Up, x, y);
00201 
00202       fButton = 0;
00203    }
00204 
00205    return kTRUE;
00206 }
00207 
00208 //______________________________________________________________________________
00209 Bool_t MINFEmbeddedCanvas::HandleContainerDoubleClick(Event_t *event)
00210 {
00211    // Handle mouse button double click events in the canvas container.
00212 
00213    Int_t button = event->fCode;
00214    Int_t x = event->fX;
00215    Int_t y = event->fY;
00216 
00217    if (button == kButton1)
00218       fCanvas->HandleInput(kButton1Double, x, y);
00219       if (fShowEventStatus) DrawEventStatus(event->fType, x, y, fCanvas->GetSelected());
00220    if (button == kButton2)
00221       fCanvas->HandleInput(kButton2Double, x, y);
00222    if (button == kButton3)
00223       fCanvas->HandleInput(kButton3Double, x, y);
00224 
00225    return kTRUE;
00226 }
00227 
00228 //______________________________________________________________________________
00229 Bool_t MINFEmbeddedCanvas::HandleContainerConfigure(Event_t *)
00230 {
00231    // Handle configure (i.e. resize) event.
00232 
00233    if (fAutoFit) {
00234       fCanvas->Resize();
00235       fCanvas->Update();
00236    }
00237    return kTRUE;
00238 }
00239 
00240 //______________________________________________________________________________
00241 Bool_t MINFEmbeddedCanvas::HandleContainerKey(Event_t *event)
00242 {
00243 
00244 // Handle mouse motion event in the canvas container.
00245    Int_t x = event->fX;
00246    Int_t y = event->fY;
00247 
00248 // Handle keyboard events in the canvas container.
00249    if (event->fType == kGKeyPress) {
00250       fButton = event->fCode;
00251       UInt_t keysym;
00252       char str[2];
00253       gVirtualX->LookupString(event, str, sizeof(str), keysym);
00254       if (str[0] == 3)   // ctrl-c sets the interrupt flag
00255          gROOT->SetInterrupt();
00256       fCanvas->HandleInput(kKeyPress, str[0], 0);
00257       if (fShowEventStatus) DrawEventStatus(event->fType, x, y, fCanvas->GetSelected());
00258    } else if (event->fType == kKeyRelease)
00259       fButton = 0;
00260 
00261    return kTRUE;
00262 }
00263 
00264 //______________________________________________________________________________
00265 Bool_t MINFEmbeddedCanvas::HandleContainerMotion(Event_t *event)
00266 {
00267    // Handle mouse motion event in the canvas container.
00268 
00269    Int_t x = event->fX;
00270    Int_t y = event->fY;
00271 
00272    if (fButton == 0)
00273       fCanvas->HandleInput(kMouseMotion, x, y);
00274       if (fShowEventStatus) DrawEventStatus(event->fType, x, y, fCanvas->GetSelected());
00275    if (fButton == kButton1)
00276       fCanvas->HandleInput(kButton1Motion, x, y);
00277       if (fShowEventStatus) DrawEventStatus(event->fType, x, y, fCanvas->GetSelected());
00278 
00279    return kTRUE;
00280 }
00281 
00282 //______________________________________________________________________________
00283 Bool_t MINFEmbeddedCanvas::HandleContainerExpose(Event_t *event)
00284 {
00285    // Handle expose events.
00286 
00287    if (event->fCount == 0)
00288       fCanvas->Flush();
00289 
00290    return kTRUE;
00291 }
00292 
00293 //______________________________________________________________________________
00294 Bool_t MINFEmbeddedCanvas::HandleContainerCrossing(Event_t *event)
00295 {
00296    // Handle enter/leave events. Only leave is activated at the moment.
00297 
00298    if (event->fType == kLeaveNotify)
00299       fCanvas->HandleInput(kMouseLeave, 0, 0);
00300 
00301    return kTRUE;
00302 }
00303 
00304 //_______________________________________________________________________
00305 void MINFEmbeddedCanvas::SetStatusText(Text_t *txt, Int_t partidx)
00306 {
00307 
00308 // Set text in status bar.
00309    ((MINFDisplayFrame *) fParent)->SetStatusText(txt, partidx);
00310 }
00311 
00312 //_______________________________________________________________________
00313 void MINFEmbeddedCanvas::SetUnZoomPad(TVirtualPad *pad)
00314 {
00315 
00316 // Set text in status bar.
00317    ((MINFDisplayFrame *) fParent)->SetUnZoomPad(pad);
00318 }

Generated on Thu Nov 1 11:51:37 2007 for loon by  doxygen 1.3.9.1