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