Logo ROOT   6.12/07
Reference Guide
TTreeInput.cxx
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: David Gonzalez Maline 21/10/2008
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 //////////////////////////////////////////////////////////////////////////
13 // //
14 // Tree Input Widget //
15 // //
16 // An dialog box that asks the user for the variables and cuts //
17 // of the selected tree in the fitpanel. //
18 // //
19 //////////////////////////////////////////////////////////////////////////
20 
21 #include "TTreeInput.h"
22 #include "TGButton.h"
23 #include "TGLabel.h"
24 #include "TGTextEntry.h"
25 
26 enum ETreeInput {
28 };
29 
31 
32 ////////////////////////////////////////////////////////////////////////////////
33 /// Create simple input dialog.
34 
36  char *strvars, char *strcuts):
37  TGTransientFrame(p, main, 10, 10, kVerticalFrame),
38  fStrvars(strvars),
39  fStrcuts(strcuts)
40 {
41  if (!p && !main) {
42  MakeZombie();
43  return;
44  }
46 
47  TGLabel *label = new TGLabel(this, "Selected Variables: ");
48  AddFrame(label, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 0));
49 
50  TGTextBuffer *tbuf = new TGTextBuffer(256); //will be deleted by TGtextEntry
51  fTEVars = new TGTextEntry(this, tbuf, kTI_TEVARS);
54 
55  label = new TGLabel(this, "Selected Cuts: ");
56  AddFrame(label, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 0));
57 
58  tbuf = new TGTextBuffer(256); //will be deleted by TGtextEntry
59  fTECuts = new TGTextEntry(this, tbuf, kTI_TECUTS);
62 
63  // create frame and layout hints for Ok and Cancel buttons
64  TGHorizontalFrame *hf = new TGHorizontalFrame(this, 60, 20, kFixedWidth);
66 
67  // create OK and Cancel buttons in their own frame (hf)
68  UInt_t width = 0, height = 0;
69 
70  fOk = new TGTextButton(hf, "&Ok", 1);
71  fOk->Associate(this);
72  hf->AddFrame(fOk, new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 5, 5, 0, 0));
73  height = fOk->GetDefaultHeight();
74  width = TMath::Max(width, fOk->GetDefaultWidth());
75 
76  fCancel = new TGTextButton(hf, "&Cancel", 2);
77  fCancel->Associate(this);
78  hf->AddFrame(fCancel, new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 5, 5, 0, 0));
79  height = fCancel->GetDefaultHeight();
80  width = TMath::Max(width, fCancel->GetDefaultWidth());
81 
82  // place button frame (hf) at the bottom
83  AddFrame(hf, new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5));
84 
85  // keep buttons centered and with the same width
86  hf->Resize((width + 20) * 2, height);
87 
88  // set dialog title
89  SetWindowName("Get Input");
90 
91  // map all widgets and calculate size of dialog
92  MapSubwindows();
93 
94  width = GetDefaultWidth();
95  height = GetDefaultHeight();
96 
97  Resize(width, height);
98 
99  // position relative to the parent's window
100  CenterOnParent();
101 
102  // make the message box non-resizable
103  SetWMSize(width, height);
104  SetWMSizeHints(width, height, width, height, 0, 0);
105 
111 
112  // popup dialog and wait till user replies
113  MapWindow();
114  fTEVars->SetFocus();
115 
116  gClient->WaitFor(this);
117 }
118 
119 ////////////////////////////////////////////////////////////////////////////////
120 /// Cleanup dialog.
121 
123 {
124  Cleanup();
125 }
126 
127 ////////////////////////////////////////////////////////////////////////////////
128 /// Handle button and text enter events
129 
131 {
132  switch (GET_MSG(msg)) {
133  case kC_COMMAND:
134  switch (GET_SUBMSG(msg)) {
135  case kCM_BUTTON:
136  switch (parm1) {
137  case 1:
138  // here copy the string from text buffer to return variable
139  // see TFitEditor.cxx for the maximum length:
140  // char variables[256] = {0}; char cuts[256] = {0};
141  strlcpy(fStrvars, fTEVars->GetBuffer()->GetString(), 256);
142  strlcpy(fStrcuts, fTECuts->GetBuffer()->GetString(), 256);
143  delete this;
144  break;
145  case 2:
146  fStrvars[0] = 0;
147  fStrcuts[0] = 0;
148  delete this;
149  break;
150  }
151  default:
152  break;
153  }
154  break;
155 
156  case kC_TEXTENTRY:
157  switch (GET_SUBMSG(msg)) {
158  case kTE_ENTER:
159  // here copy the string from text buffer to return variable
160  // see TFitEditor.cxx for the maximum length:
161  // char variables[256] = {0}; char cuts[256] = {0};
162  strlcpy(fStrvars, fTEVars->GetBuffer()->GetString(), 256);
163  strlcpy(fStrcuts, fTECuts->GetBuffer()->GetString(), 256);
164  delete this;
165  break;
166  case kTE_TAB:
167  if ( parm1 == kTI_TEVARS )
168  fTECuts->SetFocus();
169  else if ( parm1 == kTI_TECUTS )
170  fTEVars->SetFocus();
171  break;
172  default:
173  break;
174  }
175  break;
176 
177  default:
178  break;
179  }
180  return kTRUE;
181 }
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
TGTextEntry * fTECuts
Definition: TTreeInput.h:34
virtual void CenterOnParent(Bool_t croot=kTRUE, EPlacement pos=kCenter)
Position transient frame centered relative to the parent frame.
Definition: TGFrame.cxx:1913
~TTreeInput()
Cleanup dialog.
Definition: TTreeInput.cxx:122
void SetWindowName(const char *name=0)
Set window name. This is typically done via the window manager.
Definition: TGFrame.cxx:1746
#define gClient
Definition: TGClient.h:166
ETreeInput
Definition: TTreeInput.cxx:26
bool Bool_t
Definition: RtypesCore.h:59
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:373
void SetWMSizeHints(UInt_t wmin, UInt_t hmin, UInt_t wmax, UInt_t hmax, UInt_t winc, UInt_t hinc)
Give the window manager minimum and maximum size hints.
Definition: TGFrame.cxx:1862
TTreeInput(const TTreeInput &)
virtual void SetFocus()
Set focus to this text entry.
const char * GetString() const
Definition: TGTextBuffer.h:47
int main(int argc, char **argv)
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t)
Handle button and text enter events.
Definition: TTreeInput.cxx:130
TGTextBuffer * GetBuffer() const
Definition: TGTextEntry.h:127
TGTextEntry * fTEVars
Definition: TTreeInput.h:33
virtual UInt_t GetDefaultWidth() const
Definition: TGFrame.h:371
Int_t GET_SUBMSG(Long_t val)
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:84
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual UInt_t GetDefaultWidth() const
Definition: TGFrame.h:237
Int_t GET_MSG(Long_t val)
long Long_t
Definition: RtypesCore.h:50
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:238
#define ClassImp(name)
Definition: Rtypes.h:359
TGTextButton * fOk
Definition: TTreeInput.h:35
virtual void SetCleanup(Int_t mode=kLocalCleanup)
Turn on automatic cleanup of child frames in dtor.
Definition: TGFrame.cxx:1054
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1146
char * fStrvars
Definition: TTreeInput.h:37
virtual void MapWindow()
Definition: TGFrame.h:251
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:200
void MakeZombie()
Definition: TObject.h:49
void SetWMSize(UInt_t w, UInt_t h)
Give the window manager a window size hint.
Definition: TGFrame.cxx:1849
virtual void Cleanup()
Cleanup and delete all objects contained in this composite frame.
Definition: TGFrame.cxx:949
void SetMWMHints(UInt_t value, UInt_t funcs, UInt_t input)
Set decoration style for MWM-compatible wm (mwm, ncdwm, fvwm?).
Definition: TGFrame.cxx:1824
const Bool_t kTRUE
Definition: RtypesCore.h:87
TGTextButton * fCancel
Definition: TTreeInput.h:36
char * fStrcuts
Definition: TTreeInput.h:38