1 /* 2 * Copyright 2002-2006, Haiku. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * DarkWyrm (darkwyrm@earthlink.net) 7 */ 8 9 #include <Button.h> 10 #include <Messenger.h> 11 #include <TabView.h> 12 #include "APRWindow.h" 13 #include "APRView.h" 14 #include "defs.h" 15 16 static const uint32 kMsgSetDefaults = 'dflt'; 17 static const uint32 kMsgRevert = 'rvrt'; 18 19 APRWindow::APRWindow(BRect frame) 20 : BWindow(frame, "Appearance", B_TITLED_WINDOW, B_NOT_ZOOMABLE, 21 B_ALL_WORKSPACES) 22 { 23 BRect rect = Bounds(); 24 BView* view = new BView(rect, "background", B_FOLLOW_ALL, B_WILL_DRAW); 25 view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 26 AddChild(view); 27 28 rect.left = 10; 29 rect.top = rect.bottom - 10; 30 fDefaultsButton = new BButton(rect, "defaults", "Defaults", 31 new BMessage(kMsgSetDefaults), B_FOLLOW_LEFT 32 | B_FOLLOW_BOTTOM, B_WILL_DRAW); 33 fDefaultsButton->ResizeToPreferred(); 34 fDefaultsButton->SetEnabled(false); 35 float buttonHeight = fDefaultsButton->Bounds().Height(); 36 fDefaultsButton->MoveBy(0, -buttonHeight); 37 view->AddChild(fDefaultsButton); 38 39 rect = fDefaultsButton->Frame(); 40 rect.OffsetBy(fDefaultsButton->Bounds().Width() + 10, 0); 41 42 fRevertButton = new BButton(rect, "revert", "Revert", 43 new BMessage(kMsgRevert), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW); 44 fRevertButton->ResizeToPreferred(); 45 fRevertButton->SetEnabled(false); 46 view->AddChild(fRevertButton); 47 48 rect = Bounds(); 49 rect.top += 5; 50 rect.bottom -= 20 + buttonHeight; 51 rect.left += 5; 52 BTabView *tabView = new BTabView(rect, "tabview", B_WIDTH_FROM_LABEL); 53 54 rect = tabView->ContainerView()->Bounds().InsetByCopy(5, 8); 55 56 fAntialiasingSettings = new AntialiasingSettingsView(rect, "Antialiasing"); 57 fColorsView = new APRView(rect, "Colors", B_FOLLOW_ALL, B_WILL_DRAW); 58 59 tabView->AddTab(fColorsView); 60 tabView->AddTab(fAntialiasingSettings); 61 62 view->AddChild(tabView); 63 fColorsView->ResizeToPreferred(); 64 fAntialiasingSettings->ResizeToPreferred(); 65 66 fDefaultsButton->SetEnabled(fColorsView->IsDefaultable() 67 || fAntialiasingSettings->IsDefaultable()); 68 fDefaultsButton->SetTarget(this); 69 fRevertButton->SetTarget(this); 70 } 71 72 73 void 74 APRWindow::MessageReceived(BMessage *message) 75 { 76 switch (message->what) { 77 case kMsgUpdate: 78 fDefaultsButton->SetEnabled(fColorsView->IsDefaultable() 79 || fAntialiasingSettings->IsDefaultable()); 80 fRevertButton->SetEnabled(true); 81 break; 82 case kMsgSetDefaults: 83 fColorsView -> MessageReceived(new BMessage(DEFAULT_SETTINGS)); 84 fAntialiasingSettings->SetDefaults(); 85 fDefaultsButton->SetEnabled(false); 86 fRevertButton->SetEnabled(true); 87 break; 88 89 case kMsgRevert: 90 fColorsView -> MessageReceived(new BMessage(REVERT_SETTINGS)); 91 fAntialiasingSettings->Revert(); 92 fDefaultsButton->SetEnabled(fColorsView->IsDefaultable() 93 || fAntialiasingSettings->IsDefaultable()); 94 fRevertButton->SetEnabled(false); 95 break; 96 97 default: 98 BWindow::MessageReceived(message); 99 break; 100 } 101 } 102 103 104 bool 105 APRWindow::QuitRequested(void) 106 { 107 be_app->PostMessage(B_QUIT_REQUESTED); 108 return(true); 109 } 110