#include "TGInputDialog.h"
#include "TGButton.h"
#include "TGLabel.h"
#include "TGTextEntry.h"
ClassImp(TGInputDialog)
TGInputDialog::TGInputDialog(const TGWindow *p, const TGWindow *main,
const char *prompt, const char *defval,
char *retstr, UInt_t options) :
TGTransientFrame(p, main, 10, 10, options)
{
if (!p && !main) {
MakeZombie();
return;
}
SetCleanup(kDeepCleanup);
fLabel = new TGLabel(this, prompt?prompt:"Introduce value:");
TGTextBuffer *tbuf = new TGTextBuffer(256);
tbuf->AddText(0, defval?defval:"");
fTE = new TGTextEntry(this, tbuf);
fTE->Resize(260, fTE->GetDefaultHeight());
AddFrame(fLabel, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 0));
AddFrame(fTE, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5));
TGHorizontalFrame *hf = new TGHorizontalFrame(this, 60, 20, kFixedWidth);
hf->SetCleanup(kDeepCleanup);
UInt_t width = 0, height = 0;
fOk = new TGTextButton(hf, "&Ok", 1);
fOk->Associate(this);
hf->AddFrame(fOk, new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 5, 5, 0, 0));
height = fOk->GetDefaultHeight();
width = TMath::Max(width, fOk->GetDefaultWidth());
fCancel = new TGTextButton(hf, "&Cancel", 2);
fCancel->Associate(this);
hf->AddFrame(fCancel, new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 5, 5, 0, 0));
height = fCancel->GetDefaultHeight();
width = TMath::Max(width, fCancel->GetDefaultWidth());
AddFrame(hf, new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5));
hf->Resize((width + 20) * 2, height);
SetWindowName("Get Input");
MapSubwindows();
width = GetDefaultWidth();
height = GetDefaultHeight();
Resize(width, height);
CenterOnParent();
SetWMSize(width, height);
SetWMSizeHints(width, height, width, height, 0, 0);
SetMWMHints(kMWMDecorAll | kMWMDecorResizeH | kMWMDecorMaximize |
kMWMDecorMinimize | kMWMDecorMenu,
kMWMFuncAll | kMWMFuncResize | kMWMFuncMaximize |
kMWMFuncMinimize,
kMWMInputModeless);
MapWindow();
fTE->SetFocus();
if (retstr == 0)
retstr = new char[256];
fRetStr = retstr;
gClient->WaitFor(this);
}
TGInputDialog::~TGInputDialog()
{
Cleanup();
}
Bool_t TGInputDialog::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
{
switch (GET_MSG(msg)) {
case kC_COMMAND:
switch (GET_SUBMSG(msg)) {
case kCM_BUTTON:
switch (parm1) {
case 1:
strcpy(fRetStr, fTE->GetBuffer()->GetString());
delete this;
break;
case 2:
fRetStr[0] = 0;
delete this;
break;
}
default:
break;
}
break;
case kC_TEXTENTRY:
switch (GET_SUBMSG(msg)) {
case kTE_ENTER:
strcpy(fRetStr, fTE->GetBuffer()->GetString());
delete this;
break;
default:
break;
}
break;
default:
break;
}
return kTRUE;
}