1 /* 2 * Copyright 2010, Haiku, Inc. All Rights Reserved. 3 * Copyright 2009, Pier Luigi Fiorini. 4 * Distributed under the terms of the MIT License. 5 * 6 * Authors: 7 * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com 8 */ 9 10 #include <Application.h> 11 #include <GroupLayout.h> 12 #include <GroupLayoutBuilder.h> 13 #include <Button.h> 14 15 #include "PrefletWin.h" 16 #include "PrefletView.h" 17 18 #define _T(str) (str) 19 20 const int32 kRevert = '_RVT'; 21 const int32 kSave = '_SAV'; 22 23 24 PrefletWin::PrefletWin() 25 : 26 BWindow(BRect(0, 0, 1, 1), "Notifications", B_TITLED_WINDOW, B_NOT_ZOOMABLE 27 | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS) 28 { 29 // Preflet container view 30 fMainView = new PrefletView(this); 31 32 // Save and revert buttons 33 fRevert = new BButton("revert", _T("Revert"), new BMessage(kRevert)); 34 fRevert->SetEnabled(false); 35 fSave = new BButton("save", _T("Save"), new BMessage(kSave)); 36 fSave->SetEnabled(false); 37 38 // Calculate inset 39 float inset = ceilf(be_plain_font->Size() * 0.7f); 40 41 // Build the layout 42 SetLayout(new BGroupLayout(B_VERTICAL)); 43 44 // Add childs 45 AddChild(BGroupLayoutBuilder(B_VERTICAL, inset) 46 .Add(fMainView) 47 48 .AddGroup(B_HORIZONTAL, inset) 49 .AddGlue() 50 .Add(fRevert) 51 .Add(fSave) 52 .End() 53 54 .SetInsets(inset, inset, inset, inset) 55 ); 56 57 // Center this window on screen and show it 58 CenterOnScreen(); 59 Show(); 60 } 61 62 63 void 64 PrefletWin::MessageReceived(BMessage* msg) 65 { 66 switch (msg->what) { 67 case kSave: 68 for (int32 i = 0; i < fMainView->CountPages(); i++) { 69 SettingsPane* pane = 70 dynamic_cast<SettingsPane*>(fMainView->PageAt(i)); 71 if (pane) { 72 if (pane->Save() == B_OK) { 73 fSave->SetEnabled(false); 74 fRevert->SetEnabled(true); 75 } else 76 break; 77 } 78 } 79 break; 80 case kRevert: 81 for (int32 i = 0; i < fMainView->CountPages(); i++) { 82 SettingsPane* pane = 83 dynamic_cast<SettingsPane*>(fMainView->PageAt(i)); 84 if (pane) { 85 if (pane->Revert() == B_OK) 86 fRevert->SetEnabled(false); 87 } 88 } 89 break; 90 default: 91 BWindow::MessageReceived(msg); 92 } 93 } 94 95 96 bool 97 PrefletWin::QuitRequested() 98 { 99 be_app_messenger.SendMessage(B_QUIT_REQUESTED); 100 return true; 101 } 102 103 104 void 105 PrefletWin::SettingChanged() 106 { 107 fSave->SetEnabled(true); 108 } 109