KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
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
18
19
20
21
27
29 const Char_t* question, const Char_t* choice_list,
30 const Char_t* default_choice, TString* chosen, Bool_t* ok)
31{
32 // Create the dialog box asking a "question".
33 // Possible answers are in "choice list" (whitespace-separated list).
34 // Default choice (will be visible in combo box when dialog opens) is "default".
35 // The Bool_t variable will be set to kTRUE if "OK" is pressed (kFALSE otherwise)
36 // Optional argument 'tooltip' will be displayed when mouse held over text entry widget
37
38 fMain = new TGTransientFrame(gClient->GetDefaultRoot(), main, 200, 100);
39 fMain->CenterOnParent();
40 fMain->Connect("CloseWindow()", "KVDropDownDialog", this, "DoClose()");
41 fMain->DontCallClose(); // to avoid double deletions.
42 // use hierarchical cleaning
43 fMain->SetCleanup(kDeepCleanup);
44
45 fAnswer = chosen;
46 fOK = ok;
47 *fOK = kFALSE; //initialise flag
48
49 // Add a label
50 TGLabel* l = new TGLabel(fMain, question);
51 fMain->AddFrame(l,
53 0));
54 // Add drop down list
55 fDropDown = new TGComboBox(fMain);
56 // fill with choices
57 KVString choix(choice_list);
58 choix.Begin(" ");
59 int entry_id = 0;
60 int default_id = -1;
61 KVString this_choice;
62 while (! choix.End()) {
63 this_choice = choix.Next(kTRUE);
64 if (this_choice == default_choice) default_id = entry_id;
65 fDropDown->AddEntry(this_choice.Data(), entry_id++);
66 }
67 fDropDown->Resize(260, 22);
68 fMain->AddFrame(fDropDown,
70 5));
71 // display default choice
72 fDropDown->Select(default_id);
73
74 fMain->SetWindowName("KVDropDownDialog");
75 fMain->SetIconName("KVDropDownDialog");
76
77 //--- create the OK, Apply and Cancel buttons
78
79 UInt_t nb = 0, width = 0, height = 0;
80
82 new TGHorizontalFrame(fMain, 60, 20, kFixedWidth);
83 TGLayoutHints* l1 =
85
86 fOKBut = new TGTextButton(hf, "&OK", 1);
87 hf->AddFrame(fOKBut, l1);
88 height = fOKBut->GetDefaultHeight();
89 width = TMath::Max(width, fOKBut->GetDefaultWidth());
90 ++nb;
91 fOKBut->Connect("Clicked()", "KVDropDownDialog", this, "ReadAnswer()");
92 fOKBut->Connect("Clicked()", "KVDropDownDialog", this, "DoClose()");
93
94 fCancelBut = new TGTextButton(hf, "&Cancel", 3);
95 hf->AddFrame(fCancelBut, l1);
96 height = fCancelBut->GetDefaultHeight();
97 width = TMath::Max(width, fCancelBut->GetDefaultWidth());
98 ++nb;
99 fCancelBut->Connect("Clicked()", "KVDropDownDialog", this, "DoClose()");
100
101
102 // place buttons at the bottom
103 l1 = new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5);
104
105 fMain->AddFrame(hf, l1);
106
107 // keep the buttons centered and with the same width
108 hf->Resize((width + 20) * nb, height);
109
110 // map all widgets and calculate size of dialog
111 fMain->MapSubwindows();
112
113 width = fMain->GetDefaultWidth();
114 height = fMain->GetDefaultHeight();
115
116 fMain->Resize(width, height);
117
118 // position relative to the parent's window
119 fMain->CenterOnParent();
120
121 // make the message box non-resizable
122 fMain->SetWMSize(width, height);
123 fMain->SetWMSizeHints(width, height, width, height, 0, 0);
124
125 fMain->SetMWMHints(kMWMDecorAll | kMWMDecorResizeH | kMWMDecorMaximize |
129
130 fMain->CenterOnParent();
131
132 fMain->MapWindow();
133 gClient->WaitFor(fMain);
134}
135
136
137
138
141
143{
144 //Delete all widgets
145
146 if (fMain) {
147 delete fMain;
148 fMain = 0;
149 }
150}
151
152
153
154
156
158{
159 TTimer::SingleShot(150, "KVDropDownDialog", this, "CloseWindow()");
160}
161
162
163
164
166
168{
169 delete this;
170}
171
172
173
177
179{
180 //Read text from drop down list and store in "answer" TString.
181 //Set "ok" Bool_t flag to kTRUE
183 *fOK = kTRUE;
184}
185
186
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.
TGTransientFrame * fMain
TString * fAnswer
the answer to the question
Bool_t * fOK
set to kTRUE if OK button is pressed
virtual ~KVDropDownDialog()
Delete all widgets.
TGComboBox * fDropDown
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()
Double_t Max(Double_t a, Double_t b)
TLine l
ClassImp(TPyArg)