Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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/** \class TGPasswdDialog
14 \ingroup guiwidgets
15
16Graphic dialog to enter passwords
17
18Usage:
19
20```
21{
22 // Buffer for the passwd
23 char pwdbuf[128]
24
25 Open the dialog box
26 TGPasswdDialog dialog("My prompt", pwdbuf, 128);
27
28 // Wait until the user is done
29 while (gROOT->IsInterrupted())
30 gSystem->DispatchOneEvent(kFALSE);
31
32 // Password is now in pwdbuf
33 ...
34
35}
36```
37
38*/
39
40
41#include "TGPasswdDialog.h"
42
43#include "TError.h"
44#include "TGFrame.h"
45#include "TGButton.h"
46#include "TGLabel.h"
47#include "TGTextEntry.h"
48#include "TGTextBuffer.h"
49#include "TGString.h"
50#include "TROOT.h"
51#include "TVirtualX.h"
52
53
54
55////////////////////////////////////////////////////////////////////////////////
56/// Create an editor in a dialog.
57
60{
63
64 const TGWindow *mainw = gClient->GetRoot();
66 fDialog->Connect("CloseWindow()", "TGPasswdDialog", this, "CloseWindow()");
67
68 // Prompt
70 new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 5, 5, 10, 5));
71
72 // Passwd
73 fPasswdText = new TGTextBuffer(40);
78 fPasswd->Connect("ReturnPressed()", "TGPasswdDialog", this, "ReturnPressed()");
79
82 5, 5, 5, 5));
83 // Ok button
84 fOk = new TGTextButton(fDialog, " &Ok ");
85 fOk->Connect("Clicked()", "TGPasswdDialog", this, "ReturnPressed()");
87 // set window title and icon name
88 fDialog->SetWindowName("Password dialog");
89 fDialog->SetIconName("Password dialog");
90
92
95
97
99 // position relative to the parent window (which is the root window)
101 int ax, ay;
102 Int_t mw = ((TGFrame *) mainw)->GetWidth();
103 Int_t mh = ((TGFrame *) mainw)->GetHeight();
104
105 gVirtualX->TranslateCoordinates(mainw->GetId(), mainw->GetId(),
106 (mw - width) >> 1, (mh - height) >> 1, ax, ay, wdum);
107 fDialog->Move(ax, ay);
109
110 // make the message box non-resizable
113
114 // Now we wait for the user
115 gROOT->SetInterrupt(kTRUE);
116
118}
119
120////////////////////////////////////////////////////////////////////////////////
121/// Delete log window.
122
124{
125 DoClose();
126 delete fDialog;
127}
128
129////////////////////////////////////////////////////////////////////////////////
130/// Handle close button.
131
136
137////////////////////////////////////////////////////////////////////////////////
138/// Called when closed via window manager action.
139
141{
142 delete this;
143}
144
145////////////////////////////////////////////////////////////////////////////////
146/// Handle return
147
149{
150 if (fPwdBuf) {
152 len = (len < (fPwdLenMax - 1)) ? len : fPwdLenMax - 1;
154 fPwdBuf[len] = 0;
156 } else
157 Error("ReturnPressed", "passwd buffer undefined");
158
159 // We are done
160 gROOT->SetInterrupt(kFALSE);
161
162 // Close window
164}
Handle_t Window_t
Window handle.
Definition GuiTypes.h:29
#define h(i)
Definition RSha256.hxx:106
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
#define gClient
Definition TGClient.h:157
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsCenterY
Definition TGLayout.h:28
@ kLHintsCenterX
Definition TGLayout.h:25
@ kLHintsBottom
Definition TGLayout.h:29
@ kLHintsExpandX
Definition TGLayout.h:30
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
#define gROOT
Definition TROOT.h:411
#define gVirtualX
Definition TVirtualX.h:337
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1109
UInt_t GetDefaultWidth() const override
Definition TGFrame.h:314
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1156
UInt_t GetDefaultHeight() const override
Definition TGFrame.h:316
A subclasses of TGWindow, and is used as base class for some simple widgets (buttons,...
Definition TGFrame.h:80
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:597
virtual UInt_t GetDefaultHeight() const
Definition TGFrame.h:193
void MapWindow() override
map window
Definition TGFrame.h:206
void Move(Int_t x, Int_t y) override
Move frame.
Definition TGFrame.cxx:585
void UnmapWindow() override
unmap window
Definition TGFrame.h:208
This class handles GUI labels.
Definition TGLabel.h:24
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
virtual void SendCloseMessage()
Send close message to self.
Definition TGFrame.cxx:1736
void SetIconName(const char *name)
Set window icon name. This is typically done via the window manager.
Definition TGFrame.cxx:1793
void SetWMSize(UInt_t w, UInt_t h)
Give the window manager a window size hint.
Definition TGFrame.cxx:1885
void SetWMPosition(Int_t x, Int_t y)
Give the window manager a window position hint.
Definition TGFrame.cxx:1873
void SetWindowName(const char *name=nullptr) override
Set window name. This is typically done via the window manager.
Definition TGFrame.cxx:1780
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:1898
TGTextButton * fOk
Ok button.
void ReturnPressed()
Handle return.
TGTransientFrame * fDialog
main frame of this widget
char * fPwdBuf
buffer where to store the passwd
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
Password TextEntry.
TGTextBuffer * fPasswdText
Passwd Buffer.
virtual ~TGPasswdDialog()
Delete log window.
void CloseWindow()
Called when closed via window manager action.
Int_t fPwdLenMax
passwd buffer length
A text buffer is used in several widgets, like TGTextEntry, TGFileDialog, etc.
const char * GetString() const
Yield an action as soon as it is clicked.
Definition TGButton.h:142
A TGTextEntry is a one line text input widget.
Definition TGTextEntry.h:24
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.
Defines transient windows that typically are used for dialogs windows.
Definition TGFrame.h:500
ROOT GUI Window base class.
Definition TGWindow.h:23
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:865