xref: /haiku/src/bin/screen_blanker/PasswordWindow.cpp (revision 9563f44bfd75799f67201067483694e82b5779b9)
1bef4185eSJérôme Duval /*
2*9563f44bSStephan Aßmus  * Copyright 2003-2009, Haiku, Inc. All rights reserved.
3bef4185eSJérôme Duval  * Distributed under the terms of the MIT License.
4911290f7SJérôme Duval  *
5911290f7SJérôme Duval  * Authors:
6911290f7SJérôme Duval  *		Michael Phipps
77008829bSJérôme Duval  *		Jérôme Duval, jerome.duval@free.fr
813ab8074SKarsten Heimrich  *		Julun <host.haiku@gmx.de>
9bef4185eSJérôme Duval  */
10af55bae2SAxel Dörfler 
11af55bae2SAxel Dörfler 
12af55bae2SAxel Dörfler #include "PasswordWindow.h"
13af55bae2SAxel Dörfler 
14bef4185eSJérôme Duval #include <Application.h>
15af55bae2SAxel Dörfler #include <Box.h>
16af55bae2SAxel Dörfler #include <Button.h>
17bef4185eSJérôme Duval #include <Screen.h>
18af55bae2SAxel Dörfler 
194a1b9897SAxel Dörfler #include <WindowPrivate.h>
204a1b9897SAxel Dörfler 
21af55bae2SAxel Dörfler 
22af55bae2SAxel Dörfler PasswordWindow::PasswordWindow()
23*9563f44bSStephan Aßmus 	: BWindow(BRect(100, 100, 400, 230), "Enter password",
2489b1afd1SAxel Dörfler 		B_NO_BORDER_WINDOW_LOOK, kPasswordWindowFeel
2589b1afd1SAxel Dörfler 			/* TODO: B_MODAL_APP_WINDOW_FEEL should also behave correctly */,
26af55bae2SAxel Dörfler 		B_NOT_MOVABLE | B_NOT_CLOSABLE | B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE
2713ab8074SKarsten Heimrich 		| B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS, B_ALL_WORKSPACES)
28af55bae2SAxel Dörfler {
2913ab8074SKarsten Heimrich 	BView* topView = new BView(Bounds(), "topView", B_FOLLOW_ALL, B_WILL_DRAW);
3013ab8074SKarsten Heimrich 	topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
31af55bae2SAxel Dörfler 	AddChild(topView);
32af55bae2SAxel Dörfler 
33af55bae2SAxel Dörfler 	BRect bounds(Bounds());
3413ab8074SKarsten Heimrich 	bounds.InsetBy(10.0, 10.0);
35af55bae2SAxel Dörfler 
3613ab8074SKarsten Heimrich 	BBox *customBox = new BBox(bounds, "customBox", B_FOLLOW_NONE);
3713ab8074SKarsten Heimrich 	topView->AddChild(customBox);
3813ab8074SKarsten Heimrich 	customBox->SetLabel("Unlock screen saver");
39af55bae2SAxel Dörfler 
4013ab8074SKarsten Heimrich 	bounds.top += 10.0;
4113ab8074SKarsten Heimrich 	fPassword = new BTextControl(bounds, "password", "Enter password:",
4213ab8074SKarsten Heimrich 		"VeryLongPasswordPossible", B_FOLLOW_NONE);
4313ab8074SKarsten Heimrich 	customBox->AddChild(fPassword);
44af55bae2SAxel Dörfler 	fPassword->MakeFocus(true);
4513ab8074SKarsten Heimrich 	fPassword->ResizeToPreferred();
4613ab8074SKarsten Heimrich 	fPassword->TextView()->HideTyping(true);
4713ab8074SKarsten Heimrich 	fPassword->SetDivider(be_plain_font->StringWidth("Enter password:") + 5.0);
48af55bae2SAxel Dörfler 
4913ab8074SKarsten Heimrich 	BButton* button = new BButton(BRect(), "unlock", "Unlock",
50af55bae2SAxel Dörfler 		new BMessage(kMsgUnlock), B_FOLLOW_NONE);
5113ab8074SKarsten Heimrich 	customBox->AddChild(button);
52af55bae2SAxel Dörfler 	button->MakeDefault(true);
5313ab8074SKarsten Heimrich 	button->ResizeToPreferred();
5413ab8074SKarsten Heimrich 	button->SetTarget(NULL, be_app);
5513ab8074SKarsten Heimrich 
5613ab8074SKarsten Heimrich 	BRect frame = fPassword->Frame();
5713ab8074SKarsten Heimrich 	button->MoveTo(frame.right - button->Bounds().Width(), frame.bottom + 10.0);
5813ab8074SKarsten Heimrich 	customBox->ResizeTo(frame.right + 10.0,	button->Frame().bottom + 10.0);
5913ab8074SKarsten Heimrich 
6013ab8074SKarsten Heimrich 	frame = customBox->Frame();
6113ab8074SKarsten Heimrich 	ResizeTo(frame.right + 10.0, frame.bottom + 10.0);
6213ab8074SKarsten Heimrich 
6313ab8074SKarsten Heimrich 	BScreen screen(this);
6413ab8074SKarsten Heimrich 	MoveTo(screen.Frame().left + (screen.Frame().Width() - Bounds().Width()) / 2,
6513ab8074SKarsten Heimrich 		screen.Frame().top + (screen.Frame().Height() - Bounds().Height()) / 2);
66af55bae2SAxel Dörfler }
67bef4185eSJérôme Duval 
68bef4185eSJérôme Duval 
69bef4185eSJérôme Duval void
70af55bae2SAxel Dörfler PasswordWindow::SetPassword(const char* text)
71bef4185eSJérôme Duval {
72af55bae2SAxel Dörfler 	if (Lock()) {
73af55bae2SAxel Dörfler 		fPassword->SetText(text);
74cc5b9137SJérôme Duval 		fPassword->MakeFocus(true);
75af55bae2SAxel Dörfler 		Unlock();
76bef4185eSJérôme Duval 	}
77af55bae2SAxel Dörfler }
78