* Added B_ASYNCHRONOUS_CONTROLS to the window flags (smooth slider).

* Put local headers at the top, and fixed self-containment.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22027 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2007-08-21 10:32:45 +00:00
parent 8ac552e4d1
commit a6230f90a3
2 changed files with 127 additions and 111 deletions
+11 -7
View File
@@ -1,15 +1,19 @@
/* /*
* Copyright 2004-2006, the Haiku project. All rights reserved. * Copyright 2004-2007, Haiku. All rights reserved.
* Distributed under the terms of the Haiku License. * Distributed under the terms of the Haiku License.
* *
* Authors in chronological order: * Authors:
* [email protected] * Andrew McCall, [email protected]
* Jérôme Duval * Jérôme Duval
* Marcus Overhagen * Marcus Overhagen
*/ */
#ifndef KEYBOARD_MESSAGES_H #ifndef KEYBOARD_MESSAGES_H
#define KEYBOARD_MESSAGES_H #define KEYBOARD_MESSAGES_H
#include <SupportDefs.h>
const uint32 BUTTON_DEFAULTS = 'BTde'; const uint32 BUTTON_DEFAULTS = 'BTde';
const uint32 BUTTON_REVERT = 'BTre'; const uint32 BUTTON_REVERT = 'BTre';
const uint32 SLIDER_REPEAT_RATE = 'SLrr'; const uint32 SLIDER_REPEAT_RATE = 'SLrr';
@@ -17,4 +21,4 @@ const uint32 SLIDER_DELAY_RATE = 'SLdr';
const uint32 ERROR_DETECTED = 'ERor'; const uint32 ERROR_DETECTED = 'ERor';
#endif #endif // KEYBOARD_MESSAGES_H
+100 -88
View File
@@ -1,32 +1,38 @@
/* /*
* Copyright 2004-2006, the Haiku project. All rights reserved. * Copyright 2004-2007, Haiku. All rights reserved.
* Distributed under the terms of the Haiku License. * Distributed under the terms of the Haiku License.
* *
* Authors in chronological order: * Authors:
* [email protected] * Andrew McCall, [email protected]
* Jérôme Duval * Jérôme Duval
* Marcus Overhagen * Marcus Overhagen
*/ */
#include "KeyboardMessages.h"
#include "KeyboardView.h"
#include "KeyboardWindow.h"
#include <Button.h> #include <Button.h>
#include <Message.h> #include <Message.h>
#include <Screen.h> #include <Screen.h>
#include <Slider.h> #include <Slider.h>
#include <TextControl.h> #include <TextControl.h>
#include "KeyboardMessages.h"
#include "KeyboardWindow.h"
#include "KeyboardView.h"
KeyboardWindow::KeyboardWindow() KeyboardWindow::KeyboardWindow()
: BWindow(BRect(0,0,200,200), "Keyboard", B_TITLED_WINDOW, : BWindow(BRect(0, 0, 200, 200), "Keyboard", B_TITLED_WINDOW,
B_NOT_RESIZABLE | B_NOT_ZOOMABLE) B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS)
{ {
MoveTo(fSettings.WindowCorner()); MoveTo(fSettings.WindowCorner());
// Code to make sure that the window doesn't get drawn off screen... // center window if it would be off-screen
BScreen screen; BScreen screen;
if (!(screen.Frame().right >= Frame().right && screen.Frame().bottom >= Frame().bottom)) if (screen.Frame().right < Frame().right
MoveTo((screen.Frame().right-Bounds().right)*.5,(screen.Frame().bottom-Bounds().bottom)*.5); || screen.Frame().bottom < Frame().bottom) {
MoveTo((screen.Frame().right - Bounds().right) / 2,
(screen.Frame().bottom - Bounds().bottom) / 2);
}
fView = new KeyboardView(Bounds()); fView = new KeyboardView(Bounds());
AddChild(fView); AddChild(fView);
@@ -61,103 +67,109 @@ KeyboardWindow::QuitRequested()
#endif #endif
be_app->PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(B_QUIT_REQUESTED);
return true;
return(true);
} }
void void
KeyboardWindow::MessageReceived(BMessage *message) KeyboardWindow::MessageReceived(BMessage* message)
{ {
BSlider *slider=NULL; BSlider* slider = NULL;
BButton *button=NULL; BButton* button = NULL;
switch(message->what) { switch (message->what) {
case BUTTON_DEFAULTS:{ case BUTTON_DEFAULTS:
fSettings.Defaults(); {
fSettings.Defaults();
slider = (BSlider *)FindView("key_repeat_rate"); slider = (BSlider *)FindView("key_repeat_rate");
if (slider !=NULL) if (slider !=NULL)
slider->SetValue(fSettings.KeyboardRepeatRate()); slider->SetValue(fSettings.KeyboardRepeatRate());
slider = (BSlider *)FindView("delay_until_key_repeat"); slider = (BSlider *)FindView("delay_until_key_repeat");
if (slider !=NULL) if (slider !=NULL)
slider->SetValue(fSettings.KeyboardRepeatDelay()); slider->SetValue(fSettings.KeyboardRepeatDelay());
button = (BButton *)FindView("keyboard_defaults"); button = (BButton *)FindView("keyboard_defaults");
if (button !=NULL) if (button !=NULL)
button->SetEnabled(false); button->SetEnabled(false);
button = (BButton *)FindView("keyboard_revert"); button = (BButton *)FindView("keyboard_revert");
if (button !=NULL) if (button !=NULL)
button->SetEnabled(true); button->SetEnabled(true);
}
break; break;
case BUTTON_REVERT:{ }
fSettings.Revert(); case BUTTON_REVERT:
{
fSettings.Revert();
slider = (BSlider *)FindView("key_repeat_rate"); slider = (BSlider *)FindView("key_repeat_rate");
if (slider !=NULL) if (slider !=NULL)
slider->SetValue(fSettings.KeyboardRepeatRate()); slider->SetValue(fSettings.KeyboardRepeatRate());
slider = (BSlider *)FindView("delay_until_key_repeat"); slider = (BSlider *)FindView("delay_until_key_repeat");
if (slider !=NULL) if (slider !=NULL)
slider->SetValue(fSettings.KeyboardRepeatDelay()); slider->SetValue(fSettings.KeyboardRepeatDelay());
button = (BButton *)FindView("keyboard_defaults"); button = (BButton *)FindView("keyboard_defaults");
if (button !=NULL) if (button !=NULL)
button->SetEnabled(fSettings.IsDefaultable()); button->SetEnabled(fSettings.IsDefaultable());
button = (BButton *)FindView("keyboard_revert"); button = (BButton *)FindView("keyboard_revert");
if (button !=NULL) if (button !=NULL)
button->SetEnabled(false); button->SetEnabled(false);
}
break; break;
case SLIDER_REPEAT_RATE:{ }
int32 rate; case SLIDER_REPEAT_RATE:
if (message->FindInt32("be:value", &rate)!=B_OK) {
break; int32 rate;
fSettings.SetKeyboardRepeatRate(rate); if (message->FindInt32("be:value", &rate) != B_OK)
break;
fSettings.SetKeyboardRepeatRate(rate);
button = (BButton *)FindView("keyboard_defaults"); button = (BButton *)FindView("keyboard_defaults");
if (button !=NULL) if (button !=NULL)
button->SetEnabled(fSettings.IsDefaultable()); button->SetEnabled(fSettings.IsDefaultable());
button = (BButton *)FindView("keyboard_revert"); button = (BButton *)FindView("keyboard_revert");
if (button !=NULL) if (button !=NULL)
button->SetEnabled(true); button->SetEnabled(true);
}
break; break;
case SLIDER_DELAY_RATE:{ }
int32 delay; case SLIDER_DELAY_RATE:
if (message->FindInt32("be:value", &delay)!=B_OK) {
break; int32 delay;
// We need to look at the value from the slider and make it "jump" if (message->FindInt32("be:value", &delay) != B_OK)
// to the next notch along. Setting the min and max values of the break;
// slider to 1 and 4 doesn't work like the real Keyboard app.
if (delay < 375000)
delay = 250000;
if ((delay >= 375000)&&(delay < 625000))
delay = 500000;
if ((delay >= 625000)&&(delay < 875000))
delay = 750000;
if (delay >= 875000)
delay = 1000000;
fSettings.SetKeyboardRepeatDelay(delay); // We need to look at the value from the slider and make it "jump"
// to the next notch along. Setting the min and max values of the
// slider to 1 and 4 doesn't work like the real Keyboard app.
if (delay < 375000)
delay = 250000;
if (delay >= 375000 && delay < 625000)
delay = 500000;
if (delay >= 625000 && delay < 875000)
delay = 750000;
if (delay >= 875000)
delay = 1000000;
slider = (BSlider *)FindView("delay_until_key_repeat"); fSettings.SetKeyboardRepeatDelay(delay);
if (slider !=NULL)
slider->SetValue(delay);
button = (BButton *)FindView("keyboard_defaults"); slider = (BSlider *)FindView("delay_until_key_repeat");
if (button !=NULL) if (slider !=NULL)
button->SetEnabled(fSettings.IsDefaultable()); slider->SetValue(delay);
button = (BButton *)FindView("keyboard_revert"); button = (BButton *)FindView("keyboard_defaults");
if (button !=NULL) if (button !=NULL)
button->SetEnabled(true); button->SetEnabled(fSettings.IsDefaultable());
}
button = (BButton *)FindView("keyboard_revert");
if (button !=NULL)
button->SetEnabled(true);
break; break;
}
default: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
break; break;