KaliVeda
Toolkit for HIC analysis
KVTextDialog.cpp
1 //Created by KVClassFactory on Thu May 16 11:38:27 2013
2 //Author: gruyer,,,
3 
4 #include "KVTextDialog.h"
5 #include "TGTextEntry.h"
6 #include "TGFrame.h"
7 #include "KVString.h"
8 #include "TGComboBox.h"
9 #include "TGWindow.h"
10 #include "TGLabel.h"
11 #include "TGButton.h"
12 #include "TTimer.h"
13 #include "TMath.h"
14 
15 
17 
18 
19 
21 KVTextDialog::KVTextDialog(const TGWindow* main, const Char_t* question, const Char_t* default_value, TString* chosen, Bool_t* ok, const char* unit)
22 {
23  fMain = new TGTransientFrame(gClient->GetDefaultRoot(), main, 200, 100);
24  fMain->CenterOnParent();
25  fMain->Connect("CloseWindow()", "KVDropDownDialog", this, "DoClose()");
26  fMain->DontCallClose(); // to avoid double deletions.
27  // use hierarchical cleaning
28  fMain->SetCleanup(kDeepCleanup);
29 
30  fAnswer = chosen;
31  fOK = ok;
32  *fOK = kFALSE; //initialise flag
33 
34  // Add a label
35  TGLabel* l = new TGLabel(fMain, question);
36  fMain->AddFrame(l, new TGLayoutHints(kLHintsTop | kLHintsCenterX, 5, 5, 5, 0));
37  TGHorizontalFrame* hf1 = new TGHorizontalFrame(fMain);
38 
39  //Add text Entry
40  fTextEntry = new TGTextEntry(hf1, default_value);
41  fTextEntry->Resize(70, 22);
42  fTextEntry->Connect("ReturnPressed()", "KVTextDialog", this, "ReadAnswer()");
43  hf1->AddFrame(fTextEntry, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5));
44 
45  l = new TGLabel(hf1, unit);
46  hf1->AddFrame(l, new TGLayoutHints(kLHintsTop | kLHintsRight, 5, 5, 5, 0));
47 
48  fMain->AddFrame(hf1, new TGLayoutHints(kLHintsTop | kLHintsCenterX, 5, 5, 5, 5));
49 
50  fMain->SetWindowName("KVTextDialog");
51  fMain->SetIconName("KVTextDialog");
52 
53  //--- create the OK, Apply and Cancel buttons
54 
55  UInt_t nb = 0, width = 0, height = 0;
56 
57  TGHorizontalFrame* hf =
58  new TGHorizontalFrame(fMain, 60, 20, kFixedWidth);
59  TGLayoutHints* l1 =
60  new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 5, 5, 0, 0);
61 
62  fOKBut = new TGTextButton(hf, "&OK", 1);
63  hf->AddFrame(fOKBut, l1);
64  height = fOKBut->GetDefaultHeight();
65  width = TMath::Max(width, fOKBut->GetDefaultWidth());
66  ++nb;
67  fOKBut->Connect("Clicked()", "KVTextDialog", this, "ReadAnswer()");
68  fOKBut->Connect("Clicked()", "KVTextDialog", this, "DoClose()");
69  fTextEntry->Connect("ReturnPressed()", "TGTextButton", fOKBut, "Clicked()");
70 
71  fCancelBut = new TGTextButton(hf, "&Cancel", 3);
72  hf->AddFrame(fCancelBut, l1);
73  height = fCancelBut->GetDefaultHeight();
74  width = TMath::Max(width, fCancelBut->GetDefaultWidth());
75  ++nb;
76  fCancelBut->Connect("Clicked()", "KVTextDialog", this, "DoClose()");
77 
78  // place buttons at the bottom
79  l1 = new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5);
80 
81  fMain->AddFrame(hf, l1);
82 
83  // keep the buttons centered and with the same width
84  hf->Resize((width + 20) * nb, height);
85 
86  // map all widgets and calculate size of dialog
87  fMain->MapSubwindows();
88 
89  width = fMain->GetDefaultWidth();
90  height = fMain->GetDefaultHeight();
91 
92  fMain->Resize(width, height);
93 
94  // position relative to the parent's window
95  fMain->CenterOnParent();
96 
97  // make the message box non-resizable
98  fMain->SetWMSize(width, height);
99  fMain->SetWMSizeHints(width, height, width, height, 0, 0);
100 
101  fMain->SetMWMHints(kMWMDecorAll | kMWMDecorResizeH | kMWMDecorMaximize |
105 
106  fMain->CenterOnParent();
107 
108  fMain->MapWindow();
109  gClient->WaitFor(fMain);
110 }
111 
112 
113 
116 
118 {
119  // Destructor
120  if (fMain) {
121  delete fMain;
122  fMain = 0;
123  }
124 }
125 
126 
127 
129 
131 {
132  TTimer::SingleShot(150, "KVTextDialog", this, "CloseWindow()");
133 
134 }
135 
136 
137 
138 
140 
142 {
143  delete this;
144 }
145 
146 
147 
151 
153 {
154  //Read text from drop down list and store in "answer" TString.
155  //Set "ok" Bool_t flag to kTRUE
156  *fAnswer = fTextEntry->GetText();
157  *fOK = kTRUE;
158 }
159 
160 
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
kLHintsRight
kLHintsLeft
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
virtual ~KVTextDialog()
Destructor.
void CloseWindow()
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)