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