1 /* 2 * Copyright 2002-2009, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT license. 4 * 5 * Copyright 1999, Be Incorporated. All Rights Reserved. 6 * This file may be used under the terms of the Be Sample Code License. 7 * 8 * Written by: Daniel Switkin 9 */ 10 11 12 #include "PrefsWindow.h" 13 #include "Common.h" 14 #include "PulseApp.h" 15 #include "ConfigView.h" 16 17 #include <Catalog.h> 18 #include <Button.h> 19 #include <Locale.h> 20 #include <TabView.h> 21 #include <TextControl.h> 22 23 #include <stdlib.h> 24 #include <stdio.h> 25 26 #undef B_TRANSLATE_CONTEXT 27 #define B_TRANSLATE_CONTEXT "PrefsWindow" 28 29 30 PrefsWindow::PrefsWindow(BRect frame, const char *name, 31 BMessenger *messenger, Prefs *prefs) 32 : BWindow(frame, name, B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE 33 | B_NOT_MINIMIZABLE | B_ASYNCHRONOUS_CONTROLS), 34 fTarget(*messenger), 35 fPrefs(prefs) 36 { 37 // This gives a nice look, and sets the background color correctly 38 BRect bounds = Bounds(); 39 BView* topView = new BView(bounds, "ParentView", B_FOLLOW_ALL, B_WILL_DRAW); 40 topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 41 AddChild(topView); 42 43 bounds.top += 10; 44 bounds.bottom -= 45; 45 fTabView = new BTabView(bounds, "TabView", B_WIDTH_FROM_LABEL); 46 fTabView->SetFont(be_plain_font); 47 topView->AddChild(fTabView); 48 49 BRect rect = fTabView->ContainerView()->Bounds(); 50 rect.InsetBy(5, 5); 51 52 ConfigView *normalView = new ConfigView(rect, B_TRANSLATE("Normal mode"), 53 PRV_NORMAL_CHANGE_COLOR, fTarget, prefs); 54 fTabView->AddTab(normalView); 55 56 ConfigView *miniView = new ConfigView(rect, B_TRANSLATE("Mini mode"), 57 PRV_MINI_CHANGE_COLOR, fTarget, prefs); 58 fTabView->AddTab(miniView); 59 60 ConfigView *deskbarView = new ConfigView(rect, B_TRANSLATE("Deskbar mode"), 61 PRV_DESKBAR_CHANGE_COLOR, fTarget, prefs); 62 fTabView->AddTab(deskbarView); 63 64 float width, height; 65 deskbarView->GetPreferredSize(&width, &height); 66 normalView->ResizeTo(width, height); 67 miniView->ResizeTo(width, height); 68 deskbarView->ResizeTo(width, height); 69 70 fTabView->Select(0L); 71 fTabView->ResizeTo(deskbarView->Bounds().Width() + 16.0f, 72 deskbarView->Bounds().Height() + 73 fTabView->ContainerView()->Frame().top + 16.0f); 74 75 BButton *okButton = new BButton(rect, "ok", B_TRANSLATE("OK"), 76 new BMessage(PRV_BOTTOM_OK), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); 77 okButton->ResizeToPreferred(); 78 okButton->MoveTo(Bounds().Width() - 8.0f - okButton->Bounds().Width(), 79 Bounds().Height() - 8.0f - okButton->Bounds().Height()); 80 topView->AddChild(okButton); 81 82 BButton *defaultsButton = new BButton(okButton->Frame(), "defaults", 83 B_TRANSLATE("Defaults"), new BMessage(PRV_BOTTOM_DEFAULTS), 84 B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); 85 defaultsButton->ResizeToPreferred(); 86 defaultsButton->MoveBy(-defaultsButton->Bounds().Width() - 10.0f, 0.0f); 87 topView->AddChild(defaultsButton); 88 89 okButton->MakeDefault(true); 90 91 fTabView->SetResizingMode(B_FOLLOW_NONE); 92 ResizeTo(fTabView->Frame().Width(), fTabView->Frame().bottom + 16.0f 93 + okButton->Bounds().Height()); 94 } 95 96 97 PrefsWindow::~PrefsWindow() 98 { 99 fPrefs->prefs_window_rect = Frame(); 100 fPrefs->Save(); 101 } 102 103 104 void 105 PrefsWindow::MessageReceived(BMessage *message) 106 { 107 switch (message->what) { 108 case PRV_BOTTOM_OK: 109 { 110 Hide(); 111 112 fTabView->Select(2); 113 ConfigView *deskbar = (ConfigView *)FindView( 114 B_TRANSLATE("Deskbar mode")); 115 deskbar->UpdateDeskbarIconWidth(); 116 117 PostMessage(B_QUIT_REQUESTED); 118 break; 119 } 120 121 case PRV_BOTTOM_DEFAULTS: 122 { 123 BTab *tab = fTabView->TabAt(fTabView->Selection()); 124 BView *view = tab->View(); 125 view->MessageReceived(message); 126 break; 127 } 128 129 default: 130 BWindow::MessageReceived(message); 131 break; 132 } 133 } 134 135 136 bool 137 PrefsWindow::QuitRequested() 138 { 139 fTarget.SendMessage(new BMessage(PRV_QUIT)); 140 return true; 141 } 142