ROOT logo
// @(#)root/gpad:$Id: TGroupButton.cxx 20882 2007-11-19 11:31:26Z rdm $
// Author: Rene Brun   01/07/96

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "Riostream.h"
#include "TROOT.h"
#include "TBox.h"
#include "TGroupButton.h"
#include "TVirtualX.h"
#include "TDialogCanvas.h"
#include "TCanvas.h"
#include "TText.h"
#include "TInterpreter.h"
#include "TTimer.h"
#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 char *groupname, const char *title, const char *method, Double_t x1, Double_t y1,Double_t x2, Double_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 char *action, Double_t x0, Double_t y0, Double_t wc, Double_t hc)
{
   // Display Color Table in an attribute canvas.

   TGroupButton *colorpad;
   Int_t i, j;
   Int_t color;
   Double_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());
      Double_t dy;
      pad = gROOT->GetSelectedPad();
      if (obj->InheritsFrom("TPaveLabel")) {
         TBox *pl = (TBox*)obj;
         dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY(npixels);
         sprintf(params,"%f",dy/(pl->GetY2() - pl->GetY1()));
         obj->Execute("SetTextSize",params);
      } else {
         if (obj->InheritsFrom("TPave")) {
            dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY(npixels);
            sprintf(params,"%f",dy/(pad->GetY2() - pad->GetY1()));
            obj->Execute("SetTextSize",params);
         } else {
            sprintf(params,"%d",npixels);
            obj->Execute("SetTextSizePixels",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")) {
         canvas = (TDialogCanvas*)GetMother();
         if (!strcasecmp(GetTitle(),"CLOSE")) {
            canvas->Close();
            return;
         }
         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(ostream &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();
}
 TGroupButton.cxx:1
 TGroupButton.cxx:2
 TGroupButton.cxx:3
 TGroupButton.cxx:4
 TGroupButton.cxx:5
 TGroupButton.cxx:6
 TGroupButton.cxx:7
 TGroupButton.cxx:8
 TGroupButton.cxx:9
 TGroupButton.cxx:10
 TGroupButton.cxx:11
 TGroupButton.cxx:12
 TGroupButton.cxx:13
 TGroupButton.cxx:14
 TGroupButton.cxx:15
 TGroupButton.cxx:16
 TGroupButton.cxx:17
 TGroupButton.cxx:18
 TGroupButton.cxx:19
 TGroupButton.cxx:20
 TGroupButton.cxx:21
 TGroupButton.cxx:22
 TGroupButton.cxx:23
 TGroupButton.cxx:24
 TGroupButton.cxx:25
 TGroupButton.cxx:26
 TGroupButton.cxx:27
 TGroupButton.cxx:28
 TGroupButton.cxx:29
 TGroupButton.cxx:30
 TGroupButton.cxx:31
 TGroupButton.cxx:32
 TGroupButton.cxx:33
 TGroupButton.cxx:34
 TGroupButton.cxx:35
 TGroupButton.cxx:36
 TGroupButton.cxx:37
 TGroupButton.cxx:38
 TGroupButton.cxx:39
 TGroupButton.cxx:40
 TGroupButton.cxx:41
 TGroupButton.cxx:42
 TGroupButton.cxx:43
 TGroupButton.cxx:44
 TGroupButton.cxx:45
 TGroupButton.cxx:46
 TGroupButton.cxx:47
 TGroupButton.cxx:48
 TGroupButton.cxx:49
 TGroupButton.cxx:50
 TGroupButton.cxx:51
 TGroupButton.cxx:52
 TGroupButton.cxx:53
 TGroupButton.cxx:54
 TGroupButton.cxx:55
 TGroupButton.cxx:56
 TGroupButton.cxx:57
 TGroupButton.cxx:58
 TGroupButton.cxx:59
 TGroupButton.cxx:60
 TGroupButton.cxx:61
 TGroupButton.cxx:62
 TGroupButton.cxx:63
 TGroupButton.cxx:64
 TGroupButton.cxx:65
 TGroupButton.cxx:66
 TGroupButton.cxx:67
 TGroupButton.cxx:68
 TGroupButton.cxx:69
 TGroupButton.cxx:70
 TGroupButton.cxx:71
 TGroupButton.cxx:72
 TGroupButton.cxx:73
 TGroupButton.cxx:74
 TGroupButton.cxx:75
 TGroupButton.cxx:76
 TGroupButton.cxx:77
 TGroupButton.cxx:78
 TGroupButton.cxx:79
 TGroupButton.cxx:80
 TGroupButton.cxx:81
 TGroupButton.cxx:82
 TGroupButton.cxx:83
 TGroupButton.cxx:84
 TGroupButton.cxx:85
 TGroupButton.cxx:86
 TGroupButton.cxx:87
 TGroupButton.cxx:88
 TGroupButton.cxx:89
 TGroupButton.cxx:90
 TGroupButton.cxx:91
 TGroupButton.cxx:92
 TGroupButton.cxx:93
 TGroupButton.cxx:94
 TGroupButton.cxx:95
 TGroupButton.cxx:96
 TGroupButton.cxx:97
 TGroupButton.cxx:98
 TGroupButton.cxx:99
 TGroupButton.cxx:100
 TGroupButton.cxx:101
 TGroupButton.cxx:102
 TGroupButton.cxx:103
 TGroupButton.cxx:104
 TGroupButton.cxx:105
 TGroupButton.cxx:106
 TGroupButton.cxx:107
 TGroupButton.cxx:108
 TGroupButton.cxx:109
 TGroupButton.cxx:110
 TGroupButton.cxx:111
 TGroupButton.cxx:112
 TGroupButton.cxx:113
 TGroupButton.cxx:114
 TGroupButton.cxx:115
 TGroupButton.cxx:116
 TGroupButton.cxx:117
 TGroupButton.cxx:118
 TGroupButton.cxx:119
 TGroupButton.cxx:120
 TGroupButton.cxx:121
 TGroupButton.cxx:122
 TGroupButton.cxx:123
 TGroupButton.cxx:124
 TGroupButton.cxx:125
 TGroupButton.cxx:126
 TGroupButton.cxx:127
 TGroupButton.cxx:128
 TGroupButton.cxx:129
 TGroupButton.cxx:130
 TGroupButton.cxx:131
 TGroupButton.cxx:132
 TGroupButton.cxx:133
 TGroupButton.cxx:134
 TGroupButton.cxx:135
 TGroupButton.cxx:136
 TGroupButton.cxx:137
 TGroupButton.cxx:138
 TGroupButton.cxx:139
 TGroupButton.cxx:140
 TGroupButton.cxx:141
 TGroupButton.cxx:142
 TGroupButton.cxx:143
 TGroupButton.cxx:144
 TGroupButton.cxx:145
 TGroupButton.cxx:146
 TGroupButton.cxx:147
 TGroupButton.cxx:148
 TGroupButton.cxx:149
 TGroupButton.cxx:150
 TGroupButton.cxx:151
 TGroupButton.cxx:152
 TGroupButton.cxx:153
 TGroupButton.cxx:154
 TGroupButton.cxx:155
 TGroupButton.cxx:156
 TGroupButton.cxx:157
 TGroupButton.cxx:158
 TGroupButton.cxx:159
 TGroupButton.cxx:160
 TGroupButton.cxx:161
 TGroupButton.cxx:162
 TGroupButton.cxx:163
 TGroupButton.cxx:164
 TGroupButton.cxx:165
 TGroupButton.cxx:166
 TGroupButton.cxx:167
 TGroupButton.cxx:168
 TGroupButton.cxx:169
 TGroupButton.cxx:170
 TGroupButton.cxx:171
 TGroupButton.cxx:172
 TGroupButton.cxx:173
 TGroupButton.cxx:174
 TGroupButton.cxx:175
 TGroupButton.cxx:176
 TGroupButton.cxx:177
 TGroupButton.cxx:178
 TGroupButton.cxx:179
 TGroupButton.cxx:180
 TGroupButton.cxx:181
 TGroupButton.cxx:182
 TGroupButton.cxx:183
 TGroupButton.cxx:184
 TGroupButton.cxx:185
 TGroupButton.cxx:186
 TGroupButton.cxx:187
 TGroupButton.cxx:188
 TGroupButton.cxx:189
 TGroupButton.cxx:190
 TGroupButton.cxx:191
 TGroupButton.cxx:192
 TGroupButton.cxx:193
 TGroupButton.cxx:194
 TGroupButton.cxx:195
 TGroupButton.cxx:196
 TGroupButton.cxx:197
 TGroupButton.cxx:198
 TGroupButton.cxx:199
 TGroupButton.cxx:200
 TGroupButton.cxx:201
 TGroupButton.cxx:202
 TGroupButton.cxx:203
 TGroupButton.cxx:204
 TGroupButton.cxx:205
 TGroupButton.cxx:206
 TGroupButton.cxx:207
 TGroupButton.cxx:208
 TGroupButton.cxx:209
 TGroupButton.cxx:210
 TGroupButton.cxx:211
 TGroupButton.cxx:212
 TGroupButton.cxx:213
 TGroupButton.cxx:214
 TGroupButton.cxx:215
 TGroupButton.cxx:216
 TGroupButton.cxx:217
 TGroupButton.cxx:218
 TGroupButton.cxx:219
 TGroupButton.cxx:220
 TGroupButton.cxx:221
 TGroupButton.cxx:222
 TGroupButton.cxx:223
 TGroupButton.cxx:224
 TGroupButton.cxx:225
 TGroupButton.cxx:226
 TGroupButton.cxx:227
 TGroupButton.cxx:228
 TGroupButton.cxx:229
 TGroupButton.cxx:230
 TGroupButton.cxx:231
 TGroupButton.cxx:232
 TGroupButton.cxx:233
 TGroupButton.cxx:234
 TGroupButton.cxx:235
 TGroupButton.cxx:236
 TGroupButton.cxx:237
 TGroupButton.cxx:238
 TGroupButton.cxx:239
 TGroupButton.cxx:240
 TGroupButton.cxx:241
 TGroupButton.cxx:242
 TGroupButton.cxx:243
 TGroupButton.cxx:244
 TGroupButton.cxx:245
 TGroupButton.cxx:246
 TGroupButton.cxx:247
 TGroupButton.cxx:248
 TGroupButton.cxx:249
 TGroupButton.cxx:250
 TGroupButton.cxx:251
 TGroupButton.cxx:252
 TGroupButton.cxx:253
 TGroupButton.cxx:254
 TGroupButton.cxx:255
 TGroupButton.cxx:256