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 topView->SetHighUIColor(B_PANEL_TEXT_COLOR); 38 AddChild(topView); 39 40 BRect bounds(Bounds()); 41 bounds.InsetBy(10.0, 10.0); 42 43 BBox *customBox = new BBox(bounds, "customBox", B_FOLLOW_NONE); 44 topView->AddChild(customBox); 45 customBox->SetLabel(B_TRANSLATE("Unlock screen saver")); 46 47 bounds.top += 10.0; 48 fPassword = new BTextControl(bounds, "password", 49 B_TRANSLATE("Enter password:"), "VeryLongPasswordPossible", 50 NULL, B_FOLLOW_NONE); 51 customBox->AddChild(fPassword); 52 fPassword->MakeFocus(true); 53 fPassword->ResizeToPreferred(); 54 fPassword->TextView()->HideTyping(true); 55 fPassword->SetDivider(be_plain_font->StringWidth( 56 B_TRANSLATE_NOCOLLECT("Enter password:")) + 5.0); 57 58 BButton* button = new BButton(BRect(), "unlock", B_TRANSLATE("Unlock"), 59 new BMessage(kMsgUnlock), B_FOLLOW_NONE); 60 customBox->AddChild(button); 61 button->MakeDefault(true); 62 button->ResizeToPreferred(); 63 button->SetTarget(NULL, be_app); 64 65 BRect frame = fPassword->Frame(); 66 button->MoveTo(frame.right - button->Bounds().Width(), frame.bottom + 10.0); 67 customBox->ResizeTo(frame.right + 10.0, button->Frame().bottom + 10.0); 68 69 frame = customBox->Frame(); 70 ResizeTo(frame.right + 10.0, frame.bottom + 10.0); 71 72 BScreen screen(this); 73 MoveTo(screen.Frame().left + (screen.Frame().Width() - Bounds().Width()) / 2, 74 screen.Frame().top + (screen.Frame().Height() - Bounds().Height()) / 2); 75 } 76 77 78 void 79 PasswordWindow::SetPassword(const char* text) 80 { 81 if (Lock()) { 82 fPassword->SetText(text); 83 fPassword->MakeFocus(true); 84 Unlock(); 85 } 86 } 87