#include "TGPasswdDialog.h"
#include "TError.h"
#include "TGFrame.h"
#include "TGButton.h"
#include "TGLabel.h"
#include "TGTextEntry.h"
#include "TGTextBuffer.h"
#include "TGString.h"
#include "TROOT.h"
ClassImp(TGPasswdDialog)
TGPasswdDialog::TGPasswdDialog(const char *prompt, char *pwdbuf, Int_t pwdlenmax,
UInt_t w, UInt_t h)
{
fPwdBuf = pwdbuf;
fPwdLenMax = pwdlenmax;
const TGWindow *mainw = gClient->GetRoot();
fDialog = new TGTransientFrame(mainw, mainw, w, h);
fDialog->Connect("CloseWindow()", "TGPasswdDialog", this, "CloseWindow()");
fDialog->AddFrame(new TGLabel(fDialog, prompt),
new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 5, 5, 10, 5));
fPasswdText = new TGTextBuffer(40);
fPasswd = new TGTextEntry(fDialog, fPasswdText);
fPasswd->SetCursorPosition(0);
fPasswd->Resize(300, fPasswd->GetDefaultHeight());
fPasswd->SetEchoMode(TGTextEntry::kPassword);
fPasswd->Connect("ReturnPressed()", "TGPasswdDialog", this, "ReturnPressed()");
fDialog->AddFrame(fPasswd, new TGLayoutHints(kLHintsCenterY |
kLHintsLeft | kLHintsExpandX,
5, 5, 5, 5));
fOk = new TGTextButton(fDialog, " &Ok ");
fOk->Connect("Clicked()", "TGPasswdDialog", this, "ReturnPressed()");
fDialog->AddFrame(fOk, new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5));
char title[256] = {0};
sprintf(title, "Password dialog");
fDialog->SetWindowName(title);
fDialog->SetIconName(title);
fDialog->MapSubwindows();
Int_t width = fDialog->GetDefaultWidth();
Int_t height = fDialog->GetDefaultHeight();
fDialog->Resize(width, height);
fPasswd->SetFocus();
Window_t wdum;
int ax, ay;
Int_t mw = ((TGFrame *) mainw)->GetWidth();
Int_t mh = ((TGFrame *) mainw)->GetHeight();
gVirtualX->TranslateCoordinates(mainw->GetId(), mainw->GetId(),
(mw - width) >> 1, (mh - height) >> 1, ax, ay, wdum);
fDialog->Move(ax, ay);
fDialog->SetWMPosition(ax, ay);
fDialog->SetWMSize(width, height);
fDialog->SetWMSizeHints(width, height, width, height, 0, 0);
gROOT->SetInterrupt(kTRUE);
fDialog->MapWindow();
}
TGPasswdDialog::~TGPasswdDialog()
{
DoClose();
delete fDialog;
}
void TGPasswdDialog::DoClose()
{
fDialog->SendCloseMessage();
}
void TGPasswdDialog::CloseWindow()
{
delete this;
}
void TGPasswdDialog::ReturnPressed()
{
if (fPwdBuf) {
Int_t len = strlen(fPasswdText->GetString());
len = (len < (fPwdLenMax - 1)) ? len : fPwdLenMax - 1;
memcpy(fPwdBuf, fPasswdText->GetString(), len);
fPwdBuf[len] = 0;
fPasswdText->Clear();
} else
Error("ReturnPressed", "passwd buffer undefined");
gROOT->SetInterrupt(kFALSE);
fDialog->UnmapWindow();
}
Last change: Wed Jun 25 08:42:20 2008
Last generated: 2008-06-25 08:42
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.