KaliVeda
Toolkit for HIC analysis
KVInputDialog.cpp
1 /*
2 $Id: KVInputDialog.cpp,v 1.6 2007/12/12 11:17:54 franklan Exp $
3 $Revision: 1.6 $
4 $Date: 2007/12/12 11:17:54 $
5 $Author: franklan $
6 */
7 
8 #include "KVInputDialog.h"
9 #include "TMath.h"
10 #include "TGFrame.h"
11 #include "TString.h"
12 #include "KVTextEntry.h"
13 #include "TGWindow.h"
14 #include "TGLabel.h"
15 #include "TGButton.h"
16 #include "TTimer.h"
17 
18 
24 
27  const Char_t* question, TString* answer,
28  Bool_t* ok, const Char_t* tooltip)
29 {
30  //Create the dialog box asking a "question" and receiving the "answer"
31  //If you want a default value to appear, put it in 'answer' before opening dialogue
32  //The Bool_t variable will be set to kTRUE if "OK" is pressed (kFALSE otherwise)
33  //Optional argument 'tooltip' will be displayed when mouse held over text entry widget
34 
35  fMain = new TGTransientFrame(gClient->GetRoot(), main, 600, 150);
36  fMain->Connect("CloseWindow()", "KVInputDialog", this, "DoClose()");
37  fMain->DontCallClose(); // to avoid double deletions.
38  // use hierarchical cleaning
39  fMain->SetCleanup(kDeepCleanup);
40 
41  fAnswer = answer;
42  fOK = ok;
43  *fOK = kFALSE; //initialise flag
44  // Add a label and text input field.
45 
46  TGLabel* l = new TGLabel(fMain, question);
47  fTextEntry = new KVTextEntry(fMain, answer->Data());
48  if (strcmp(tooltip, ""))
49  fTextEntry->SetToolTipText(tooltip);
50 
51  fTextEntry->Resize(l->GetDefaultWidth(), fTextEntry->GetDefaultHeight());
52  fMain->AddFrame(l,
54  0));
55  fMain->AddFrame(fTextEntry,
57  5));
58 
59  fMain->SetWindowName("KVInputDialog");
60  fMain->SetIconName("KVInputDialog");
61 
62  //--- create the OK, Apply and Cancel buttons
63 
64  UInt_t nb = 0, width = 0, height = 0;
65 
66  TGHorizontalFrame* hf =
67  new TGHorizontalFrame(fMain, 60, 20, kFixedWidth);
68  TGLayoutHints* l1 =
69  new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 5, 5, 0, 0);
70 
71  fOKBut = new TGTextButton(hf, "&OK", 1);
72  hf->AddFrame(fOKBut, l1);
73  height = fOKBut->GetDefaultHeight();
74  width = TMath::Max(width, fOKBut->GetDefaultWidth());
75  ++nb;
76  fOKBut->Connect("Clicked()", "KVInputDialog", this, "ReadAnswer()");
77  fOKBut->Connect("Clicked()", "KVInputDialog", this, "DoClose()");
78 
79  fCancelBut = new TGTextButton(hf, "&Cancel", 3);
80  hf->AddFrame(fCancelBut, l1);
81  height = fCancelBut->GetDefaultHeight();
82  width = TMath::Max(width, fCancelBut->GetDefaultWidth());
83  ++nb;
84  fCancelBut->Connect("Clicked()", "KVInputDialog", this, "DoClose()");
85 
86  // place buttons at the bottom
87  l1 = new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5);
88 
89  fMain->AddFrame(hf, l1);
90 
91  // keep the buttons centered and with the same width
92  hf->Resize((width + 20) * nb, height);
93 
94  // map all widgets and calculate size of dialog
95  fMain->MapSubwindows();
96 
97  width = fMain->GetDefaultWidth();
98  height = fMain->GetDefaultHeight();
99 
100  fMain->Resize(width, height);
101 
102  // position relative to the parent's window
103  fMain->CenterOnParent();
104 
105  // make the message box non-resizable
106  fMain->SetWMSize(width, height);
107  fMain->SetWMSizeHints(width, height, width, height, 0, 0);
108 
109  fMain->SetMWMHints(kMWMDecorAll | kMWMDecorResizeH | kMWMDecorMaximize |
113 
114  fMain->CenterOnParent();
115  fMain->MapWindow();
116  gClient->WaitFor(fMain);
117 }
118 
119 
120 
121 
124 
125 KVInputDialog::~KVInputDialog()
126 {
127  //Delete all widgets
128 
129  if (fMain) {
130  delete fMain;
131  fMain = 0;
132  }
133 }
134 
135 
136 
137 
139 
141 {
142  TTimer::SingleShot(150, "KVInputDialog", this, "CloseWindow()");
143 }
144 
145 
146 
147 
149 
151 {
152  delete this;
153 }
154 
155 
156 
160 
162 {
163  //Read text from text entry widget and store in "answer" TString.
164  //Set "ok" Bool_t flag to kTRUE
165  *fAnswer = fTextEntry->GetText();
166  *fOK = kTRUE;
167 }
168 
169 
unsigned int UInt_t
kFixedWidth
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
#define gClient
kMWMDecorResizeH
kMWMFuncAll
kMWMFuncResize
kMWMDecorMaximize
kMWMDecorMinimize
kMWMDecorMenu
kMWMDecorAll
kMWMFuncMaximize
kMWMInputModeless
kMWMFuncMinimize
kDeepCleanup
kLHintsCenterY
kLHintsCenterX
kLHintsBottom
kLHintsTop
kLHintsExpandX
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
General purpose dialog box asking for some input in the form of a string.
Definition: KVInputDialog.h:24
TGTextEntry without any limit on the length of the text.
Definition: KVTextEntry.h:22
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
virtual void Resize(TGDimension size)
const char * GetText() const
static void SingleShot(Int_t milliSec, const char *receiver_class, void *receiver, const char *method)
int main(int argc, char **argv)
Double_t Max(Double_t a, Double_t b)
TLine l
ClassImp(TPyArg)