TGroupButton.cxx

Go to the documentation of this file.
00001 // @(#)root/gpad:$Id: TGroupButton.cxx 35535 2010-09-21 12:58:33Z brun $
00002 // Author: Rene Brun   01/07/96
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "Riostream.h"
00013 #include "TROOT.h"
00014 #include "TBox.h"
00015 #include "TGroupButton.h"
00016 #include "TVirtualX.h"
00017 #include "TDialogCanvas.h"
00018 #include "TCanvas.h"
00019 #include "TText.h"
00020 #include "TInterpreter.h"
00021 #include "TTimer.h"
00022 #include <string.h>
00023 
00024 ClassImp(TGroupButton)
00025 
00026 
00027 //______________________________________________________________________________
00028 //
00029 //  A TGroupButton object is a specialized TButton used in a group of Buttons.
00030 //  When a button from a group of TGroupButtons is selected, all other buttons
00031 //  from the group with the same name are disabled.
00032 //
00033 //  For examples of use of TGroupButton objects, see:
00034 //    TAttFillCanvas, TAttLineCanvas, TAttTextCanvas and TAttMarkerCanvas.
00035 
00036 
00037 //______________________________________________________________________________
00038 TGroupButton::TGroupButton(): TButton()
00039 {
00040    // GroupButton default constructor.
00041 
00042    SetFraming();
00043 }
00044 
00045 
00046 //______________________________________________________________________________
00047 TGroupButton::TGroupButton(const char *groupname, const char *title, const char *method, Double_t x1, Double_t y1,Double_t x2, Double_t  y2)
00048            :TButton(title,method,x1,y1,x2,y2)
00049 {
00050    // GroupButton normal constructor.
00051 
00052    SetName((char*)groupname);
00053    SetFraming();
00054 }
00055 
00056 
00057 //______________________________________________________________________________
00058 TGroupButton::~TGroupButton()
00059 {
00060    // GroupButton default destructor.
00061 }
00062 
00063 
00064 //______________________________________________________________________________
00065 void TGroupButton::DisplayColorTable(const char *action, Double_t x0, Double_t y0, Double_t wc, Double_t hc)
00066 {
00067    // Display Color Table in an attribute canvas.
00068 
00069    TGroupButton *colorpad;
00070    Int_t i, j;
00071    Int_t color;
00072    Double_t xlow, ylow, hs, ws;
00073 
00074    // draw colortable buttons
00075    hs = hc/5;
00076    ws = wc/10;
00077    char command[32];
00078    for (i=0;i<10;i++) {
00079       xlow = x0 + ws*i;
00080       for (j=0;j<5;j++) {
00081          ylow = y0 + hs*j;
00082          color = 10*j + i + 1;
00083          snprintf(command,32,"%s(%d)",action,10*j+i+1);
00084          colorpad = new TGroupButton("Color","",command,xlow, ylow, xlow+0.9*ws, ylow+0.9*hs);
00085          colorpad->SetFillColor(color);
00086          colorpad->SetBorderSize(1);
00087          if (i == 0 && j == 0) colorpad->SetBorderMode(-1);
00088          colorpad->Draw();
00089       }
00090    }
00091 }
00092 
00093 
00094 //______________________________________________________________________________
00095 void TGroupButton::ExecuteAction()
00096 {
00097    // Execute action of this button.
00098    //
00099    //   If an object has been selected before executing the APPLY button
00100    //   in the control canvas, The member function and its parameters
00101    //   for this object is executed via the interpreter.
00102 
00103    TVirtualPad *pad;
00104    char line[128];
00105    strlcpy(line,GetMethod(),128); 
00106    char *method = line;
00107    if(!strlen(line)) return;
00108    char *params = strchr(method,'(');
00109    if (params) {
00110       *params = 0;
00111       params++;
00112       char *end = strrchr(params,')');
00113       if (end) *end = 0;
00114    }
00115    TDialogCanvas *canvas = (TDialogCanvas*)GetMother();
00116    TObject *obj = canvas->GetRefObject();
00117    if (!obj) return;
00118    if (strcmp(method,"PIXELS")) {
00119       obj->Execute(method,params);
00120    } else {
00121       TText *text = (TText*)GetListOfPrimitives()->First();
00122       Int_t npixels = Int_t((YtoPixel(0) - YtoPixel(1))*text->GetTextSize());
00123       Double_t dy;
00124       pad = gROOT->GetSelectedPad();
00125       if (!params) return;
00126       Int_t nmax = (Int_t)(params-method);
00127       if (obj->InheritsFrom("TPaveLabel")) {
00128          TBox *pl = (TBox*)obj;
00129          dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY(npixels);
00130          snprintf(params,nmax,"%f",dy/(pl->GetY2() - pl->GetY1()));
00131          obj->Execute("SetTextSize",params);
00132       } else {
00133          if (obj->InheritsFrom("TPave")) {
00134             dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY(npixels);
00135             snprintf(params,nmax,"%f",dy/(pad->GetY2() - pad->GetY1()));
00136             obj->Execute("SetTextSize",params);
00137          } else {
00138             snprintf(params,nmax,"%d",npixels);
00139             obj->Execute("SetTextSizePixels",params);
00140          }
00141       }
00142    }
00143 }
00144 
00145 
00146 //______________________________________________________________________________
00147 void TGroupButton::ExecuteEvent(Int_t event, Int_t px, Int_t py)
00148 {
00149    // Execute action corresponding to one event.
00150    //
00151    //  This member function is called when a Button object is clicked.
00152 
00153    if (fMother->IsEditable()) {
00154       TPad::ExecuteEvent(event,px,py);
00155       return;
00156    }
00157 
00158    TIter next(gPad->GetCanvas()->GetListOfPrimitives());
00159    TObject *obj;
00160    TGroupButton *button;
00161    TPad *pad;
00162    TDialogCanvas *canvas;
00163 
00164    switch (event) {
00165 
00166    case kButton1Down:
00167 
00168    case kMouseMotion:
00169 
00170       break;
00171 
00172    case kButton1Motion:
00173 
00174       break;
00175 
00176    case kButton1Up:
00177       //Clicked on APPLY button?
00178       if (!strcasecmp(GetName(),"APPLY")) {
00179          canvas = (TDialogCanvas*)GetMother();
00180          if (!strcasecmp(GetTitle(),"CLOSE")) {
00181             canvas->Close();
00182             return;
00183          }
00184          pad = canvas->GetRefPad();
00185          if (pad) pad->GetCanvas()->FeedbackMode(kFALSE);
00186          canvas->Apply(GetTitle());   //just in case the apply button executes some code
00187          if (pad) {
00188             pad->Modified(kTRUE);
00189             pad->Update();
00190          }
00191          break;
00192       }
00193       //Unset other buttons with same name
00194       while ((obj = next())) {
00195          if (obj == this) continue;
00196          if (obj->InheritsFrom(TGroupButton::Class())) {
00197             button = (TGroupButton*)obj;
00198             if (!strcmp(button->GetName(),GetName())) {
00199                if (button->GetBorderMode() < 0) {
00200                   button->SetBorderMode(1);
00201                   button->Modified();
00202                }
00203             }
00204          }
00205       }
00206       //Set button on
00207       SetBorderMode(-1);
00208       Modified();
00209       gPad->GetCanvas()->Modified();
00210       gPad->Update();
00211       break;
00212    }
00213 }
00214 
00215 
00216 //______________________________________________________________________________
00217 void TGroupButton::SavePrimitive(ostream &out, Option_t * /*= ""*/)
00218 {
00219    // Save primitive as a C++ statement(s) on output stream out
00220 
00221    TPad *padsav = (TPad*)gPad;
00222    char quote = '"';
00223    if (gROOT->ClassSaved(TGroupButton::Class())) {
00224       out<<"   ";
00225    } else {
00226       out<<"   TGroupButton *";
00227    }
00228    out<<"button = new TGroupButton("<<quote<<GetName()<<quote<<", "<<quote<<GetTitle()
00229       <<quote<<","<<quote<<GetMethod()<<quote
00230       <<","<<fXlowNDC
00231       <<","<<fYlowNDC
00232       <<","<<fXlowNDC+fWNDC
00233       <<","<<fYlowNDC+fHNDC
00234       <<");"<<endl;
00235 
00236    SaveFillAttributes(out,"button",0,1001);
00237    SaveLineAttributes(out,"button",1,1,1);
00238    SaveTextAttributes(out,"button",22,0,1,62,.75);
00239 
00240    if (GetBorderSize() != 2) {
00241       out<<"   button->SetBorderSize("<<GetBorderSize()<<");"<<endl;
00242    }
00243    if (GetBorderMode() != 1) {
00244       out<<"   button->SetBorderMode("<<GetBorderMode()<<");"<<endl;
00245    }
00246 
00247    out<<"   button->Draw();"<<endl;
00248    out<<"   button->cd();"<<endl;
00249 
00250    TIter next(GetListOfPrimitives());
00251    TObject *obj = next();  //do not save first primitive
00252 
00253    while ((obj = next()))
00254          obj->SavePrimitive(out, (Option_t *)next.GetOption());
00255 
00256    out<<"   "<<padsav->GetName()<<"->cd();"<<endl;
00257    padsav->cd();
00258 }

Generated on Tue Jul 5 14:14:07 2011 for ROOT_528-00b_version by  doxygen 1.5.1