xref: /haiku/src/bin/screen_blanker/PasswordWindow.cpp (revision baf30547f7d246394209acabd6e94c38683eeda3)
1bef4185eSJérôme Duval /*
29563f44bSStephan 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>
17c3cd5321SJonas Sundström #include <Catalog.h>
18bef4185eSJérôme Duval #include <Screen.h>
19af55bae2SAxel Dörfler 
204a1b9897SAxel Dörfler #include <WindowPrivate.h>
214a1b9897SAxel Dörfler 
22af55bae2SAxel Dörfler 
23546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT
24546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "Screensaver password dialog"
25c3cd5321SJonas Sundström 
26c3cd5321SJonas Sundström 
PasswordWindow()27af55bae2SAxel Dörfler PasswordWindow::PasswordWindow()
28c3cd5321SJonas Sundström 	:
29c3cd5321SJonas Sundström 	BWindow(BRect(100, 100, 400, 230), "Enter password",
3089b1afd1SAxel Dörfler 		B_NO_BORDER_WINDOW_LOOK, kPasswordWindowFeel
3189b1afd1SAxel Dörfler 			/* TODO: B_MODAL_APP_WINDOW_FEEL should also behave correctly */,
32af55bae2SAxel Dörfler 		B_NOT_MOVABLE | B_NOT_CLOSABLE | B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE
3313ab8074SKarsten Heimrich 		| B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS, B_ALL_WORKSPACES)
34af55bae2SAxel Dörfler {
3513ab8074SKarsten Heimrich 	BView* topView = new BView(Bounds(), "topView", B_FOLLOW_ALL, B_WILL_DRAW);
36f696e88aSlooncraz 	topView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
37*baf30547SNiklas Poslovski 	topView->SetHighUIColor(B_PANEL_TEXT_COLOR);
38af55bae2SAxel Dörfler 	AddChild(topView);
39af55bae2SAxel Dörfler 
40af55bae2SAxel Dörfler 	BRect bounds(Bounds());
4113ab8074SKarsten Heimrich 	bounds.InsetBy(10.0, 10.0);
42af55bae2SAxel Dörfler 
4313ab8074SKarsten Heimrich 	BBox *customBox = new BBox(bounds, "customBox", B_FOLLOW_NONE);
4413ab8074SKarsten Heimrich 	topView->AddChild(customBox);
45c3cd5321SJonas Sundström 	customBox->SetLabel(B_TRANSLATE("Unlock screen saver"));
46af55bae2SAxel Dörfler 
4713ab8074SKarsten Heimrich 	bounds.top += 10.0;
48c3cd5321SJonas Sundström 	fPassword = new BTextControl(bounds, "password",
49c3cd5321SJonas Sundström 		B_TRANSLATE("Enter password:"), "VeryLongPasswordPossible",
503cb84528STrung Nguyen 		NULL, B_FOLLOW_NONE);
5113ab8074SKarsten Heimrich 	customBox->AddChild(fPassword);
52af55bae2SAxel Dörfler 	fPassword->MakeFocus(true);
5313ab8074SKarsten Heimrich 	fPassword->ResizeToPreferred();
5413ab8074SKarsten Heimrich 	fPassword->TextView()->HideTyping(true);
55c3cd5321SJonas Sundström 	fPassword->SetDivider(be_plain_font->StringWidth(
56c3cd5321SJonas Sundström 		B_TRANSLATE_NOCOLLECT("Enter password:")) + 5.0);
57af55bae2SAxel Dörfler 
58c3cd5321SJonas Sundström 	BButton* button = new BButton(BRect(), "unlock", B_TRANSLATE("Unlock"),
59af55bae2SAxel Dörfler 		new BMessage(kMsgUnlock), B_FOLLOW_NONE);
6013ab8074SKarsten Heimrich 	customBox->AddChild(button);
61af55bae2SAxel Dörfler 	button->MakeDefault(true);
6213ab8074SKarsten Heimrich 	button->ResizeToPreferred();
6313ab8074SKarsten Heimrich 	button->SetTarget(NULL, be_app);
6413ab8074SKarsten Heimrich 
6513ab8074SKarsten Heimrich 	BRect frame = fPassword->Frame();
6613ab8074SKarsten Heimrich 	button->MoveTo(frame.right - button->Bounds().Width(), frame.bottom + 10.0);
6713ab8074SKarsten Heimrich 	customBox->ResizeTo(frame.right + 10.0,	button->Frame().bottom + 10.0);
6813ab8074SKarsten Heimrich 
6913ab8074SKarsten Heimrich 	frame = customBox->Frame();
7013ab8074SKarsten Heimrich 	ResizeTo(frame.right + 10.0, frame.bottom + 10.0);
7113ab8074SKarsten Heimrich 
7213ab8074SKarsten Heimrich 	BScreen screen(this);
7313ab8074SKarsten Heimrich 	MoveTo(screen.Frame().left + (screen.Frame().Width() - Bounds().Width()) / 2,
7413ab8074SKarsten Heimrich 		screen.Frame().top + (screen.Frame().Height() - Bounds().Height()) / 2);
75af55bae2SAxel Dörfler }
76bef4185eSJérôme Duval 
77bef4185eSJérôme Duval 
78bef4185eSJérôme Duval void
SetPassword(const char * text)79af55bae2SAxel Dörfler PasswordWindow::SetPassword(const char* text)
80bef4185eSJérôme Duval {
81af55bae2SAxel Dörfler 	if (Lock()) {
82af55bae2SAxel Dörfler 		fPassword->SetText(text);
83cc5b9137SJérôme Duval 		fPassword->MakeFocus(true);
84af55bae2SAxel Dörfler 		Unlock();
85bef4185eSJérôme Duval 	}
86af55bae2SAxel Dörfler }
87