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 <LayoutBuilder.h> 17 #include <Locale.h> 18 #include <Messenger.h> 19 #include <TabView.h> 20 21 #include "AntialiasingSettingsView.h" 22 #include "APRView.h" 23 #include "defs.h" 24 #include "FontView.h" 25 #include "LookAndFeelSettingsView.h" 26 27 28 #undef B_TRANSLATION_CONTEXT 29 #define B_TRANSLATION_CONTEXT "APRWindow" 30 31 32 static const uint32 kMsgSetDefaults = 'dflt'; 33 static const uint32 kMsgRevert = 'rvrt'; 34 35 36 APRWindow::APRWindow(BRect frame) 37 : 38 BWindow(frame, B_TRANSLATE_SYSTEM_NAME("Appearance"), B_TITLED_WINDOW, 39 B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS 40 | B_QUIT_ON_WINDOW_CLOSE, B_ALL_WORKSPACES) 41 { 42 fDefaultsButton = new BButton("defaults", B_TRANSLATE("Defaults"), 43 new BMessage(kMsgSetDefaults), B_WILL_DRAW); 44 45 fRevertButton = new BButton("revert", B_TRANSLATE("Revert"), 46 new BMessage(kMsgRevert), B_WILL_DRAW); 47 48 BTabView* tabView = new BTabView("tabview", B_WIDTH_FROM_LABEL); 49 50 fFontSettings = new FontView(B_TRANSLATE("Fonts")); 51 52 fColorsView = new APRView(B_TRANSLATE("Colors")); 53 54 fLookAndFeelSettings = new LookAndFeelSettingsView( 55 B_TRANSLATE("Look and feel")); 56 57 fAntialiasingSettings = new AntialiasingSettingsView( 58 B_TRANSLATE("Antialiasing")); 59 60 tabView->AddTab(fFontSettings); 61 tabView->AddTab(fColorsView); 62 tabView->AddTab(fLookAndFeelSettings); 63 tabView->AddTab(fAntialiasingSettings); 64 65 _UpdateButtons(); 66 67 BLayoutBuilder::Group<>(this, B_VERTICAL) 68 .SetInsets(B_USE_DEFAULT_SPACING) 69 .Add(tabView) 70 .AddGroup(B_HORIZONTAL) 71 .Add(fDefaultsButton) 72 .Add(fRevertButton) 73 .AddGlue(); 74 } 75 76 77 void 78 APRWindow::MessageReceived(BMessage *message) 79 { 80 switch (message->what) { 81 case kMsgUpdate: 82 _UpdateButtons(); 83 break; 84 85 case kMsgSetDefaults: 86 fFontSettings->SetDefaults(); 87 fColorsView->SetDefaults(); 88 fLookAndFeelSettings->SetDefaults(); 89 fAntialiasingSettings->SetDefaults(); 90 91 _UpdateButtons(); 92 break; 93 94 case kMsgRevert: 95 fFontSettings->Revert(); 96 fColorsView->Revert(); 97 fLookAndFeelSettings->Revert(); 98 fAntialiasingSettings->Revert(); 99 100 _UpdateButtons(); 101 break; 102 103 default: 104 BWindow::MessageReceived(message); 105 break; 106 } 107 } 108 109 110 void 111 APRWindow::_UpdateButtons() 112 { 113 fDefaultsButton->SetEnabled(_IsDefaultable()); 114 fRevertButton->SetEnabled(_IsRevertable()); 115 } 116 117 118 bool 119 APRWindow::_IsDefaultable() const 120 { 121 // printf("fonts defaultable: %d\n", fFontSettings->IsDefaultable()); 122 // printf("colors defaultable: %d\n", fColorsView->IsDefaultable()); 123 // printf("AA defaultable: %d\n", fAntialiasingSettings->IsDefaultable()); 124 // printf("decor defaultable: %d\n", fLookAndFeelSettings->IsDefaultable()); 125 return fFontSettings->IsDefaultable() 126 || fColorsView->IsDefaultable() 127 || fLookAndFeelSettings->IsDefaultable() 128 || fAntialiasingSettings->IsDefaultable(); 129 } 130 131 132 bool 133 APRWindow::_IsRevertable() const 134 { 135 // printf("fonts revertable: %d\n", fFontSettings->IsRevertable()); 136 // printf("colors revertable: %d\n", fColorsView->IsRevertable()); 137 // printf("AA revertable: %d\n", fAntialiasingSettings->IsRevertable()); 138 // printf("decor revertable: %d\n", fLookAndFeelSettings->IsRevertable()); 139 return fFontSettings->IsRevertable() 140 || fColorsView->IsRevertable() 141 || fLookAndFeelSettings->IsRevertable() 142 || fAntialiasingSettings->IsRevertable(); 143 } 144