//*CMZ :  2.23/04 04/10/99  11.11.22  by  Rene Brun
//*CMZ :  2.23/02 17/09/99  09.26.15  by  Rene Brun
//*CMZ :  2.23/00 16/08/99  18.31.45  by  Rene Brun
//*CMZ :  2.20/05 15/12/98  09.17.21  by  Rene Brun
//*CMZ :  2.20/00 13/11/98  18.43.35  by  Fons Rademakers
//*-- Author :    Rene Brun   01/07/96

//*KEEP,CopyRight,T=C.
/*************************************************************************
 * Copyright(c) 1995-1999, The ROOT System, All rights reserved.         *
 * Authors: Rene Brun and Fons Rademakers.                               *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/AA_LICENSE.                      *
 * For the list of contributors see $ROOTSYS/AA_CREDITS.                 *
 *************************************************************************/
//*KEND.

#include <fstream.h>

//*KEEP,TROOT.
#include "TROOT.h"
//*KEEP,TBox.
#include "TBox.h"
//*KEEP,TGroupButton,T=C++.
#include "TGroupButton.h"
//*KEEP,TVirtualX.
#include "TVirtualX.h"
//*KEEP,TDialogCanvas,T=C++.
#include "TDialogCanvas.h"
//*KEEP,TCanvas.
#include "TCanvas.h"
//*KEEP,TText.
#include "TText.h"
//*KEEP,TInterpreter, T=C++.
#include "TInterpreter.h"
//*KEND.

#include <string.h>

ClassImp(TGroupButton)

//______________________________________________________________________________
//
//  A TGroupButton object is a specialized TButton used in a group of Buttons.
//  When a button from a group of TGroupButtons is selected, all other buttons
//  from the group with the same name are disabled.
//
//  For examples of use of TGroupButton objects, see:
//    TAttFillCanvas, TAttLineCanvas, TAttTextCanvas and TAttMarkerCanvas.

//______________________________________________________________________________
 TGroupButton::TGroupButton(): TButton()
{
//*-*-*-*-*-*-*-*-*-*-*GroupButton default constructor*-*-*-*-*-*-*-*-*-*-*-*
//*-*                  ===============================
   SetFraming();
}

//______________________________________________________________________________
 TGroupButton::TGroupButton(const Text_t *groupname, const Text_t *title, const Text_t *method, Coord_t x1, Coord_t y1,Coord_t x2, Coord_t  y2)
           :TButton(title,method,x1,y1,x2,y2)
{
//*-*-*-*-*-*-*-*-*-*-*GroupButton normal constructor*-*-*-*-*-*-*-*-*-*-*-*
//                     ==============================

   SetName((char*)groupname);
   SetFraming();
}

//______________________________________________________________________________
 TGroupButton::~TGroupButton()
{
//*-*-*-*-*-*-*-*-*-*-*GroupButton default destructor*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*                  ==============================
}

//______________________________________________________________________________
 void TGroupButton::DisplayColorTable(const Text_t *action, Float_t x0, Float_t y0, Float_t wc, Float_t hc)
{
//*-*-*-*-*-*-*-*-*-*-*Display Color Table in an attribute canvas*-*-*-*-*-*-*
//*-*                  ==========================================

   TGroupButton *colorpad;
   Int_t i, j;
   Int_t color;
   Float_t xlow, ylow, hs, ws;

//*-* draw colortable buttons
   hs = hc/5;
   ws = wc/10;
   char command[32];
   for (i=0;i<10;i++) {
      xlow = x0 + ws*i;
      for (j=0;j<5;j++) {
         ylow = y0 + hs*j;
         color = 10*j + i + 1;
         sprintf(command,"%s(%d)",action,10*j+i+1);
         colorpad = new TGroupButton("Color","",command,xlow, ylow, xlow+0.9*ws, ylow+0.9*hs);
         colorpad->SetFillColor(color);
         colorpad->SetBorderSize(1);
         if (i == 0 && j == 0) colorpad->SetBorderMode(-1);
         colorpad->Draw();
      }
   }
}

//______________________________________________________________________________
 void TGroupButton::ExecuteAction()
{
//*-*-*-*-*-*-*-*Execute action of this button*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*            =============================
//*-*
//*-*   If an object has been selected before executing the APPLY button
//*-*   in the control canvas, The member function and its parameters
//*-*   for this object is executed via the interpreter.

   TVirtualPad *pad;
   char line[128];
   strcpy(line,GetMethod());
   char *method = line;
   if(!strlen(line)) return;
   char *params = strchr(method,'(');
   if (params) {
      *params = 0;
      params++;
      char *end = strrchr(params,')');
      if (end) *end = 0;
   }
   TDialogCanvas *canvas = (TDialogCanvas*)GetMother();
   TObject *obj = canvas->GetRefObject();
   if (!obj) return;
   if (strcmp(method,"PIXELS")) {
      obj->Execute(method,params);
   } else {
      TText *text = (TText*)GetListOfPrimitives()->First();
      Int_t npixels = Int_t((YtoPixel(0) - YtoPixel(1))*text->GetTextSize());
      Float_t dy;
      pad = gROOT->GetSelectedPad();
      if (obj->InheritsFrom("TPaveLabel::Class()")) {
         TBox *pl = (TBox*)obj;
         dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY(npixels);
         sprintf(params,"%f",dy/(pl->GetY2() - pl->GetY1()));
      } else {
         dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY(npixels);
         sprintf(params,"%f",dy/(pad->GetY2() - pad->GetY1()));
      }
      obj->Execute("SetTextSize",params);
   }
}

//______________________________________________________________________________
 void TGroupButton::ExecuteEvent(Int_t event, Int_t px, Int_t py)
{
//*-*-*-*-*-*-*-*-*-*-*Execute action corresponding to one event*-*-*-*
//*-*                  =========================================
//*-*  This member function is called when a Button object is clicked.
//*-*

   if (fMother->IsEditable()) {
      TPad::ExecuteEvent(event,px,py);
      return;
   }

   TIter next(gPad->GetCanvas()->GetListOfPrimitives());
   TObject *obj;
   TGroupButton *button;
   TPad *pad;
   TDialogCanvas *canvas;

   switch (event) {

   case kButton1Down:

   case kMouseMotion:

      break;

   case kButton1Motion:

      break;

   case kButton1Up:
      //Clicked on APPLY button?
      if (!strcasecmp(GetName(),"APPLY")) {
         if (!strcasecmp(GetTitle(),"CLOSE")) {
            gPad->GetCanvas()->Close();
            return;
         }
         canvas = (TDialogCanvas*)GetMother();
         pad = canvas->GetRefPad();
         if (pad) pad->GetCanvas()->FeedbackMode(kFALSE);
         canvas->Apply(GetTitle());   //just in case the apply button executes some code
         if (pad) {
            pad->Modified(kTRUE);
            pad->Update();
         }
         break;
      }
      //Unset other buttons with same name
      while ((obj = next())) {
         if (obj == this) continue;
         if (obj->InheritsFrom(TGroupButton::Class())) {
            button = (TGroupButton*)obj;
            if (!strcmp(button->GetName(),GetName())) {
               if (button->GetBorderMode() < 0) {
                  button->SetBorderMode(1);
                  button->Modified();
               }
            }
         }
      }
      //Set button on
      SetBorderMode(-1);
      Modified();
      gPad->GetCanvas()->Modified();
      gPad->Update();
      break;
   }
}

//______________________________________________________________________________
 void TGroupButton::SavePrimitive(ofstream &out, Option_t *)
{
    // Save primitive as a C++ statement(s) on output stream out

   TPad *padsav = (TPad*)gPad;
   char quote = '"';
   if (gROOT->ClassSaved(TGroupButton::Class())) {
       out<<"   ";
   } else {
       out<<"   TGroupButton *";
   }
   out<<"button = new TGroupButton("<<quote<<GetName()<<quote<<", "<<quote<<GetTitle()
      <<quote<<","<<quote<<GetMethod()<<quote
      <<","<<fXlowNDC
      <<","<<fYlowNDC
      <<","<<fXlowNDC+fWNDC
      <<","<<fYlowNDC+fHNDC
      <<");"<<endl;

   SaveFillAttributes(out,"button",0,1001);
   SaveLineAttributes(out,"button",1,1,1);
   SaveTextAttributes(out,"button",22,0,1,62,.75);

   if (GetBorderSize() != 2) {
      out<<"   button->SetBorderSize("<<GetBorderSize()<<");"<<endl;
   }
   if (GetBorderMode() != 1) {
      out<<"   button->SetBorderMode("<<GetBorderMode()<<");"<<endl;
   }

   out<<"   button->Draw();"<<endl;
   out<<"   button->cd();"<<endl;

   TIter next(GetListOfPrimitives());
   TObject *obj = next();  //do not save first primitive

   while ((obj = next()))
         obj->SavePrimitive(out, (Option_t *)next.GetOption());

   out<<"   "<<padsav->GetName()<<"->cd();"<<endl;
   padsav->cd();
}



ROOT page - Class index - 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.