Committing patch by Justin O'Dell to fix the Defaults buttons on several

preferences apps. This fixes most of bug #254.

This is his first contribution to Haiku, and hopefully the first of many.

Thanks Justin!


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21992 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ryan Leavengood 2007-08-17 03:45:37 +00:00
parent 9d6482b1fd
commit 3f64fbd011
17 changed files with 136 additions and 35 deletions

View File

@ -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(&current_family, &current_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()
{

View File

@ -34,6 +34,7 @@ class FontSelectionView : public BView {
void SetDefaults();
void Revert();
bool IsDefaultable();
bool IsRevertable();
void UpdateFontsMenu();

View File

@ -93,6 +93,13 @@ FontView::RelayoutIfNeeded()
fFixedView->RelayoutIfNeeded();
}
bool
FontView::IsDefaultable()
{
return fPlainView->IsDefaultable()
|| fBoldView->IsDefaultable()
|| fFixedView->IsDefaultable();
}
bool
FontView::IsRevertable()

View File

@ -25,6 +25,7 @@ class FontView : public BView {
void UpdateFonts();
void RelayoutIfNeeded();
bool IsDefaultable();
bool IsRevertable();
private:

View File

@ -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;

View File

@ -33,6 +33,7 @@ class MainWindow : public BWindow {
BMessageRunner* fRunner;
FontView* fFontsView;
BButton* fDefaultsButton;
BButton* fRevertButton;
FontsSettings fSettings;

View File

@ -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;
}

View File

@ -21,6 +21,7 @@ public :
void Dump();
void Revert();
void Defaults();
bool IsDefaultable();
BPoint WindowCorner() const { return fCorner; }
void SetWindowCorner(BPoint corner);

View File

@ -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);

View File

@ -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
*/

View File

@ -30,6 +30,7 @@ class MouseSettings {
void Revert();
void Defaults();
bool IsDefaultable();
void Dump();
BPoint WindowPosition() const { return fWindowPosition; }

View File

@ -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);
}

View File

@ -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;
};

View File

@ -204,6 +204,14 @@ Settings::RevertSwapChanges()
}
bool
Settings::IsDefaultable()
{
return fSwapEnabled != fInitialSwapEnabled
|| fSwapSize != fInitialSwapSize;
}
bool
Settings::SwapChanged()
{

View File

@ -27,6 +27,7 @@ class Settings {
void SetSwapDefaults();
void RevertSwapChanges();
bool IsDefaultable();
bool SwapChanged();
private:

View File

@ -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);

View File

@ -30,6 +30,7 @@ class SettingsWindow : public BWindow {
BCheckBox* fSwapEnabledCheckBox;
BSlider* fSizeSlider;
BButton* fDefaultsButton;
BButton* fRevertButton;
BStringView* fWarningStringView;