TTreeInput.cxx

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TTreeInput.cxx 35505 2010-09-21 08:18:20Z brun $
00002 // Author: David Gonzalez Maline  21/10/2008
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 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // Tree Input Widget                                                    //
00015 //                                                                      //
00016 // An dialog box that asks the user for the variables and cuts          //
00017 // of the selected tree in the fitpanel.                                //
00018 //                                                                      //
00019 //////////////////////////////////////////////////////////////////////////
00020 
00021 #include "TTreeInput.h"
00022 #include "TGButton.h"
00023 #include "TGLabel.h"
00024 #include "TGTextEntry.h"
00025 
00026 enum ETreeInput {
00027    kTI_TEVARS, kTI_TECUTS
00028 };
00029 
00030 ClassImp(TTreeInput)
00031 
00032 //______________________________________________________________________________
00033    TTreeInput::TTreeInput(const TGWindow *p, const TGWindow *main,
00034                           char *strvars, char *strcuts):
00035       TGTransientFrame(p, main, 10, 10, kVerticalFrame),
00036       fStrvars(strvars),
00037       fStrcuts(strcuts)
00038 {
00039    // Create simple input dialog.
00040 
00041    if (!p && !main) {
00042       MakeZombie();
00043       return;
00044    }
00045    SetCleanup(kDeepCleanup);
00046 
00047    TGLabel *label = new TGLabel(this, "Selected Variables: ");
00048    AddFrame(label, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 0));
00049 
00050    TGTextBuffer *tbuf = new TGTextBuffer(256);  //will be deleted by TGtextEntry
00051    fTEVars = new TGTextEntry(this, tbuf, kTI_TEVARS);
00052    fTEVars->Resize(260, fTEVars->GetDefaultHeight());
00053    AddFrame(fTEVars, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5));
00054 
00055    label = new TGLabel(this, "Selected Cuts: ");
00056    AddFrame(label, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 0));
00057 
00058    tbuf = new TGTextBuffer(256);  //will be deleted by TGtextEntry
00059    fTECuts = new TGTextEntry(this, tbuf, kTI_TECUTS);
00060    fTECuts->Resize(260, fTECuts->GetDefaultHeight());
00061    AddFrame(fTECuts, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5));
00062 
00063    // create frame and layout hints for Ok and Cancel buttons
00064    TGHorizontalFrame *hf = new TGHorizontalFrame(this, 60, 20, kFixedWidth);
00065    hf->SetCleanup(kDeepCleanup);
00066 
00067    // create OK and Cancel buttons in their own frame (hf)
00068    UInt_t  width = 0, height = 0;
00069 
00070    fOk = new TGTextButton(hf, "&Ok", 1);
00071    fOk->Associate(this);
00072    hf->AddFrame(fOk, new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 5, 5, 0, 0));
00073    height = fOk->GetDefaultHeight();
00074    width  = TMath::Max(width, fOk->GetDefaultWidth());
00075 
00076    fCancel = new TGTextButton(hf, "&Cancel", 2);
00077    fCancel->Associate(this);
00078    hf->AddFrame(fCancel, new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 5, 5, 0, 0));
00079    height = fCancel->GetDefaultHeight();
00080    width  = TMath::Max(width, fCancel->GetDefaultWidth());
00081 
00082    // place button frame (hf) at the bottom
00083    AddFrame(hf, new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5));
00084 
00085    // keep buttons centered and with the same width
00086    hf->Resize((width + 20) * 2, height);
00087 
00088    // set dialog title
00089    SetWindowName("Get Input");
00090 
00091    // map all widgets and calculate size of dialog
00092    MapSubwindows();
00093 
00094    width  = GetDefaultWidth();
00095    height = GetDefaultHeight();
00096 
00097    Resize(width, height);
00098 
00099    // position relative to the parent's window
00100    CenterOnParent();
00101 
00102    // make the message box non-resizable
00103    SetWMSize(width, height);
00104    SetWMSizeHints(width, height, width, height, 0, 0);
00105 
00106    SetMWMHints(kMWMDecorAll | kMWMDecorResizeH  | kMWMDecorMaximize |
00107                                        kMWMDecorMinimize | kMWMDecorMenu,
00108                         kMWMFuncAll  | kMWMFuncResize    | kMWMFuncMaximize |
00109                                        kMWMFuncMinimize,
00110                         kMWMInputModeless);
00111 
00112    // popup dialog and wait till user replies
00113    MapWindow();
00114    fTEVars->SetFocus();
00115 
00116    gClient->WaitFor(this);
00117 }
00118 
00119 //______________________________________________________________________________
00120 TTreeInput::~TTreeInput()
00121 {
00122    // Cleanup dialog.
00123 
00124    Cleanup();
00125 }
00126 
00127 //______________________________________________________________________________
00128 Bool_t TTreeInput::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
00129 {
00130    // Handle button and text enter events
00131 
00132    switch (GET_MSG(msg)) {
00133       case kC_COMMAND:
00134          switch (GET_SUBMSG(msg)) {
00135             case kCM_BUTTON:
00136                switch (parm1) {
00137                   case 1:
00138                      // here copy the string from text buffer to return variable
00139                      // see TFitEditor.cxx for the maximum length:
00140                      // char variables[256] = {0}; char cuts[256] = {0};
00141                      strlcpy(fStrvars, fTEVars->GetBuffer()->GetString(), 256);
00142                      strlcpy(fStrcuts, fTECuts->GetBuffer()->GetString(), 256);
00143                      delete this;
00144                      break;
00145                   case 2:
00146                      fStrvars[0] = 0;
00147                      fStrcuts[0] = 0;
00148                      delete this;
00149                      break;
00150                }
00151                default:
00152                   break;
00153          }
00154          break;
00155 
00156       case kC_TEXTENTRY:
00157          switch (GET_SUBMSG(msg)) {
00158             case kTE_ENTER:
00159                // here copy the string from text buffer to return variable
00160                // see TFitEditor.cxx for the maximum length:
00161                // char variables[256] = {0}; char cuts[256] = {0};
00162                strlcpy(fStrvars, fTEVars->GetBuffer()->GetString(), 256);
00163                strlcpy(fStrcuts, fTECuts->GetBuffer()->GetString(), 256);
00164                delete this;
00165                break;
00166             case kTE_TAB:
00167                if ( parm1 == kTI_TEVARS )
00168                   fTECuts->SetFocus();
00169                else if ( parm1 == kTI_TECUTS )
00170                   fTEVars->SetFocus();
00171                break;
00172             default:
00173                break;
00174          }
00175          break;
00176 
00177       default:
00178          break;
00179    }
00180    return kTRUE;
00181 }

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