diff --git a/src/preferences/fonts/FontSelectionView.cpp b/src/preferences/fonts/FontSelectionView.cpp index 0fcbf87562..58178b2a17 100644 --- a/src/preferences/fonts/FontSelectionView.cpp +++ b/src/preferences/fonts/FontSelectionView.cpp @@ -391,6 +391,29 @@ FontSelectionView::Revert() } +bool +FontSelectionView::IsDefaultable() +{ + font_family default_family; + font_style default_style; + float default_size; + + if (_get_system_default_font_(Name(), default_family, default_style, &default_size) != B_OK) + return false; + + font_family current_family; + font_style current_style; + float current_size; + + fCurrentFont.GetFamilyAndStyle(¤t_family, ¤t_style); + current_size = fCurrentFont.Size(); + + return strcmp(current_family, default_family) != 0 + || strcmp(current_style, default_style) != 0 + || current_size != default_size; +} + + bool FontSelectionView::IsRevertable() { diff --git a/src/preferences/fonts/FontSelectionView.h b/src/preferences/fonts/FontSelectionView.h index e656d14979..8d1c6b4154 100644 --- a/src/preferences/fonts/FontSelectionView.h +++ b/src/preferences/fonts/FontSelectionView.h @@ -34,6 +34,7 @@ class FontSelectionView : public BView { void SetDefaults(); void Revert(); + bool IsDefaultable(); bool IsRevertable(); void UpdateFontsMenu(); diff --git a/src/preferences/fonts/FontView.cpp b/src/preferences/fonts/FontView.cpp index 7faf7891bc..4e5134aef1 100644 --- a/src/preferences/fonts/FontView.cpp +++ b/src/preferences/fonts/FontView.cpp @@ -93,6 +93,13 @@ FontView::RelayoutIfNeeded() fFixedView->RelayoutIfNeeded(); } +bool +FontView::IsDefaultable() +{ + return fPlainView->IsDefaultable() + || fBoldView->IsDefaultable() + || fFixedView->IsDefaultable(); +} bool FontView::IsRevertable() diff --git a/src/preferences/fonts/FontView.h b/src/preferences/fonts/FontView.h index bf9b462a76..951564ba8a 100644 --- a/src/preferences/fonts/FontView.h +++ b/src/preferences/fonts/FontView.h @@ -25,6 +25,7 @@ class FontView : public BView { void UpdateFonts(); void RelayoutIfNeeded(); + bool IsDefaultable(); bool IsRevertable(); private: diff --git a/src/preferences/fonts/MainWindow.cpp b/src/preferences/fonts/MainWindow.cpp index 6e335a8900..9d25a9673c 100644 --- a/src/preferences/fonts/MainWindow.cpp +++ b/src/preferences/fonts/MainWindow.cpp @@ -35,15 +35,16 @@ MainWindow::MainWindow() rect.left = 10; rect.top = rect.bottom - 10; - BButton *button = new BButton(rect, "defaults", "Defaults", + fDefaultsButton = new BButton(rect, "defaults", "Defaults", new BMessage(kMsgSetDefaults), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW); - button->ResizeToPreferred(); - float buttonHeight = button->Bounds().Height(); - button->MoveBy(0, -buttonHeight); - view->AddChild(button); + fDefaultsButton->ResizeToPreferred(); + fDefaultsButton->SetEnabled(false); + float buttonHeight = fDefaultsButton->Bounds().Height(); + fDefaultsButton->MoveBy(0, -buttonHeight); + view->AddChild(fDefaultsButton); - rect = button->Frame(); - rect.OffsetBy(button->Bounds().Width() + 10, 0); + rect = fDefaultsButton->Frame(); + rect.OffsetBy(fDefaultsButton->Bounds().Width() + 10, 0); fRevertButton = new BButton(rect, "revert", "Revert", new BMessage(kMsgRevert), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW); @@ -99,6 +100,8 @@ MainWindow::MainWindow() fRunner = new BMessageRunner(this, new BMessage(kMsgCheckFonts), 3000000); // every 3 seconds + + fDefaultsButton->SetEnabled(fFontsView->IsDefaultable()); } @@ -123,16 +126,19 @@ MainWindow::MessageReceived(BMessage *message) { switch (message->what) { case kMsgUpdate: + fDefaultsButton->SetEnabled(fFontsView->IsDefaultable()); fRevertButton->SetEnabled(fFontsView->IsRevertable()); break; case kMsgSetDefaults: fFontsView->SetDefaults(); + fDefaultsButton->SetEnabled(false); fRevertButton->SetEnabled(fFontsView->IsRevertable()); break; case kMsgRevert: fFontsView->Revert(); + fDefaultsButton->SetEnabled(fFontsView->IsDefaultable()); fRevertButton->SetEnabled(false); break; diff --git a/src/preferences/fonts/MainWindow.h b/src/preferences/fonts/MainWindow.h index d7f3b295f8..9569c98971 100644 --- a/src/preferences/fonts/MainWindow.h +++ b/src/preferences/fonts/MainWindow.h @@ -33,6 +33,7 @@ class MainWindow : public BWindow { BMessageRunner* fRunner; FontView* fFontsView; + BButton* fDefaultsButton; BButton* fRevertButton; FontsSettings fSettings; diff --git a/src/preferences/keyboard/KeyboardSettings.cpp b/src/preferences/keyboard/KeyboardSettings.cpp index b1181f23b0..d256002f8d 100644 --- a/src/preferences/keyboard/KeyboardSettings.cpp +++ b/src/preferences/keyboard/KeyboardSettings.cpp @@ -117,3 +117,11 @@ KeyboardSettings::Defaults() SetKeyboardRepeatDelay(kb_default_key_repeat_delay); SetKeyboardRepeatRate(kb_default_key_repeat_rate); } + + +bool +KeyboardSettings::IsDefaultable() +{ + return fSettings.key_repeat_delay != kb_default_key_repeat_delay + || fSettings.key_repeat_rate != kb_default_key_repeat_rate; +} diff --git a/src/preferences/keyboard/KeyboardSettings.h b/src/preferences/keyboard/KeyboardSettings.h index 9ad45f8f2f..31dc185d48 100644 --- a/src/preferences/keyboard/KeyboardSettings.h +++ b/src/preferences/keyboard/KeyboardSettings.h @@ -21,6 +21,7 @@ public : void Dump(); void Revert(); void Defaults(); + bool IsDefaultable(); BPoint WindowCorner() const { return fCorner; } void SetWindowCorner(BPoint corner); diff --git a/src/preferences/keyboard/KeyboardWindow.cpp b/src/preferences/keyboard/KeyboardWindow.cpp index e6f2dd0123..79e67a3e92 100644 --- a/src/preferences/keyboard/KeyboardWindow.cpp +++ b/src/preferences/keyboard/KeyboardWindow.cpp @@ -39,6 +39,10 @@ KeyboardWindow::KeyboardWindow() if (slider !=NULL) slider->SetValue(fSettings.KeyboardRepeatDelay()); + BButton *button = (BButton *)FindView("keyboard_defaults"); + if (button !=NULL) + button->SetEnabled(fSettings.IsDefaultable()); + #ifdef DEBUG fSettings.Dump(); #endif @@ -78,6 +82,10 @@ KeyboardWindow::MessageReceived(BMessage *message) slider = (BSlider *)FindView("delay_until_key_repeat"); if (slider !=NULL) slider->SetValue(fSettings.KeyboardRepeatDelay()); + + button = (BButton *)FindView("keyboard_defaults"); + if (button !=NULL) + button->SetEnabled(false); button = (BButton *)FindView("keyboard_revert"); if (button !=NULL) @@ -95,6 +103,10 @@ KeyboardWindow::MessageReceived(BMessage *message) if (slider !=NULL) slider->SetValue(fSettings.KeyboardRepeatDelay()); + button = (BButton *)FindView("keyboard_defaults"); + if (button !=NULL) + button->SetEnabled(fSettings.IsDefaultable()); + button = (BButton *)FindView("keyboard_revert"); if (button !=NULL) button->SetEnabled(false); @@ -106,6 +118,10 @@ KeyboardWindow::MessageReceived(BMessage *message) break; fSettings.SetKeyboardRepeatRate(rate); + button = (BButton *)FindView("keyboard_defaults"); + if (button !=NULL) + button->SetEnabled(fSettings.IsDefaultable()); + button = (BButton *)FindView("keyboard_revert"); if (button !=NULL) button->SetEnabled(true); @@ -133,6 +149,10 @@ KeyboardWindow::MessageReceived(BMessage *message) if (slider !=NULL) slider->SetValue(delay); + button = (BButton *)FindView("keyboard_defaults"); + if (button !=NULL) + button->SetEnabled(fSettings.IsDefaultable()); + button = (BButton *)FindView("keyboard_revert"); if (button !=NULL) button->SetEnabled(true); diff --git a/src/preferences/mouse/MouseSettings.cpp b/src/preferences/mouse/MouseSettings.cpp index a7d96a2b79..4c948312fc 100644 --- a/src/preferences/mouse/MouseSettings.cpp +++ b/src/preferences/mouse/MouseSettings.cpp @@ -191,6 +191,23 @@ MouseSettings::Defaults() } +/** Checks if the settings are different then the system defaults + */ + +bool +MouseSettings::IsDefaultable() +{ + return fSettings.click_speed != kDefaultClickSpeed + || fSettings.accel.speed != kDefaultMouseSpeed + || fSettings.type != kDefaultMouseType + || fSettings.accel.accel_factor != kDefaultAccelerationFactor + || fMode != B_NORMAL_MOUSE + || fSettings.map.button[0] != B_PRIMARY_MOUSE_BUTTON + || fSettings.map.button[1] != B_SECONDARY_MOUSE_BUTTON + || fSettings.map.button[2] != B_TERTIARY_MOUSE_BUTTON; +} + + /** Reverts to the active settings at program startup */ diff --git a/src/preferences/mouse/MouseSettings.h b/src/preferences/mouse/MouseSettings.h index d2e3424184..a03b09ed04 100644 --- a/src/preferences/mouse/MouseSettings.h +++ b/src/preferences/mouse/MouseSettings.h @@ -30,6 +30,7 @@ class MouseSettings { void Revert(); void Defaults(); + bool IsDefaultable(); void Dump(); BPoint WindowPosition() const { return fWindowPosition; } diff --git a/src/preferences/mouse/MouseWindow.cpp b/src/preferences/mouse/MouseWindow.cpp index 445140959f..d5c8099c07 100644 --- a/src/preferences/mouse/MouseWindow.cpp +++ b/src/preferences/mouse/MouseWindow.cpp @@ -48,12 +48,13 @@ MouseWindow::MouseWindow(BRect _rect) // Add the "Default" button BRect rect(kBorderSpace, fSettingsView->Frame().bottom + kItemSpace + 2, kBorderSpace + 75, fSettingsView->Frame().bottom + 20); - BButton *button = new BButton(rect, "defaults", "Defaults", new BMessage(kMsgDefaults)); - button->ResizeToPreferred(); - view->AddChild(button); + fDefaultsButton = new BButton(rect, "defaults", "Defaults", new BMessage(kMsgDefaults)); + fDefaultsButton->ResizeToPreferred(); + fDefaultsButton->SetEnabled(fSettings.IsDefaultable()); + view->AddChild(fDefaultsButton); // Add the "Revert" button - rect.OffsetBy(button->Bounds().Width() + kItemSpace, 0); + rect.OffsetBy(fDefaultsButton->Bounds().Width() + kItemSpace, 0); fRevertButton = new BButton(rect, "revert", "Revert", new BMessage(kMsgRevert)); fRevertButton->SetEnabled(false); fRevertButton->ResizeToPreferred(); @@ -64,7 +65,7 @@ MouseWindow::MouseWindow(BRect _rect) // buttons and draw the selected imagery ResizeTo(fSettingsView->Frame().right + kBorderSpace, - button->Frame().bottom + kBorderSpace - 1); + fRevertButton->Frame().bottom + kBorderSpace - 1); // check if the window is on screen @@ -105,7 +106,8 @@ MouseWindow::MessageReceived(BMessage *message) fSettings.Defaults(); fSettingsView->UpdateFromSettings(); - SetRevertable(true); + fDefaultsButton->SetEnabled(false); + fRevertButton->SetEnabled(true); break; } @@ -114,7 +116,8 @@ MouseWindow::MessageReceived(BMessage *message) fSettings.Revert(); fSettingsView->UpdateFromSettings(); - SetRevertable(false); + fDefaultsButton->SetEnabled(fSettings.IsDefaultable()); + fRevertButton->SetEnabled(false); break; } @@ -124,7 +127,8 @@ MouseWindow::MessageReceived(BMessage *message) if (message->FindInt32("index", &type) == B_OK) { fSettings.SetMouseType(++type); fSettingsView->SetMouseType(type); - SetRevertable(true); + fDefaultsButton->SetEnabled(fSettings.IsDefaultable()); + fRevertButton->SetEnabled(true); } break; } @@ -134,7 +138,8 @@ MouseWindow::MessageReceived(BMessage *message) int32 mode; if (message->FindInt32("mode", &mode) == B_OK) { fSettings.SetMouseMode((mode_mouse)mode); - SetRevertable(true); + fDefaultsButton->SetEnabled(fSettings.IsDefaultable()); + fRevertButton->SetEnabled(true); } break; } @@ -145,7 +150,8 @@ MouseWindow::MessageReceived(BMessage *message) if (message->FindInt32("be:value", &value) == B_OK) { // slow = 1000000, fast = 0 fSettings.SetClickSpeed(value * 1000); - SetRevertable(true); + fDefaultsButton->SetEnabled(fSettings.IsDefaultable()); + fRevertButton->SetEnabled(true); } break; } @@ -156,7 +162,8 @@ MouseWindow::MessageReceived(BMessage *message) if (message->FindInt32("be:value", &value) == B_OK) { // slow = 8192, fast = 524287 fSettings.SetMouseSpeed((int32)pow(2, value * 6 / 1000) * 8192); - SetRevertable(true); + fDefaultsButton->SetEnabled(fSettings.IsDefaultable()); + fRevertButton->SetEnabled(true); } break; } @@ -167,7 +174,8 @@ MouseWindow::MessageReceived(BMessage *message) if (message->FindInt32("be:value", &value) == B_OK) { // slow = 0, fast = 262144 fSettings.SetAccelerationFactor((int32)pow(value * 4 / 1000, 2) * 16384); - SetRevertable(true); + fDefaultsButton->SetEnabled(fSettings.IsDefaultable()); + fRevertButton->SetEnabled(true); } break; } @@ -189,7 +197,8 @@ MouseWindow::MessageReceived(BMessage *message) } fSettings.SetMapping(button, mapping); - SetRevertable(true); + fDefaultsButton->SetEnabled(fSettings.IsDefaultable()); + fRevertButton->SetEnabled(true); fSettingsView->MouseMapUpdated(); } break; @@ -201,10 +210,3 @@ MouseWindow::MessageReceived(BMessage *message) } } - -void -MouseWindow::SetRevertable(bool revertable) -{ - fRevertButton->SetEnabled(revertable); -} - diff --git a/src/preferences/mouse/MouseWindow.h b/src/preferences/mouse/MouseWindow.h index 43e267bf3e..b2847d1e34 100644 --- a/src/preferences/mouse/MouseWindow.h +++ b/src/preferences/mouse/MouseWindow.h @@ -33,10 +33,9 @@ class MouseWindow : public BWindow { virtual bool QuitRequested(); virtual void MessageReceived(BMessage *message); - void SetRevertable(bool revertable); - private: MouseSettings fSettings; + BButton *fDefaultsButton; BButton *fRevertButton; SettingsView *fSettingsView; }; diff --git a/src/preferences/virtualmemory/Settings.cpp b/src/preferences/virtualmemory/Settings.cpp index 3fe9371633..163aaf4bac 100644 --- a/src/preferences/virtualmemory/Settings.cpp +++ b/src/preferences/virtualmemory/Settings.cpp @@ -204,6 +204,14 @@ Settings::RevertSwapChanges() } +bool +Settings::IsDefaultable() +{ + return fSwapEnabled != fInitialSwapEnabled + || fSwapSize != fInitialSwapSize; +} + + bool Settings::SwapChanged() { diff --git a/src/preferences/virtualmemory/Settings.h b/src/preferences/virtualmemory/Settings.h index 5993f09229..bd247c555a 100644 --- a/src/preferences/virtualmemory/Settings.h +++ b/src/preferences/virtualmemory/Settings.h @@ -27,6 +27,7 @@ class Settings { void SetSwapDefaults(); void RevertSwapChanges(); + bool IsDefaultable(); bool SwapChanged(); private: diff --git a/src/preferences/virtualmemory/SettingsWindow.cpp b/src/preferences/virtualmemory/SettingsWindow.cpp index d90e6e0b6c..516ada289f 100644 --- a/src/preferences/virtualmemory/SettingsWindow.cpp +++ b/src/preferences/virtualmemory/SettingsWindow.cpp @@ -196,17 +196,19 @@ SettingsWindow::SettingsWindow() // Add "Defaults" and "Revert" buttons rect.top = box->Frame().bottom + 10; - BButton* button = new BButton(rect, "defaults", "Defaults", new BMessage(kMsgDefaults)); - button->ResizeToPreferred(); - view->AddChild(button); + fDefaultsButton = new BButton(rect, "defaults", "Defaults", new BMessage(kMsgDefaults)); + fDefaultsButton->ResizeToPreferred(); + fDefaultsButton->SetEnabled(fSettings.IsDefaultable()); + view->AddChild(fDefaultsButton); - rect = button->Frame(); + rect = fDefaultsButton->Frame(); rect.OffsetBy(rect.Width() + 10, 0); fRevertButton = new BButton(rect, "revert", "Revert", new BMessage(kMsgRevert)); - button->ResizeToPreferred(); + fRevertButton->ResizeToPreferred(); + fRevertButton->SetEnabled(false); view->AddChild(fRevertButton); - view->ResizeTo(view->Frame().Width(), button->Frame().bottom + 10); + view->ResizeTo(view->Frame().Width(), fRevertButton->Frame().bottom + 10); ResizeTo(view->Bounds().Width(), view->Bounds().Height()); AddChild(view); // add view after resizing the window, so that the view's resizing @@ -266,6 +268,8 @@ SettingsWindow::_Update() // ToDo: set volume + fDefaultsButton->SetEnabled(fSettings.IsDefaultable()); + bool changed = fSettings.SwapChanged(); if (fRevertButton->IsEnabled() != changed) { fRevertButton->SetEnabled(changed); diff --git a/src/preferences/virtualmemory/SettingsWindow.h b/src/preferences/virtualmemory/SettingsWindow.h index f481988334..22163e7379 100644 --- a/src/preferences/virtualmemory/SettingsWindow.h +++ b/src/preferences/virtualmemory/SettingsWindow.h @@ -30,6 +30,7 @@ class SettingsWindow : public BWindow { BCheckBox* fSwapEnabledCheckBox; BSlider* fSizeSlider; + BButton* fDefaultsButton; BButton* fRevertButton; BStringView* fWarningStringView;