btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / bin / screen_blanker / PasswordWindow.cpp
blobb69cb39b1b0df36ebd846a6606a0ef04e840e467
1 /*
2 * Copyright 2003-2009, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Michael Phipps
7 * Jérôme Duval, jerome.duval@free.fr
8 * Julun <host.haiku@gmx.de>
9 */
12 #include "PasswordWindow.h"
14 #include <Application.h>
15 #include <Box.h>
16 #include <Button.h>
17 #include <Catalog.h>
18 #include <Screen.h>
20 #include <WindowPrivate.h>
23 #undef B_TRANSLATION_CONTEXT
24 #define B_TRANSLATION_CONTEXT "Screensaver password dialog"
27 PasswordWindow::PasswordWindow()
29 BWindow(BRect(100, 100, 400, 230), "Enter password",
30 B_NO_BORDER_WINDOW_LOOK, kPasswordWindowFeel
31 /* TODO: B_MODAL_APP_WINDOW_FEEL should also behave correctly */,
32 B_NOT_MOVABLE | B_NOT_CLOSABLE | B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE
33 | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS, B_ALL_WORKSPACES)
35 BView* topView = new BView(Bounds(), "topView", B_FOLLOW_ALL, B_WILL_DRAW);
36 topView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
37 AddChild(topView);
39 BRect bounds(Bounds());
40 bounds.InsetBy(10.0, 10.0);
42 BBox *customBox = new BBox(bounds, "customBox", B_FOLLOW_NONE);
43 topView->AddChild(customBox);
44 customBox->SetLabel(B_TRANSLATE("Unlock screen saver"));
46 bounds.top += 10.0;
47 fPassword = new BTextControl(bounds, "password",
48 B_TRANSLATE("Enter password:"), "VeryLongPasswordPossible",
49 B_FOLLOW_NONE);
50 customBox->AddChild(fPassword);
51 fPassword->MakeFocus(true);
52 fPassword->ResizeToPreferred();
53 fPassword->TextView()->HideTyping(true);
54 fPassword->SetDivider(be_plain_font->StringWidth(
55 B_TRANSLATE_NOCOLLECT("Enter password:")) + 5.0);
57 BButton* button = new BButton(BRect(), "unlock", B_TRANSLATE("Unlock"),
58 new BMessage(kMsgUnlock), B_FOLLOW_NONE);
59 customBox->AddChild(button);
60 button->MakeDefault(true);
61 button->ResizeToPreferred();
62 button->SetTarget(NULL, be_app);
64 BRect frame = fPassword->Frame();
65 button->MoveTo(frame.right - button->Bounds().Width(), frame.bottom + 10.0);
66 customBox->ResizeTo(frame.right + 10.0, button->Frame().bottom + 10.0);
68 frame = customBox->Frame();
69 ResizeTo(frame.right + 10.0, frame.bottom + 10.0);
71 BScreen screen(this);
72 MoveTo(screen.Frame().left + (screen.Frame().Width() - Bounds().Width()) / 2,
73 screen.Frame().top + (screen.Frame().Height() - Bounds().Height()) / 2);
77 void
78 PasswordWindow::SetPassword(const char* text)
80 if (Lock()) {
81 fPassword->SetText(text);
82 fPassword->MakeFocus(true);
83 Unlock();