Now uses MouseView::SetRevertable() instead of accessing the member

variable directly.
Broken settings no longer quit the app.
Many style fixes.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5945 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2004-01-06 22:03:30 +00:00
parent e9cc36ba1a
commit eb8423f435
2 changed files with 66 additions and 47 deletions

View File

@ -12,6 +12,7 @@
// Created : December 10, 2003
//
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
#include <Alert.h>
#include <Application.h>
#include <Message.h>
@ -28,12 +29,13 @@
#include "MouseWindow.h"
#include "MouseView.h"
MouseWindow::MouseWindow(BRect rect)
: BWindow(rect, "Mouse", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE )
: BWindow(rect, "Mouse", B_TITLED_WINDOW,
B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS)
{
AddChild(fView = new MouseView(Bounds()));
if(fSettings.InitCheck() != B_OK)
PostMessage(ERROR_DETECTED);
SetPulseRate(100000);
}
@ -41,18 +43,19 @@ MouseWindow::MouseWindow(BRect rect)
bool
MouseWindow::QuitRequested()
{
fSettings.SetWindowCorner(Frame().LeftTop());
fSettings.SetWindowPosition(Frame().LeftTop());
be_app->PostMessage(B_QUIT_REQUESTED);
return(true);
return true;
}
void
MouseWindow::MessageReceived(BMessage *message)
{
switch(message->what) {
switch (message->what) {
case BUTTON_DEFAULTS: {
// reverts to default settings
fView->dcSpeedSlider->SetValue(500);
fView->dcSpeedSlider->Invoke();
fView->mouseSpeedSlider->SetValue(500);
@ -67,11 +70,13 @@ MouseWindow::MessageReceived(BMessage *message)
fView->fCurrentMouseMap.button[1] = B_SECONDARY_MOUSE_BUTTON;
fView->fCurrentMouseMap.button[2] = B_TERTIARY_MOUSE_BUTTON;
set_mouse_map(&fView->fCurrentMouseMap);
fView->revertButton->SetEnabled(true);
fView->SetRevertable(true);
break;
}
break;
case BUTTON_REVERT: {
// revert to last settings
fView->Init();
set_mouse_type(fView->fMouseType);
set_mouse_mode(fView->fMouseMode);
@ -80,17 +85,20 @@ MouseWindow::MessageReceived(BMessage *message)
set_mouse_acceleration(fView->fMouseAcc);
set_mouse_map(&fView->fMouseMap);
get_mouse_map(&fView->fCurrentMouseMap);
fView->revertButton->SetEnabled(false);
fView->SetRevertable(false);
break;
}
break;
case POPUP_MOUSE_TYPE: {
status_t err = set_mouse_type(fView->mouseTypeMenu->IndexOf(fView->mouseTypeMenu->FindMarked())+1);
if(err < B_OK)
if (err < B_OK)
printf("error while setting mouse type : %s\n", strerror(err));
fView->revertButton->SetEnabled(true);
fView->SetRevertable(true);
break;
}
break;
case POPUP_MOUSE_FOCUS: {
mode_mouse mouse_mode = B_NORMAL_MOUSE;
switch (fView->focusMenu->IndexOf(fView->focusMenu->FindMarked())) {
@ -100,39 +108,47 @@ MouseWindow::MessageReceived(BMessage *message)
case 3: mouse_mode = B_INSTANT_WARP_MOUSE; break;
}
set_mouse_mode(mouse_mode);
fView->revertButton->SetEnabled(true);
fView->SetRevertable(true);
break;
}
break;
case SLIDER_DOUBLE_CLICK_SPEED: {
int32 value = fView->dcSpeedSlider->Value();
int32 click_speed; // slow = 1000000, fast = 0
click_speed = (int32) (1000000 - value * 1000);
status_t err = set_click_speed(click_speed);
if(err < B_OK)
if (err < B_OK)
printf("error while setting click speed : %s\n", strerror(err));
fView->revertButton->SetEnabled(true);
fView->SetRevertable(true);
break;
}
break;
case SLIDER_MOUSE_SPEED: {
int32 value = fView->mouseSpeedSlider->Value();
int32 mouse_speed; // slow = 8192, fast = 524287
mouse_speed = (int32) pow(2, value * 6 / 1000) * 8192;
status_t err = set_mouse_speed(mouse_speed);
if(err < B_OK)
if (err < B_OK)
printf("error while setting mouse speed : %s\n", strerror(err));
fView->revertButton->SetEnabled(true);
fView->SetRevertable(true);
break;
}
break;
case SLIDER_MOUSE_ACC: {
int32 value = fView->mouseAccSlider->Value();
int32 mouse_acc; // slow = 0, fast = 262144
mouse_acc = (int32) pow(value * 4 / 1000, 2) * 16384;
status_t err = set_mouse_acceleration(mouse_acc);
if(err < B_OK)
if (err < B_OK)
printf("error while setting mouse acceleration : %s\n", strerror(err));
fView->revertButton->SetEnabled(true);
fView->SetRevertable(true);
break;
}
break;
case POPUP_MOUSE_MAP: {
int32 index = fView->mouseMapMenu->IndexOf(fView->mouseMapMenu->FindMarked());
int32 number = B_PRIMARY_MOUSE_BUTTON;
@ -144,20 +160,22 @@ MouseWindow::MessageReceived(BMessage *message)
fView->fCurrentMouseMap.button[fView->fCurrentButton] = number;
status_t err = set_mouse_map(&fView->fCurrentMouseMap);
fView->fCurrentButton = -1;
if(err < B_OK)
if (err < B_OK)
printf("error while setting mouse map : %s\n", strerror(err));
fView->revertButton->SetEnabled(true);
fView->SetRevertable(true);
break;
}
break;
case ERROR_DETECTED: {
(new BAlert("Error", "Something has gone wrong!","OK",NULL,NULL,
B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT))->Go();
be_app->PostMessage(B_QUIT_REQUESTED);
(new BAlert("Error", "Something has gone wrong!", "OK", NULL, NULL,
B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT))->Go();
be_app->PostMessage(B_QUIT_REQUESTED);
break;
}
break;
default:
BWindow::MessageReceived(message);
break;
}
}

View File

@ -20,17 +20,18 @@
#include "MouseSettings.h"
#include "MouseView.h"
class MouseWindow : public BWindow
{
public:
MouseWindow(BRect rect);
bool QuitRequested();
void MessageReceived(BMessage *message);
MouseSettings fSettings;
private:
MouseView *fView;
class MouseWindow : public BWindow {
public:
MouseWindow(BRect rect);
bool QuitRequested();
void MessageReceived(BMessage *message);
MouseSettings fSettings;
private:
MouseView *fView;
};
#endif