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
55
56////////////////////////////////////////////////////////////////////////////////
57/// Create an editor in a dialog.
58
59TGPasswdDialog::TGPasswdDialog(const char *prompt, char *pwdbuf, Int_t pwdlenmax,
61{
62 fPwdBuf = pwdbuf;
63 fPwdLenMax = pwdlenmax;
64
65 const TGWindow *mainw = gClient->GetRoot();
66 fDialog = new TGTransientFrame(mainw, mainw, w, h);
67 fDialog->Connect("CloseWindow()", "TGPasswdDialog", this, "CloseWindow()");
68
69 // Prompt
70 fDialog->AddFrame(new TGLabel(fDialog, prompt),
71 new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 5, 5, 10, 5));
72
73 // Passwd
74 fPasswdText = new TGTextBuffer(40);
79 fPasswd->Connect("ReturnPressed()", "TGPasswdDialog", this, "ReturnPressed()");
80
83 5, 5, 5, 5));
84 // Ok button
85 fOk = new TGTextButton(fDialog, " &Ok ");
86 fOk->Connect("Clicked()", "TGPasswdDialog", this, "ReturnPressed()");
88 // set window title and icon name
89 fDialog->SetWindowName("Password dialog");
90 fDialog->SetIconName("Password dialog");
91
93
96
98
100 // position relative to the parent window (which is the root window)
101 Window_t wdum;
102 int ax, ay;
103 Int_t mw = ((TGFrame *) mainw)->GetWidth();
104 Int_t mh = ((TGFrame *) mainw)->GetHeight();
105
106 gVirtualX->TranslateCoordinates(mainw->GetId(), mainw->GetId(),
107 (mw - width) >> 1, (mh - height) >> 1, ax, ay, wdum);
108 fDialog->Move(ax, ay);
109 fDialog->SetWMPosition(ax, ay);
110
111 // make the message box non-resizable
114
115 // Now we wait for the user
116 gROOT->SetInterrupt(kTRUE);
117
119}
120
121////////////////////////////////////////////////////////////////////////////////
122/// Delete log window.
123
125{
126 DoClose();
127 delete fDialog;
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// Handle close button.
132
134{
136}
137
138////////////////////////////////////////////////////////////////////////////////
139/// Called when closed via window manager action.
140
142{
143 delete this;
144}
145
146////////////////////////////////////////////////////////////////////////////////
147/// Handle return
148
150{
151 if (fPwdBuf) {
152 Int_t len = strlen(fPasswdText->GetString());
153 len = (len < (fPwdLenMax - 1)) ? len : fPwdLenMax - 1;
154 memcpy(fPwdBuf, fPasswdText->GetString(), len);
155 fPwdBuf[len] = 0;
157 } else
158 Error("ReturnPressed", "passwd buffer undefined");
159
160 // We are done
161 gROOT->SetInterrupt(kFALSE);
162
163 // Close window
165}
Handle_t Window_t
Window handle.
Definition GuiTypes.h:29
#define h(i)
Definition RSha256.hxx:106
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:197
#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:405
#define gVirtualX
Definition TVirtualX.h:338
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
UInt_t GetDefaultWidth() const override
Definition TGFrame.h:312
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1164
UInt_t GetDefaultHeight() const override
Definition TGFrame.h:314
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:605
virtual UInt_t GetDefaultHeight() const
Definition TGFrame.h:191
void MapWindow() override
map window
Definition TGFrame.h:204
void Move(Int_t x, Int_t y) override
Move frame.
Definition TGFrame.cxx:593
void UnmapWindow() override
unmap window
Definition TGFrame.h:206
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:1744
void SetIconName(const char *name)
Set window icon name. This is typically done via the window manager.
Definition TGFrame.cxx:1801
void SetWMSize(UInt_t w, UInt_t h)
Give the window manager a window size hint.
Definition TGFrame.cxx:1893
void SetWMPosition(Int_t x, Int_t y)
Give the window manager a window position hint.
Definition TGFrame.cxx:1881
void SetWindowName(const char *name=nullptr) override
Set window name. This is typically done via the window manager.
Definition TGFrame.cxx:1788
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:1906
Handle_t GetId() const
Definition TGObject.h:41
Graphic dialog to enter passwords.
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:498
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:869