KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVTextDialog.cpp
Go to the documentation of this file.
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 
14 
16 
17 
18 
20 KVTextDialog::KVTextDialog(const TGWindow* main, const Char_t* question, const Char_t* default_value, TString* chosen, Bool_t* ok, const char* unit)
21 {
22  fMain = new TGTransientFrame(gClient->GetDefaultRoot(), main, 200, 100);
23  fMain->CenterOnParent();
24  fMain->Connect("CloseWindow()", "KVDropDownDialog", this, "DoClose()");
25  fMain->DontCallClose(); // to avoid double deletions.
26  // use hierarchical cleaning
27  fMain->SetCleanup(kDeepCleanup);
28 
29  fAnswer = chosen;
30  fOK = ok;
31  *fOK = kFALSE; //initialise flag
32 
33  // Add a label
34  TGLabel* l = new TGLabel(fMain, question);
35  fMain->AddFrame(l, new TGLayoutHints(kLHintsTop | kLHintsCenterX, 5, 5, 5, 0));
36  TGHorizontalFrame* hf1 = new TGHorizontalFrame(fMain);
37 
38  //Add text Entry
39  fTextEntry = new TGTextEntry(hf1, default_value);
40  fTextEntry->Resize(70, 22);
41  fTextEntry->Connect("ReturnPressed()", "KVTextDialog", this, "ReadAnswer()");
42  hf1->AddFrame(fTextEntry, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5));
43 
44  l = new TGLabel(hf1, unit);
45  hf1->AddFrame(l, new TGLayoutHints(kLHintsTop | kLHintsRight, 5, 5, 5, 0));
46 
47  fMain->AddFrame(hf1, new TGLayoutHints(kLHintsTop | kLHintsCenterX, 5, 5, 5, 5));
48 
49  fMain->SetWindowName("KVTextDialog");
50  fMain->SetIconName("KVTextDialog");
51 
52  //--- create the OK, Apply and Cancel buttons
53 
54  UInt_t nb = 0, width = 0, height = 0;
55 
56  TGHorizontalFrame* hf =
57  new TGHorizontalFrame(fMain, 60, 20, kFixedWidth);
58  TGLayoutHints* l1 =
59  new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 5, 5, 0, 0);
60 
61  fOKBut = new TGTextButton(hf, "&OK", 1);
62  hf->AddFrame(fOKBut, l1);
63  height = fOKBut->GetDefaultHeight();
64  width = TMath::Max(width, fOKBut->GetDefaultWidth());
65  ++nb;
66  fOKBut->Connect("Clicked()", "KVTextDialog", this, "ReadAnswer()");
67  fOKBut->Connect("Clicked()", "KVTextDialog", this, "DoClose()");
68  fTextEntry->Connect("ReturnPressed()", "TGTextButton", fOKBut, "Clicked()");
69 
70  fCancelBut = new TGTextButton(hf, "&Cancel", 3);
71  hf->AddFrame(fCancelBut, l1);
72  height = fCancelBut->GetDefaultHeight();
73  width = TMath::Max(width, fCancelBut->GetDefaultWidth());
74  ++nb;
75  fCancelBut->Connect("Clicked()", "KVTextDialog", this, "DoClose()");
76 
77  // place buttons at the bottom
78  l1 = new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5);
79 
80  fMain->AddFrame(hf, l1);
81 
82  // keep the buttons centered and with the same width
83  hf->Resize((width + 20) * nb, height);
84 
85  // map all widgets and calculate size of dialog
86  fMain->MapSubwindows();
87 
88  width = fMain->GetDefaultWidth();
89  height = fMain->GetDefaultHeight();
90 
91  fMain->Resize(width, height);
92 
93  // position relative to the parent's window
94  fMain->CenterOnParent();
95 
96  // make the message box non-resizable
97  fMain->SetWMSize(width, height);
98  fMain->SetWMSizeHints(width, height, width, height, 0, 0);
99 
100  fMain->SetMWMHints(kMWMDecorAll | kMWMDecorResizeH | kMWMDecorMaximize |
104 
105  fMain->CenterOnParent();
106 
107  fMain->MapWindow();
108  gClient->WaitFor(fMain);
109 }
110 
111 
112 
115 
117 {
118  // Destructor
119  if (fMain) {
120  delete fMain;
121  fMain = 0;
122  }
123 }
124 
125 
126 
128 
130 {
131  TTimer::SingleShot(150, "KVTextDialog", this, "CloseWindow()");
132 
133 }
134 
135 
136 
137 
139 
141 {
142  delete this;
143 }
144 
145 
146 
150 
152 {
153  //Read text from drop down list and store in "answer" TString.
154  //Set "ok" Bool_t flag to kTRUE
155  *fAnswer = fTextEntry->GetText();
156  *fOK = kTRUE;
157 }
158 
159 
160 
unsigned int UInt_t
kFixedWidth
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
char Char_t
const Bool_t kFALSE
bool Bool_t
const Bool_t kTRUE
include TDocParser_001 C image html pict1_TDocParser_001 png width
#define gClient
kMWMDecorResizeH
kMWMFuncAll
kMWMFuncResize
kMWMDecorMaximize
kMWMDecorMinimize
kMWMDecorMenu
kMWMDecorAll
kMWMFuncMaximize
kMWMInputModeless
kMWMFuncMinimize
kDeepCleanup
kLHintsRight
kLHintsLeft
kLHintsCenterY
kLHintsCenterX
kLHintsBottom
kLHintsTop
kLHintsExpandX
virtual ~KVTextDialog()
Destructor.
TString * fAnswer
the answer to the question
Definition: KVTextDialog.h:23
TGTransientFrame * fMain
Definition: KVTextDialog.h:22
void CloseWindow()
Bool_t * fOK
set to kTRUE if OK button is pressed
Definition: KVTextDialog.h:27
TGTextEntry * fTextEntry
drop down list
Definition: KVTextDialog.h:24
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
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)
auto * l