Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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/** \class TTreeInput
14 \ingroup fitpanel
15
16Tree Input Dialog Widget
17
18An dialog box that asks the user for the variables and cuts
19of the selected tree in the fitpanel.
20
21*/
22
23
24#include "TTreeInput.h"
25#include "TGButton.h"
26#include "TGLabel.h"
27#include "TGTextEntry.h"
28#include "strlcpy.h"
29
33
34
35////////////////////////////////////////////////////////////////////////////////
36/// Create simple input dialog.
37
39 char *strvars, char *strcuts):
41 fStrvars(strvars),
42 fStrcuts(strcuts)
43{
44 if (!p && !main) {
45 MakeZombie();
46 return;
47 }
49
50 TGLabel *label = new TGLabel(this, "Selected Variables: ");
51 AddFrame(label, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 0));
52
53 TGTextBuffer *tbuf = new TGTextBuffer(256); //will be deleted by TGtextEntry
54 fTEVars = new TGTextEntry(this, tbuf, kTI_TEVARS);
55 fTEVars->Resize(260, fTEVars->GetDefaultHeight());
57
58 label = new TGLabel(this, "Selected Cuts: ");
59 AddFrame(label, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 0));
60
61 tbuf = new TGTextBuffer(256); //will be deleted by TGtextEntry
62 fTECuts = new TGTextEntry(this, tbuf, kTI_TECUTS);
63 fTECuts->Resize(260, fTECuts->GetDefaultHeight());
65
66 // create frame and layout hints for Ok and Cancel buttons
67 TGHorizontalFrame *hf = new TGHorizontalFrame(this, 60, 20, kFixedWidth);
69
70 // create OK and Cancel buttons in their own frame (hf)
71 UInt_t width = 0, height = 0;
72
73 fOk = new TGTextButton(hf, "&Ok", 1);
74 fOk->Associate(this);
76 width = std::max(width, fOk->GetDefaultWidth());
77
78 fCancel = new TGTextButton(hf, "&Cancel", 2);
79 fCancel->Associate(this);
81 height = fCancel->GetDefaultHeight();
82 width = std::max(width, fCancel->GetDefaultWidth());
83
84 // place button frame (hf) at the bottom
85 AddFrame(hf, new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5));
86
87 // keep buttons centered and with the same width
88 hf->Resize((width + 20) * 2, height);
89
90 // set dialog title
91 SetWindowName("Get Input");
92
93 // map all widgets and calculate size of dialog
95
96 width = GetDefaultWidth();
97 height = GetDefaultHeight();
98
99 Resize(width, height);
100
101 // position relative to the parent's window
103
104 // make the message box non-resizable
105 SetWMSize(width, height);
106 SetWMSizeHints(width, height, width, height, 0, 0);
107
113
114 // popup dialog and wait till user replies
115 MapWindow();
116 fTEVars->SetFocus();
117
118 gClient->WaitFor(this);
119}
120
121////////////////////////////////////////////////////////////////////////////////
122/// Cleanup dialog.
123
128
129////////////////////////////////////////////////////////////////////////////////
130/// Handle button and text enter events
131
133{
134 switch (GET_MSG(msg)) {
135 case kC_COMMAND:
136 switch (GET_SUBMSG(msg)) {
137 case kCM_BUTTON:
138 switch (parm1) {
139 case 1:
140 // here copy the string from text buffer to return variable
141 // see TFitEditor.cxx for the maximum length:
142 // char variables[256] = {0}; char cuts[256] = {0};
143 strlcpy(fStrvars, fTEVars->GetBuffer()->GetString(), 256);
144 strlcpy(fStrcuts, fTECuts->GetBuffer()->GetString(), 256);
145 delete this;
146 break;
147 case 2:
148 fStrvars[0] = 0;
149 fStrcuts[0] = 0;
150 delete this;
151 break;
152 }
153 default:
154 break;
155 }
156 break;
157
158 case kC_TEXTENTRY:
159 switch (GET_SUBMSG(msg)) {
160 case kTE_ENTER:
161 // here copy the string from text buffer to return variable
162 // see TFitEditor.cxx for the maximum length:
163 // char variables[256] = {0}; char cuts[256] = {0};
164 strlcpy(fStrvars, fTEVars->GetBuffer()->GetString(), 256);
165 strlcpy(fStrcuts, fTECuts->GetBuffer()->GetString(), 256);
166 delete this;
167 break;
168 case kTE_TAB:
169 if ( parm1 == kTI_TEVARS )
170 fTECuts->SetFocus();
171 else if ( parm1 == kTI_TECUTS )
172 fTEVars->SetFocus();
173 break;
174 default:
175 break;
176 }
177 break;
178
179 default:
180 break;
181 }
182 return kTRUE;
183}
@ kVerticalFrame
Definition GuiTypes.h:382
@ kFixedWidth
Definition GuiTypes.h:388
long Longptr_t
Integer large enough to hold a pointer (platform-dependent).
Definition RtypesCore.h:89
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
#define gClient
Definition TGClient.h:157
@ kMWMDecorResizeH
Definition TGFrame.h:65
@ kMWMFuncAll
Definition TGFrame.h:49
@ kMWMFuncResize
Definition TGFrame.h:50
@ kMWMDecorMaximize
Definition TGFrame.h:69
@ kMWMDecorMinimize
Definition TGFrame.h:68
@ kMWMDecorMenu
Definition TGFrame.h:67
@ kMWMDecorAll
Definition TGFrame.h:63
@ kMWMFuncMaximize
Definition TGFrame.h:53
@ kMWMInputModeless
Definition TGFrame.h:57
@ kMWMFuncMinimize
Definition TGFrame.h:52
@ kDeepCleanup
Definition TGFrame.h:42
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsCenterY
Definition TGLayout.h:28
@ kLHintsCenterX
Definition TGLayout.h:25
@ kLHintsBottom
Definition TGLayout.h:29
@ kLHintsTop
Definition TGLayout.h:27
@ kLHintsExpandX
Definition TGLayout.h:30
ETreeInput
@ kTI_TECUTS
@ kTI_TEVARS
Int_t GET_MSG(Long_t val)
@ kTE_ENTER
@ kC_COMMAND
@ kCM_BUTTON
@ kTE_TAB
@ kC_TEXTENTRY
Int_t GET_SUBMSG(Long_t val)
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1109
UInt_t GetDefaultWidth() const override
Definition TGFrame.h:314
virtual void Cleanup()
Cleanup and delete all objects contained in this composite frame.
Definition TGFrame.cxx:959
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1156
UInt_t GetDefaultHeight() const override
Definition TGFrame.h:316
void SetCleanup(Int_t mode=kLocalCleanup) override
Turn on automatic cleanup of child frames in dtor.
Definition TGFrame.cxx:1064
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:597
void MapWindow() override
map window
Definition TGFrame.h:206
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:387
This class handles GUI labels.
Definition TGLabel.h:24
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
void SetWMSize(UInt_t w, UInt_t h)
Give the window manager a window size hint.
Definition TGFrame.cxx:1885
void SetWindowName(const char *name=nullptr) override
Set window name. This is typically done via the window manager.
Definition TGFrame.cxx:1780
void SetMWMHints(UInt_t value, UInt_t funcs, UInt_t input)
Set decoration style for MWM-compatible wm (mwm, ncdwm, fvwm?).
Definition TGFrame.cxx:1860
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:1898
A text buffer is used in several widgets, like TGTextEntry, TGFileDialog, etc.
Yield an action as soon as it is clicked.
Definition TGButton.h:142
A TGTextEntry is a one line text input widget.
Definition TGTextEntry.h:24
TGTransientFrame(const TGTransientFrame &)=delete
virtual void CenterOnParent(Bool_t croot=kTRUE, EPlacement pos=kCenter)
Position transient frame centered relative to the parent frame.
Definition TGFrame.cxx:1949
ROOT GUI Window base class.
Definition TGWindow.h:23
void MakeZombie()
Definition TObject.h:55
TGTextButton * fOk
ok button
Definition TTreeInput.h:27
char * fStrcuts
address to store cuts string
Definition TTreeInput.h:30
char * fStrvars
address to store variables string
Definition TTreeInput.h:29
TTreeInput(const TTreeInput &)
TGTextEntry * fTECuts
text entry widget for cuts
Definition TTreeInput.h:26
~TTreeInput() override
Cleanup dialog.
TGTextEntry * fTEVars
text entry widget for variables
Definition TTreeInput.h:25
TGTextButton * fCancel
cancel button
Definition TTreeInput.h:28
Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t) override
Handle button and text enter events.
int main(int argc, char **argv)
Definition hadd.cxx:631