Logo ROOT   6.18/05
Reference Guide
TGPasswdDialog.cxx
Go to the documentation of this file.
1// @(#)root/gui:$Id$
2// Author: G. Ganis 10/10/2005
3
4/*************************************************************************
5 * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12//////////////////////////////////////////////////////////////////////////
13// //
14// TGPasswdDialog //
15// //
16// Graphic dialog to enter passwords //
17// //
18// Usage: //
19// //
20// { //
21// // Buffer for the passwd //
22// char pwdbuf[128] //
23// //
24// Open the dialog box //
25// TGPasswdDialog dialog("My prompt", pwdbuf, 128); //
26// //
27// // Wait until the user is done //
28// while (gROOT->IsInterrupted()) //
29// gSystem->DispatchOneEvent(kFALSE); //
30// //
31// // Password is now in pwdbuf //
32// ... //
33// //
34// } //
35// //
36// //
37//////////////////////////////////////////////////////////////////////////
38
39#include "TGPasswdDialog.h"
40
41#include "TError.h"
42#include "TGFrame.h"
43#include "TGButton.h"
44#include "TGLabel.h"
45#include "TGTextEntry.h"
46#include "TGTextBuffer.h"
47#include "TGString.h"
48#include "TROOT.h"
49
50
52
53////////////////////////////////////////////////////////////////////////////////
54/// Create an editor in a dialog.
55
56TGPasswdDialog::TGPasswdDialog(const char *prompt, char *pwdbuf, Int_t pwdlenmax,
57 UInt_t w, UInt_t h)
58{
59 fPwdBuf = pwdbuf;
60 fPwdLenMax = pwdlenmax;
61
62 const TGWindow *mainw = gClient->GetRoot();
63 fDialog = new TGTransientFrame(mainw, mainw, w, h);
64 fDialog->Connect("CloseWindow()", "TGPasswdDialog", this, "CloseWindow()");
65
66 // Prompt
67 fDialog->AddFrame(new TGLabel(fDialog, prompt),
68 new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 5, 5, 10, 5));
69
70 // Passwd
71 fPasswdText = new TGTextBuffer(40);
76 fPasswd->Connect("ReturnPressed()", "TGPasswdDialog", this, "ReturnPressed()");
77
80 5, 5, 5, 5));
81 // Ok button
82 fOk = new TGTextButton(fDialog, " &Ok ");
83 fOk->Connect("Clicked()", "TGPasswdDialog", this, "ReturnPressed()");
85 // set window title and icon name
86 fDialog->SetWindowName("Password dialog");
87 fDialog->SetIconName("Password dialog");
88
90
92 Int_t height = fDialog->GetDefaultHeight();
93
94 fDialog->Resize(width, height);
95
97 // position relative to the parent window (which is the root window)
98 Window_t wdum;
99 int ax, ay;
100 Int_t mw = ((TGFrame *) mainw)->GetWidth();
101 Int_t mh = ((TGFrame *) mainw)->GetHeight();
102
103 gVirtualX->TranslateCoordinates(mainw->GetId(), mainw->GetId(),
104 (mw - width) >> 1, (mh - height) >> 1, ax, ay, wdum);
105 fDialog->Move(ax, ay);
106 fDialog->SetWMPosition(ax, ay);
107
108 // make the message box non-resizable
109 fDialog->SetWMSize(width, height);
110 fDialog->SetWMSizeHints(width, height, width, height, 0, 0);
111
112 // Now we wait for the user
113 gROOT->SetInterrupt(kTRUE);
114
116}
117
118////////////////////////////////////////////////////////////////////////////////
119/// Delete log window.
120
122{
123 DoClose();
124 delete fDialog;
125}
126
127////////////////////////////////////////////////////////////////////////////////
128/// Handle close button.
129
131{
133}
134
135////////////////////////////////////////////////////////////////////////////////
136/// Called when closed via window manager action.
137
139{
140 delete this;
141}
142
143////////////////////////////////////////////////////////////////////////////////
144/// Handle return
145
147{
148 if (fPwdBuf) {
149 Int_t len = strlen(fPasswdText->GetString());
150 len = (len < (fPwdLenMax - 1)) ? len : fPwdLenMax - 1;
151 memcpy(fPwdBuf, fPasswdText->GetString(), len);
152 fPwdBuf[len] = 0;
154 } else
155 Error("ReturnPressed", "passwd buffer undefined");
156
157 // We are done
158 gROOT->SetInterrupt(kFALSE);
159
160 // Close window
162}
Handle_t Window_t
Definition: GuiTypes.h:28
#define h(i)
Definition: RSha256.hxx:106
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
void Error(const char *location, const char *msgfmt,...)
#define gClient
Definition: TGClient.h:166
@ kLHintsLeft
Definition: TGLayout.h:31
@ kLHintsCenterY
Definition: TGLayout.h:35
@ kLHintsCenterX
Definition: TGLayout.h:32
@ kLHintsBottom
Definition: TGLayout.h:36
@ kLHintsExpandX
Definition: TGLayout.h:37
#define gROOT
Definition: TROOT.h:414
#define gVirtualX
Definition: TVirtualX.h:345
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
virtual UInt_t GetDefaultWidth() const
Definition: TGFrame.h:371
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1146
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:373
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:238
virtual void Move(Int_t x, Int_t y)
Move frame.
Definition: TGFrame.cxx:575
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
virtual void MapWindow()
Definition: TGFrame.h:251
virtual void UnmapWindow()
Definition: TGFrame.h:253
virtual void SendCloseMessage()
Send close message to self.
Definition: TGFrame.cxx:1702
void SetIconName(const char *name)
Set window icon name. This is typically done via the window manager.
Definition: TGFrame.cxx:1759
void SetWMSize(UInt_t w, UInt_t h)
Give the window manager a window size hint.
Definition: TGFrame.cxx:1849
void SetWMPosition(Int_t x, Int_t y)
Give the window manager a window position hint.
Definition: TGFrame.cxx:1837
void SetWMSizeHints(UInt_t wmin, UInt_t hmin, UInt_t wmax, UInt_t hmax, UInt_t winc, UInt_t hinc)
Give the window manager minimum and maximum size hints.
Definition: TGFrame.cxx:1862
void SetWindowName(const char *name=0)
Set window name. This is typically done via the window manager.
Definition: TGFrame.cxx:1746
Handle_t GetId() const
Definition: TGObject.h:47
TGTextButton * fOk
void ReturnPressed()
Handle return.
TGTransientFrame * fDialog
void DoClose()
Handle close button.
TGPasswdDialog(const char *prompt, char *pwdbuf, Int_t pwdlenmax, UInt_t w=400, UInt_t h=400)
Create an editor in a dialog.
TGTextEntry * fPasswd
TGTextBuffer * fPasswdText
virtual ~TGPasswdDialog()
Delete log window.
void CloseWindow()
Called when closed via window manager action.
const char * GetString() const
Definition: TGTextBuffer.h:47
void Clear()
Definition: TGTextBuffer.h:52
virtual void SetFocus()
Set focus to this text entry.
virtual void SetEchoMode(EEchoMode mode=kNormal)
The echo modes available are:
virtual void SetCursorPosition(Int_t pos)
Set the cursor position to newPos.
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition: TQObject.cxx:867