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 "TGFrame.h"
10 #include "TString.h"
11 #include "KVTextEntry.h"
12 #include "TGWindow.h"
13 #include "TGLabel.h"
14 #include "TGButton.h"
15 #include "TTimer.h"
16 
17 
23 
26  const Char_t* question, TString* answer,
27  Bool_t* ok, const Char_t* tooltip)
28 {
29  //Create the dialog box asking a "question" and receiving the "answer"
30  //If you want a default value to appear, put it in 'answer' before opening dialogue
31  //The Bool_t variable will be set to kTRUE if "OK" is pressed (kFALSE otherwise)
32  //Optional argument 'tooltip' will be displayed when mouse held over text entry widget
33 
34  fMain = new TGTransientFrame(gClient->GetRoot(), main, 600, 150);
35  fMain->Connect("CloseWindow()", "KVInputDialog", this, "DoClose()");
36  fMain->DontCallClose(); // to avoid double deletions.
37  // use hierarchical cleaning
38  fMain->SetCleanup(kDeepCleanup);
39 
40  fAnswer = answer;
41  fOK = ok;
42  *fOK = kFALSE; //initialise flag
43  // Add a label and text input field.
44 
45  TGLabel* l = new TGLabel(fMain, question);
46  fTextEntry = new KVTextEntry(fMain, answer->Data());
47  if (strcmp(tooltip, ""))
48  fTextEntry->SetToolTipText(tooltip);
49 
50  fTextEntry->Resize(l->GetDefaultWidth(), fTextEntry->GetDefaultHeight());
51  fMain->AddFrame(l,
53  0));
54  fMain->AddFrame(fTextEntry,
56  5));
57 
58  fMain->SetWindowName("KVInputDialog");
59  fMain->SetIconName("KVInputDialog");
60 
61  //--- create the OK, Apply and Cancel buttons
62 
63  UInt_t nb = 0, width = 0, height = 0;
64 
65  TGHorizontalFrame* hf =
66  new TGHorizontalFrame(fMain, 60, 20, kFixedWidth);
67  TGLayoutHints* l1 =
68  new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 5, 5, 0, 0);
69 
70  fOKBut = new TGTextButton(hf, "&OK", 1);
71  hf->AddFrame(fOKBut, l1);
72  height = fOKBut->GetDefaultHeight();
73  width = TMath::Max(width, fOKBut->GetDefaultWidth());
74  ++nb;
75  fOKBut->Connect("Clicked()", "KVInputDialog", this, "ReadAnswer()");
76  fOKBut->Connect("Clicked()", "KVInputDialog", this, "DoClose()");
77 
78  fCancelBut = new TGTextButton(hf, "&Cancel", 3);
79  hf->AddFrame(fCancelBut, l1);
80  height = fCancelBut->GetDefaultHeight();
81  width = TMath::Max(width, fCancelBut->GetDefaultWidth());
82  ++nb;
83  fCancelBut->Connect("Clicked()", "KVInputDialog", this, "DoClose()");
84 
85  // place buttons at the bottom
86  l1 = new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5);
87 
88  fMain->AddFrame(hf, l1);
89 
90  // keep the buttons centered and with the same width
91  hf->Resize((width + 20) * nb, height);
92 
93  // map all widgets and calculate size of dialog
94  fMain->MapSubwindows();
95 
96  width = fMain->GetDefaultWidth();
97  height = fMain->GetDefaultHeight();
98 
99  fMain->Resize(width, height);
100 
101  // position relative to the parent's window
102  fMain->CenterOnParent();
103 
104  // make the message box non-resizable
105  fMain->SetWMSize(width, height);
106  fMain->SetWMSizeHints(width, height, width, height, 0, 0);
107 
108  fMain->SetMWMHints(kMWMDecorAll | kMWMDecorResizeH | kMWMDecorMaximize |
112 
113  fMain->CenterOnParent();
114  fMain->MapWindow();
115  gClient->WaitFor(fMain);
116 }
117 
118 
119 
120 
123 
124 KVInputDialog::~KVInputDialog()
125 {
126  //Delete all widgets
127 
128  if (fMain) {
129  delete fMain;
130  fMain = 0;
131  }
132 }
133 
134 
135 
136 
138 
140 {
141  TTimer::SingleShot(150, "KVInputDialog", this, "CloseWindow()");
142 }
143 
144 
145 
146 
148 
150 {
151  delete this;
152 }
153 
154 
155 
159 
161 {
162  //Read text from text entry widget and store in "answer" TString.
163  //Set "ok" Bool_t flag to kTRUE
164  *fAnswer = fTextEntry->GetText();
165  *fOK = kTRUE;
166 }
167 
168 
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
KVTextEntry * fTextEntry
text entry for answer
Definition: KVInputDialog.h:31
TString * fAnswer
the answer to the question
Definition: KVInputDialog.h:30
Bool_t * fOK
set to kTRUE if OK button is pressed
Definition: KVInputDialog.h:34
TGTransientFrame * fMain
Definition: KVInputDialog.h:29
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)