KaliVeda
Toolkit for HIC analysis
KVDropDownDialog.cpp
1 /*
2 $Id: KVDropDownDialog.cpp,v 1.2 2009/03/03 14:27:15 franklan Exp $
3 $Revision: 1.2 $
4 $Date: 2009/03/03 14:27:15 $
5 $Author: franklan $
6 */
7 
8 #include "KVDropDownDialog.h"
9 #include "TGFrame.h"
10 #include "KVString.h"
11 #include "TGComboBox.h"
12 #include "TGWindow.h"
13 #include "TGLabel.h"
14 #include "TGButton.h"
15 #include "TTimer.h"
16 #include "TMath.h"
17 
19 
20 
21 
22 
30  const Char_t* question, const Char_t* choice_list,
31  const Char_t* default_choice, TString* chosen, Bool_t* ok)
32 {
33  // Create the dialog box asking a "question".
34  // Possible answers are in "choice list" (whitespace-separated list).
35  // Default choice (will be visible in combo box when dialog opens) is "default".
36  // The Bool_t variable will be set to kTRUE if "OK" is pressed (kFALSE otherwise)
37  // Optional argument 'tooltip' will be displayed when mouse held over text entry widget
38 
39  fMain = new TGTransientFrame(gClient->GetDefaultRoot(), main, 200, 100);
40  fMain->CenterOnParent();
41  fMain->Connect("CloseWindow()", "KVDropDownDialog", this, "DoClose()");
42  fMain->DontCallClose(); // to avoid double deletions.
43  // use hierarchical cleaning
44  fMain->SetCleanup(kDeepCleanup);
45 
46  fAnswer = chosen;
47  fOK = ok;
48  *fOK = kFALSE; //initialise flag
49 
50  // Add a label
51  TGLabel* l = new TGLabel(fMain, question);
52  fMain->AddFrame(l,
54  0));
55  // Add drop down list
56  fDropDown = new TGComboBox(fMain);
57  // fill with choices
58  KVString choix(choice_list);
59  choix.Begin(" ");
60  int entry_id = 0;
61  int default_id = -1;
62  KVString this_choice;
63  while (! choix.End()) {
64  this_choice = choix.Next(kTRUE);
65  if (this_choice == default_choice) default_id = entry_id;
66  fDropDown->AddEntry(this_choice.Data(), entry_id++);
67  }
68  fDropDown->Resize(260, 22);
69  fMain->AddFrame(fDropDown,
70  new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5,
71  5));
72  // display default choice
73  fDropDown->Select(default_id);
74 
75  fMain->SetWindowName("KVDropDownDialog");
76  fMain->SetIconName("KVDropDownDialog");
77 
78  //--- create the OK, Apply and Cancel buttons
79 
80  UInt_t nb = 0, width = 0, height = 0;
81 
82  TGHorizontalFrame* hf =
83  new TGHorizontalFrame(fMain, 60, 20, kFixedWidth);
84  TGLayoutHints* l1 =
85  new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 5, 5, 0, 0);
86 
87  fOKBut = new TGTextButton(hf, "&OK", 1);
88  hf->AddFrame(fOKBut, l1);
89  height = fOKBut->GetDefaultHeight();
90  width = TMath::Max(width, fOKBut->GetDefaultWidth());
91  ++nb;
92  fOKBut->Connect("Clicked()", "KVDropDownDialog", this, "ReadAnswer()");
93  fOKBut->Connect("Clicked()", "KVDropDownDialog", this, "DoClose()");
94 
95  fCancelBut = new TGTextButton(hf, "&Cancel", 3);
96  hf->AddFrame(fCancelBut, l1);
97  height = fCancelBut->GetDefaultHeight();
98  width = TMath::Max(width, fCancelBut->GetDefaultWidth());
99  ++nb;
100  fCancelBut->Connect("Clicked()", "KVDropDownDialog", this, "DoClose()");
101 
102 
103  // place buttons at the bottom
104  l1 = new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5);
105 
106  fMain->AddFrame(hf, l1);
107 
108  // keep the buttons centered and with the same width
109  hf->Resize((width + 20) * nb, height);
110 
111  // map all widgets and calculate size of dialog
112  fMain->MapSubwindows();
113 
114  width = fMain->GetDefaultWidth();
115  height = fMain->GetDefaultHeight();
116 
117  fMain->Resize(width, height);
118 
119  // position relative to the parent's window
120  fMain->CenterOnParent();
121 
122  // make the message box non-resizable
123  fMain->SetWMSize(width, height);
124  fMain->SetWMSizeHints(width, height, width, height, 0, 0);
125 
126  fMain->SetMWMHints(kMWMDecorAll | kMWMDecorResizeH | kMWMDecorMaximize |
130 
131  fMain->CenterOnParent();
132 
133  fMain->MapWindow();
134  gClient->WaitFor(fMain);
135 }
136 
137 
138 
139 
142 
143 KVDropDownDialog::~KVDropDownDialog()
144 {
145  //Delete all widgets
146 
147  if (fMain) {
148  delete fMain;
149  fMain = 0;
150  }
151 }
152 
153 
154 
155 
157 
159 {
160  TTimer::SingleShot(150, "KVDropDownDialog", this, "CloseWindow()");
161 }
162 
163 
164 
165 
167 
169 {
170  delete this;
171 }
172 
173 
174 
178 
180 {
181  //Read text from drop down list and store in "answer" TString.
182  //Set "ok" Bool_t flag to kTRUE
183  *fAnswer = fDropDown->GetSelectedEntry()->GetTitle();
184  *fOK = kTRUE;
185 }
186 
187 
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
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
Ask user to choose between several options in a drop-down list.
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
void Begin(TString delim) const
Definition: KVString.cpp:565
Bool_t End() const
Definition: KVString.cpp:634
KVString Next(Bool_t strip_whitespace=kFALSE) const
Definition: KVString.cpp:695
virtual TGLBEntry * GetSelectedEntry() const
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
virtual void Resize(TGDimension size)
virtual const char * GetTitle() const
const char * Data() const
void Resize(Ssiz_t n)
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)