1 /* 2 * Copyright 2003-2008, Haiku, Inc. All Rights Reserved. 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 * Julun <host.haiku@gmx.de> 9 */ 10 11 12 #include "PasswordWindow.h" 13 14 #include <Application.h> 15 #include <Box.h> 16 #include <Button.h> 17 #include <Screen.h> 18 19 #include <WindowPrivate.h> 20 21 22 PasswordWindow::PasswordWindow() 23 : BWindow(BRect(100, 100, 400, 230), "Enter Password", 24 B_NO_BORDER_WINDOW_LOOK, kPasswordWindowFeel 25 /* TODO: B_MODAL_APP_WINDOW_FEEL should also behave correctly */, 26 B_NOT_MOVABLE | B_NOT_CLOSABLE | B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE 27 | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS, B_ALL_WORKSPACES) 28 { 29 BView* topView = new BView(Bounds(), "topView", B_FOLLOW_ALL, B_WILL_DRAW); 30 topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 31 AddChild(topView); 32 33 BRect bounds(Bounds()); 34 bounds.InsetBy(10.0, 10.0); 35 36 BBox *customBox = new BBox(bounds, "customBox", B_FOLLOW_NONE); 37 topView->AddChild(customBox); 38 customBox->SetLabel("Unlock screen saver"); 39 40 bounds.top += 10.0; 41 fPassword = new BTextControl(bounds, "password", "Enter password:", 42 "VeryLongPasswordPossible", B_FOLLOW_NONE); 43 customBox->AddChild(fPassword); 44 fPassword->MakeFocus(true); 45 fPassword->ResizeToPreferred(); 46 fPassword->TextView()->HideTyping(true); 47 fPassword->SetDivider(be_plain_font->StringWidth("Enter password:") + 5.0); 48 49 BButton* button = new BButton(BRect(), "unlock", "Unlock", 50 new BMessage(kMsgUnlock), B_FOLLOW_NONE); 51 customBox->AddChild(button); 52 button->MakeDefault(true); 53 button->ResizeToPreferred(); 54 button->SetTarget(NULL, be_app); 55 56 BRect frame = fPassword->Frame(); 57 button->MoveTo(frame.right - button->Bounds().Width(), frame.bottom + 10.0); 58 customBox->ResizeTo(frame.right + 10.0, button->Frame().bottom + 10.0); 59 60 frame = customBox->Frame(); 61 ResizeTo(frame.right + 10.0, frame.bottom + 10.0); 62 63 BScreen screen(this); 64 MoveTo(screen.Frame().left + (screen.Frame().Width() - Bounds().Width()) / 2, 65 screen.Frame().top + (screen.Frame().Height() - Bounds().Height()) / 2); 66 } 67 68 69 void 70 PasswordWindow::SetPassword(const char* text) 71 { 72 if (Lock()) { 73 fPassword->SetText(text); 74 fPassword->MakeFocus(true); 75 Unlock(); 76 } 77 } 78