1 /* 2 * Copyright 2002-2011, Haiku. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * DarkWyrm (darkwyrm@earthlink.net) 7 * Alexander von Gluck, kallisti5@unixzen.com 8 * Stephan Aßmus <superstippi@gmx.de> 9 */ 10 11 12 #include "APRWindow.h" 13 14 #include <Button.h> 15 #include <Catalog.h> 16 #include <GroupLayoutBuilder.h> 17 #include <Locale.h> 18 #include <Messenger.h> 19 #include <SpaceLayoutItem.h> 20 #include <TabView.h> 21 22 #include "AntialiasingSettingsView.h" 23 #include "APRView.h" 24 #include "LookAndFeelSettingsView.h" 25 #include "defs.h" 26 #include "FontView.h" 27 28 29 #undef B_TRANSLATION_CONTEXT 30 #define B_TRANSLATION_CONTEXT "APRWindow" 31 32 33 static const uint32 kMsgSetDefaults = 'dflt'; 34 static const uint32 kMsgRevert = 'rvrt'; 35 36 37 APRWindow::APRWindow(BRect frame) 38 : 39 BWindow(frame, B_TRANSLATE_SYSTEM_NAME("Appearance"), B_TITLED_WINDOW, 40 B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS 41 | B_QUIT_ON_WINDOW_CLOSE, B_ALL_WORKSPACES) 42 { 43 SetLayout(new BGroupLayout(B_HORIZONTAL)); 44 45 fDefaultsButton = new BButton("defaults", B_TRANSLATE("Defaults"), 46 new BMessage(kMsgSetDefaults), B_WILL_DRAW); 47 48 fRevertButton = new BButton("revert", B_TRANSLATE("Revert"), 49 new BMessage(kMsgRevert), B_WILL_DRAW); 50 51 BTabView* tabView = new BTabView("tabview", B_WIDTH_FROM_LABEL); 52 53 fLookAndFeelSettings = new LookAndFeelSettingsView( 54 B_TRANSLATE("Look and feel")); 55 56 fFontSettings = new FontView(B_TRANSLATE("Fonts")); 57 58 fColorsView = new APRView(B_TRANSLATE("Colors")); 59 60 fAntialiasingSettings = new AntialiasingSettingsView( 61 B_TRANSLATE("Antialiasing")); 62 63 tabView->AddTab(fLookAndFeelSettings); 64 tabView->AddTab(fFontSettings); 65 tabView->AddTab(fColorsView); 66 tabView->AddTab(fAntialiasingSettings); 67 68 _UpdateButtons(); 69 70 AddChild(BGroupLayoutBuilder(B_VERTICAL, 0) 71 .Add(tabView) 72 .Add(BSpaceLayoutItem::CreateVerticalStrut(5)) 73 .Add(BGroupLayoutBuilder(B_HORIZONTAL) 74 .Add(fRevertButton) 75 .AddGlue() 76 .Add(fDefaultsButton) 77 ) 78 .SetInsets(5, 5, 5, 5) 79 ); 80 } 81 82 83 void 84 APRWindow::MessageReceived(BMessage *message) 85 { 86 switch (message->what) { 87 case kMsgUpdate: 88 _UpdateButtons(); 89 break; 90 91 case kMsgSetDefaults: 92 fFontSettings->SetDefaults(); 93 fColorsView->SetDefaults(); 94 fAntialiasingSettings->SetDefaults(); 95 fLookAndFeelSettings->SetDefaults(); 96 97 _UpdateButtons(); 98 break; 99 100 case kMsgRevert: 101 fColorsView->Revert(); 102 fAntialiasingSettings->Revert(); 103 fFontSettings->Revert(); 104 fLookAndFeelSettings->Revert(); 105 106 _UpdateButtons(); 107 break; 108 109 default: 110 BWindow::MessageReceived(message); 111 break; 112 } 113 } 114 115 116 void 117 APRWindow::_UpdateButtons() 118 { 119 fDefaultsButton->SetEnabled(_IsDefaultable()); 120 fRevertButton->SetEnabled(_IsRevertable()); 121 } 122 123 124 bool 125 APRWindow::_IsDefaultable() const 126 { 127 // printf("fonts defaultable: %d\n", fFontSettings->IsDefaultable()); 128 // printf("colors defaultable: %d\n", fColorsView->IsDefaultable()); 129 // printf("AA defaultable: %d\n", fAntialiasingSettings->IsDefaultable()); 130 // printf("decor defaultable: %d\n", fLookAndFeelSettings->IsDefaultable()); 131 return fColorsView->IsDefaultable() 132 || fFontSettings->IsDefaultable() 133 || fAntialiasingSettings->IsDefaultable() 134 || fLookAndFeelSettings->IsDefaultable(); 135 } 136 137 138 bool 139 APRWindow::_IsRevertable() const 140 { 141 // printf("fonts revertable: %d\n", fFontSettings->IsRevertable()); 142 // printf("colors revertable: %d\n", fColorsView->IsRevertable()); 143 // printf("AA revertable: %d\n", fAntialiasingSettings->IsRevertable()); 144 // printf("decor revertable: %d\n", fLookAndFeelSettings->IsRevertable()); 145 return fColorsView->IsRevertable() 146 || fFontSettings->IsRevertable() 147 || fAntialiasingSettings->IsRevertable() 148 || fLookAndFeelSettings->IsRevertable(); 149 } 150