1 /* 2 * Copyright 2003-2009, 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 <Catalog.h> 18 #include <Screen.h> 19 20 #include <WindowPrivate.h> 21 22 23 #undef B_TRANSLATION_CONTEXT 24 #define B_TRANSLATION_CONTEXT "Screensaver password dialog" 25 26 27 PasswordWindow::PasswordWindow() 28 : 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) 34 { 35 BView* topView = new BView(Bounds(), "topView", B_FOLLOW_ALL, B_WILL_DRAW); 36 topView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR); 37 AddChild(topView); 38 39 BRect bounds(Bounds()); 40 bounds.InsetBy(10.0, 10.0); 41 42 BBox *customBox = new BBox(bounds, "customBox", B_FOLLOW_NONE); 43 topView->AddChild(customBox); 44 customBox->SetLabel(B_TRANSLATE("Unlock screen saver")); 45 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); 56 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); 63 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); 67 68 frame = customBox->Frame(); 69 ResizeTo(frame.right + 10.0, frame.bottom + 10.0); 70 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); 74 } 75 76 77 void 78 PasswordWindow::SetPassword(const char* text) 79 { 80 if (Lock()) { 81 fPassword->SetText(text); 82 fPassword->MakeFocus(true); 83 Unlock(); 84 } 85 } 86