Logo ROOT  
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#include "TVirtualX.h"
50
51
53
54////////////////////////////////////////////////////////////////////////////////
55/// Create an editor in a dialog.
56
57TGPasswdDialog::TGPasswdDialog(const char *prompt, char *pwdbuf, Int_t pwdlenmax,
58 UInt_t w, UInt_t h)
59{
60 fPwdBuf = pwdbuf;
61 fPwdLenMax = pwdlenmax;
62
63 const TGWindow *mainw = gClient->GetRoot();
64 fDialog = new TGTransientFrame(mainw, mainw, w, h);
65 fDialog->Connect("CloseWindow()", "TGPasswdDialog", this, "CloseWindow()");
66
67 // Prompt
68 fDialog->AddFrame(new TGLabel(fDialog, prompt),
69 new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 5, 5, 10, 5));
70
71 // Passwd
72 fPasswdText = new TGTextBuffer(40);
77 fPasswd->Connect("ReturnPressed()", "TGPasswdDialog", this, "ReturnPressed()");
78
81 5, 5, 5, 5));
82 // Ok button
83 fOk = new TGTextButton(fDialog, " &Ok ");
84 fOk->Connect("Clicked()", "TGPasswdDialog", this, "ReturnPressed()");
86 // set window title and icon name
87 fDialog->SetWindowName("Password dialog");
88 fDialog->SetIconName("Password dialog");
89
91
93 Int_t height = fDialog->GetDefaultHeight();
94
95 fDialog->Resize(width, height);
96
98 // position relative to the parent window (which is the root window)
99 Window_t wdum;
100 int ax, ay;
101 Int_t mw = ((TGFrame *) mainw)->GetWidth();
102 Int_t mh = ((TGFrame *) mainw)->GetHeight();
103
104 gVirtualX->TranslateCoordinates(mainw->GetId(), mainw->GetId(),
105 (mw - width) >> 1, (mh - height) >> 1, ax, ay, wdum);
106 fDialog->Move(ax, ay);
107 fDialog->SetWMPosition(ax, ay);
108
109 // make the message box non-resizable
110 fDialog->SetWMSize(width, height);
111 fDialog->SetWMSizeHints(width, height, width, height, 0, 0);
112
113 // Now we wait for the user
114 gROOT->SetInterrupt(kTRUE);
115
117}
118
119////////////////////////////////////////////////////////////////////////////////
120/// Delete log window.
121
123{
124 DoClose();
125 delete fDialog;
126}
127
128////////////////////////////////////////////////////////////////////////////////
129/// Handle close button.
130
132{
134}
135
136////////////////////////////////////////////////////////////////////////////////
137/// Called when closed via window manager action.
138
140{
141 delete this;
142}
143
144////////////////////////////////////////////////////////////////////////////////
145/// Handle return
146
148{
149 if (fPwdBuf) {
150 Int_t len = strlen(fPasswdText->GetString());
151 len = (len < (fPwdLenMax - 1)) ? len : fPwdLenMax - 1;
152 memcpy(fPwdBuf, fPasswdText->GetString(), len);
153 fPwdBuf[len] = 0;
155 } else
156 Error("ReturnPressed", "passwd buffer undefined");
157
158 // We are done
159 gROOT->SetInterrupt(kFALSE);
160
161 // Close window
163}
Handle_t Window_t
Definition: GuiTypes.h:28
#define h(i)
Definition: RSha256.hxx:106
const Bool_t kFALSE
Definition: RtypesCore.h:90
const Bool_t kTRUE
Definition: RtypesCore.h:89
#define ClassImp(name)
Definition: Rtypes.h:361
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:406
#define gVirtualX
Definition: TVirtualX.h:338
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1101
virtual UInt_t GetDefaultWidth() const
Definition: TGFrame.h:349
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1148
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:351
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:216
virtual void Move(Int_t x, Int_t y)
Move frame.
Definition: TGFrame.cxx:577
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:589
virtual void MapWindow()
map window
Definition: TGFrame.h:229
virtual void UnmapWindow()
unmap window
Definition: TGFrame.h:231
virtual void SendCloseMessage()
Send close message to self.
Definition: TGFrame.cxx:1704
void SetIconName(const char *name)
Set window icon name. This is typically done via the window manager.
Definition: TGFrame.cxx:1761
void SetWMSize(UInt_t w, UInt_t h)
Give the window manager a window size hint.
Definition: TGFrame.cxx:1851
void SetWMPosition(Int_t x, Int_t y)
Give the window manager a window position hint.
Definition: TGFrame.cxx:1839
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:1864
void SetWindowName(const char *name=0)
Set window name. This is typically done via the window manager.
Definition: TGFrame.cxx:1748
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:866