xref: /haiku/src/bin/screen_blanker/PasswordWindow.cpp (revision 1d9d47fc72028bb71b5f232a877231e59cfe2438)
1 /*
2  * Copyright 2003-2006, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Michael Phipps
7  *		Jérôme Duval, jerome.duval@free.fr
8  */
9 
10 
11 #include "PasswordWindow.h"
12 
13 #include <Application.h>
14 #include <Box.h>
15 #include <Button.h>
16 #include <Screen.h>
17 #include <StringView.h>
18 
19 
20 PasswordWindow::PasswordWindow()
21 	: BWindow(BRect(100, 100, 400, 230), "Enter Password", B_NO_BORDER_WINDOW_LOOK,
22 		B_FLOATING_ALL_WINDOW_FEEL,
23 		B_NOT_MOVABLE | B_NOT_CLOSABLE |B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE
24 		| B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS ,
25 		B_ALL_WORKSPACES)
26 {
27 	BScreen screen(this);
28 	MoveTo(screen.Frame().left + (screen.Frame().Width() - Bounds().Width()) / 2,
29 		screen.Frame().top + (screen.Frame().Height() - Bounds().Height()) / 2);
30 
31 	BView* topView = new BView(Bounds(), "top", B_FOLLOW_ALL, B_WILL_DRAW);
32 	topView->SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR));
33 	AddChild(topView);
34 
35 	BRect bounds(Bounds());
36 	bounds.InsetBy(5, 5);
37 
38 	BBox* box = new BBox(bounds, NULL, B_FOLLOW_NONE);
39 	box->SetLabel("Unlock screen saver");
40 	topView->AddChild(box);
41 
42 	fPassword = new BTextControl(BRect(10,28,260,47), NULL, "Enter password:",
43 		NULL, B_FOLLOW_NONE);
44 	fPassword->TextView()->HideTyping(true);
45 	fPassword->SetDivider(100);
46 	box->AddChild(fPassword);
47 	fPassword->MakeFocus(true);
48 
49 	BButton* button = new BButton(BRect(160,70,255,85), "fUnlock", "Unlock",
50 		new BMessage(kMsgUnlock), B_FOLLOW_NONE);
51 	button->SetTarget(NULL, be_app);
52 	box->AddChild(button);
53 	button->MakeDefault(true);
54 }
55 
56 
57 void
58 PasswordWindow::SetPassword(const char* text)
59 {
60 	if (Lock()) {
61 		fPassword->SetText(text);
62 		fPassword->MakeFocus(true);
63 		Unlock();
64 	}
65 }
66