00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "TGPasswdDialog.h"
00040
00041 #include "TError.h"
00042 #include "TGFrame.h"
00043 #include "TGButton.h"
00044 #include "TGLabel.h"
00045 #include "TGTextEntry.h"
00046 #include "TGTextBuffer.h"
00047 #include "TGString.h"
00048 #include "TROOT.h"
00049
00050
00051 ClassImp(TGPasswdDialog)
00052
00053
00054 TGPasswdDialog::TGPasswdDialog(const char *prompt, char *pwdbuf, Int_t pwdlenmax,
00055 UInt_t w, UInt_t h)
00056 {
00057
00058
00059 fPwdBuf = pwdbuf;
00060 fPwdLenMax = pwdlenmax;
00061
00062 const TGWindow *mainw = gClient->GetRoot();
00063 fDialog = new TGTransientFrame(mainw, mainw, w, h);
00064 fDialog->Connect("CloseWindow()", "TGPasswdDialog", this, "CloseWindow()");
00065
00066
00067 fDialog->AddFrame(new TGLabel(fDialog, prompt),
00068 new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 5, 5, 10, 5));
00069
00070
00071 fPasswdText = new TGTextBuffer(40);
00072 fPasswd = new TGTextEntry(fDialog, fPasswdText);
00073 fPasswd->SetCursorPosition(0);
00074 fPasswd->Resize(300, fPasswd->GetDefaultHeight());
00075 fPasswd->SetEchoMode(TGTextEntry::kPassword);
00076 fPasswd->Connect("ReturnPressed()", "TGPasswdDialog", this, "ReturnPressed()");
00077
00078 fDialog->AddFrame(fPasswd, new TGLayoutHints(kLHintsCenterY |
00079 kLHintsLeft | kLHintsExpandX,
00080 5, 5, 5, 5));
00081
00082 fOk = new TGTextButton(fDialog, " &Ok ");
00083 fOk->Connect("Clicked()", "TGPasswdDialog", this, "ReturnPressed()");
00084 fDialog->AddFrame(fOk, new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5));
00085
00086 fDialog->SetWindowName("Password dialog");
00087 fDialog->SetIconName("Password dialog");
00088
00089 fDialog->MapSubwindows();
00090
00091 Int_t width = fDialog->GetDefaultWidth();
00092 Int_t height = fDialog->GetDefaultHeight();
00093
00094 fDialog->Resize(width, height);
00095
00096 fPasswd->SetFocus();
00097
00098 Window_t wdum;
00099 int ax, ay;
00100 Int_t mw = ((TGFrame *) mainw)->GetWidth();
00101 Int_t mh = ((TGFrame *) mainw)->GetHeight();
00102
00103 gVirtualX->TranslateCoordinates(mainw->GetId(), mainw->GetId(),
00104 (mw - width) >> 1, (mh - height) >> 1, ax, ay, wdum);
00105 fDialog->Move(ax, ay);
00106 fDialog->SetWMPosition(ax, ay);
00107
00108
00109 fDialog->SetWMSize(width, height);
00110 fDialog->SetWMSizeHints(width, height, width, height, 0, 0);
00111
00112
00113 gROOT->SetInterrupt(kTRUE);
00114
00115 fDialog->MapWindow();
00116 }
00117
00118
00119 TGPasswdDialog::~TGPasswdDialog()
00120 {
00121
00122
00123 DoClose();
00124 delete fDialog;
00125 }
00126
00127
00128 void TGPasswdDialog::DoClose()
00129 {
00130
00131
00132 fDialog->SendCloseMessage();
00133 }
00134
00135
00136 void TGPasswdDialog::CloseWindow()
00137 {
00138
00139
00140 delete this;
00141 }
00142
00143
00144 void TGPasswdDialog::ReturnPressed()
00145 {
00146
00147
00148 if (fPwdBuf) {
00149 Int_t len = strlen(fPasswdText->GetString());
00150 len = (len < (fPwdLenMax - 1)) ? len : fPwdLenMax - 1;
00151 memcpy(fPwdBuf, fPasswdText->GetString(), len);
00152 fPwdBuf[len] = 0;
00153 fPasswdText->Clear();
00154 } else
00155 Error("ReturnPressed", "passwd buffer undefined");
00156
00157
00158 gROOT->SetInterrupt(kFALSE);
00159
00160
00161 fDialog->UnmapWindow();
00162 }