Revised the code, to be cleaner

added a rdef file


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8713 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2004-08-29 16:28:21 +00:00
parent 6106f25494
commit 76dd4cf399
8 changed files with 330 additions and 174 deletions

View File

@ -1,7 +1,11 @@
SubDir OBOS_TOP src prefs keyboard ;
AddResources Keyboard : Keyboard.rsrc ;
AddResources Keyboard : Keyboard.rdef ;
Preference Keyboard : Keyboard.cpp KeyboardSettings.cpp KeyboardView.cpp KeyboardWindow.cpp ;
LinkSharedOSLibs Keyboard : translation be root ;
Preference Keyboard :
Keyboard.cpp
KeyboardSettings.cpp
KeyboardView.cpp
KeyboardWindow.cpp
: translation be
;

View File

@ -1,15 +1,14 @@
/*
* Keyboard.cpp
* Keyboard mccall@digitalparadise.co.uk
*
*/
** Copyright 2004, the Haiku project. All rights reserved.
** Distributed under the terms of the Haiku License.
**
** Author : mccall@digitalparadise.co.uk, Jérôme Duval
*/
#include <Alert.h>
#include <Screen.h>
#include "Keyboard.h"
#include "KeyboardWindow.h"
#include "KeyboardSettings.h"
#include "KeyboardMessages.h"
const char KeyboardApplication::kKeyboardApplicationSig[] = "application/x-vnd.OpenBeOS-KYBD";
@ -27,12 +26,7 @@ KeyboardApplication::KeyboardApplication()
:BApplication(kKeyboardApplicationSig)
{
KeyboardWindow *window;
fSettings = new KeyboardSettings();
window = new KeyboardWindow();
new KeyboardWindow();
}
void
@ -52,31 +46,9 @@ KeyboardApplication::MessageReceived(BMessage *message)
}
}
void
KeyboardApplication::SetWindowCorner(BPoint corner)
{
fSettings->SetWindowCorner(corner);
}
void
KeyboardApplication::SetKeyboardRepeatRate(int32 rate)
{
fSettings->SetKeyboardRepeatRate(rate);
}
void
KeyboardApplication::SetKeyboardRepeatDelay(int32 rate)
{
fSettings->SetKeyboardRepeatDelay(rate);
}
void
KeyboardApplication::AboutRequested(void)
{
(new BAlert("about", "...by Andrew Edward McCall", "Dig Deal"))->Go();
}
KeyboardApplication::~KeyboardApplication()
{
delete fSettings;
}

View File

@ -1,33 +1,25 @@
/*
** Copyright 2004, the Haiku project. All rights reserved.
** Distributed under the terms of the Haiku License.
**
** Author : mccall@digitalparadise.co.uk, Jérôme Duval
*/
#ifndef KEYBOARD_H
#define KEYBOARD_H
#include <Application.h>
#include "KeyboardWindow.h"
#include "KeyboardSettings.h"
class KeyboardApplication : public BApplication
{
public:
KeyboardApplication();
virtual ~KeyboardApplication();
void MessageReceived(BMessage *message);
BPoint WindowCorner() const {return fSettings->WindowCorner(); }
void SetWindowCorner(BPoint corner);
int32 KeyboardRepeatRate() const {return fSettings->KeyboardRepeatRate(); }
void SetKeyboardRepeatRate(int32 rate);
int32 KeyboardRepeatDelay() const {return fSettings->KeyboardRepeatDelay(); }
void SetKeyboardRepeatDelay(int32 rate);
void AboutRequested(void);
private:
static const char kKeyboardApplicationSig[];
KeyboardSettings *fSettings;
};
#endif

View File

@ -0,0 +1,149 @@
resource app_signature "application/x-vnd.Haiku-KeyboardPrefs";
resource app_version
{
short_info = "Keyboard",
long_info = "Haiku Keyboard Preferences"
};
resource app_flags B_SINGLE_LAUNCH;
resource large_icon
{
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFF000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFFFFFFFFFF001B1C1B0000FFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFFFFFFFF001B151C3F1B1C0000FFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFFFFFF001B151C1C0F1B1C1B1C0000FFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFFFF001B151C1C00151C1B1C1B1C1C00FFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFF001B151C1C1B0000001C1C1B1C3F0E00FFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFF003F3F15151C1B1C15001C1B3F0E0F00FFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFF003F153F3F15151C001B1C3F0E0F0F00FFFFFFFFFFFFFF"
$"FFFFFFFFFFFF0000003F151515163F3F15151C3F0E0F0F0F0F00FFFFFFFFFFFF"
$"FFFFFFFFFF001B1C1B000016151515163F3F3F0E0F0F0F0F0F00FFFFFFFFFFFF"
$"FFFFFFFF001B151C1C1B1C000015151615150F0F0F0000000F00FFFFFFFFFFFF"
$"FFFFFF001B151C00001C1B1C1C00001515150F0F001C1B1C0000FFFFFFFFFFFF"
$"FFFF001B151C1C001B00001C1C1B1C0000150F001C151B1C1C1B0000FFFFFFFF"
$"FF001B151C1C1B1C001C1B1C1B1C007B7B00001C151C00001B1C1B1C0000FFFF"
$"FF003F3F15151C1B001C1C1B1C3F00DA7B7B00151C003F001B001C1B1C1C00FF"
$"FF003F153F3F15151C1B1C1C3F002B2CDA7B001B1C1C1B00001C1B1C1C3F0E00"
$"003F151515163F3F15151C3F0E002B2FEB003F15151C1B001C1C1B1C3F0E0F00"
$"003F1515151615153F3F3F0E002B2B2F2F00163F3F15151C1B1C1C3F0E0F0F00"
$"003F15151516151515160E0F002B2F2F00161515153F3F15151C3F0E0F0F0F00"
$"003F15151516151515160E002B2B2F2F001615151516153F3F3F0E0F0F0F0F00"
$"003F15151500000016150F002B2F2F003F15151516151515160E0F0F0F0F0F00"
$"FF000015007B7B7B0015002B2B2F2F003F15151516151515160E0F0F0F0F0F00"
$"FFFFFF007B7B7BDA0015002B2F2F00003F15151516151515160E0F0F0F0F00FF"
$"FFFFFF002B2CDA7B7B002B2CEB2F00FF0000151515161515150F0F0F0F00FFFF"
$"FFFFFFFF002B2CDA7B2B2CEB2F00FFFFFFFF000015151516150F0F0E00FFFFFF"
$"FFFFFFFF002B2CDA7B2B2CEB2F00FFFFFFFFFFFF00001515150F0F00FFFFFFFF"
$"FFFFFFFFFF002B2C2B2B2F2F00FFFFFFFFFFFFFFFFFF0000150F00FFFFFFFFFF"
$"FFFFFFFFFF002B2C2B2B2F2F00FFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF"
$"FFFFFFFFFFFF002B2CEB2F00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFF002B2CEB2F00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFF002B2F000E0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFF0000000E0F0F0F0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
};
resource mini_icon
{
$"FFFFFFFFFFFFFF0000FFFFFFFFFFFFFF"
$"FFFFFFFFFFFF001B1C0000FFFFFFFFFF"
$"FFFFFFFFFF001B1C1B1C1C0000FFFFFF"
$"FFFFFFFF00153F3F1B1C0F0F00FFFFFF"
$"FFFF00001B0015163F0E0F0F00FFFFFF"
$"FF001B1C1B1C0000150F000000FFFFFF"
$"003F3F1B1C1B1C0000001C1B1C0000FF"
$"0015153F3F1B007B001C1B1C1C1B1C00"
$"00151516150F002F003F1B1C1B1C0F00"
$"0015151615002F0015153F3F1B0F0F00"
$"0000000000002F00151516150F0F0F00"
$"FF002B00002F0000001515150F0F0000"
$"FF002B7B2CEB00FFFF0000150F0000FF"
$"FFFF002B2F0000FFFFFFFF000000FFFF"
$"FFFF002B2F00FFFFFFFFFFFFFFFFFFFF"
$"FFFFFF00000E0F0FFFFFFFFFFFFFFFFF"
};
resource file_types message;
resource(601, "key_bmap") #'bits' array
{
$"424D14050000000000003A000000280000001100000012000000010018000000"
$"0000DA040000130B0000130B00000000F0420000F042FFFFFFFFD8D8D8D8D8D8"
$"D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8000000000000D8D8D8D8D8"
$"D8D8D8D8D8D8D8D8D8D8D8D8D800D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8"
$"D8D8D8000000000000A8A8A8787878000000D8D8D8D8D8D8D8D8D8D8D8D8D8D8"
$"D800D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8000000000000A8A8A8A8A8A8A8A8A8"
$"787878787878000000D8D8D8D8D8D8D8D8D8D8D8D800D8D8D8D8D8D8D8D8D800"
$"0000000000A8A8A8A8A8A8A8A8A8A8A8A8A8A8A8787878787878787878000000"
$"D8D8D8D8D8D8D8D8D800D8D8D8000000000000A8A8A8A8A8A8A8A8A8A8A8A8A8"
$"A8A8A8A8A8A8A8A8787878787878787878787878000000D8D8D8D8D8D8000000"
$"00FFFFFFA8A8A8A8A8A8A8A8A8A8A8A8A8A8A8A8A8A8A8A8A8A8A8A878787878"
$"7878787878787878787878000000D8D8D800000000FFFFFFA8A8A8A8A8A8A8A8"
$"A8A8A8A8A8A8A8A8A8A8A8A8A8A8A8A878787878787878787878787887878787"
$"878700000000000000FFFFFFA8A8A8A8A8A8A8A8A8A8A8A8A8A8A8A8A8A8A8A8"
$"A8A8A8A878787878787878787878787878787878787800000000000000FFFFFF"
$"A8A8A8A8A8A8A8A8A8A8A8A8A8A8A8A8A8A8FFFFFFFFFFFFFFFFFF7878787878"
$"7878787878787878787800000000000000FFFFFFA8A8A8A8A8A8A8A8A8A8A8A8"
$"FFFFFFFFFFFFA8A8A8A8A8A8E0E0E0FFFFFF7878787878787878787878780000"
$"0000D8D8D8000000FFFFFFA8A8A8FFFFFFFFFFFFA8A8A8A8A8A8E0E0E0000000"
$"D8D8D8E0E0E0FFFFFF78787878787878787800000000D8D8D8000000FFFFFFFF"
$"FFFFA8A8A8A8A8A8E0E0E0D8D8D8E0E0E0A8A8A8000000E0E0E0E0E0E0FFFFFF"
$"78787878787800000000D8D8D8000000D8D8D8A8A8A8E0E0E0E0E0E0D8D8D800"
$"0000000000000000E0E0E0E0E0E0D8D8D8E0E0E0FFFFFF78787800000000D8D8"
$"D8D8D8D8000000D8D8D8A8A8A8E0E0E0E0E0E0000000A8A8A8E0E0E0D8D8D8E0"
$"E0E0D8D8D8E0E0E0E0E0E0000000D8D8D800D8D8D8D8D8D8D8D8D8000000D8D8"
$"D8A8A8A8E0E0E0E0E0E0787878D8D8D8E0E0E0D8D8D8E0E0E0000000000000D8"
$"D8D8D8D8D800D8D8D8D8D8D8D8D8D8D8D8D8000000D8D8D8A8A8A8E0E0E0FFFF"
$"FFD8D8D8E0E0E0000000000000D8D8D8D8D8D8D8D8D8D8D8D800D8D8D8D8D8D8"
$"D8D8D8D8D8D8D8D8D8000000D8D8D8E0E0E0D8D8D8000000000000D8D8D8D8D8"
$"D8D8D8D8D8D8D8D8D8D8D8D8D800D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8"
$"000000000000000000D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8"
$"D800000008428E0000FF0000114300000C420000114300004842008E00FF0000"
$"114300004C42000011430000844200008EFF0000124300000040000012430000"
$"90418F8F8FFFF99001000000984100001243000008428F0000FF000012430000"
$"0C420000124300004842008F00FF0000124300004C4200001243000084420000"
$"8FFF00001343000000400000134300009041909090FF00001343000098410000"
$"134300000842900000FF0000134300000C420000134300004842009000FF0000"
$"134300004C420000134300008442000090FF0000144300000040000014430000"
$"9041919191FF00001443000098410000144300000842910000FF000014430000"
$"0C420000144300004842009100FF0000144300004C4200001443000084420000"
$"91FF000015430000004000001543000090419292"
};
resource(602, "clock_bmap") #'bits' array
{
$"424DEB030000000000003A000000280000000F0000000F000000010018000000"
$"0000B1030000130B0000130B00000800000008000000FFFFFFFFD8D8D8D8D8D8"
$"D8D8D8D8D8D8D8D8D8000000000000000000000000000000D8D8D8D8D8D8D8D8"
$"D8D8D8D8D8D8D8000000D8D8D8D8D8D8D8D8D800000000000080808080808080"
$"8080808080808080000000000000D8D8D8D8D8D8D8D8D8000000D8D8D8D8D8D8"
$"000000B8B8B8B8B8B8B8B8B8B8B8B8B8B8B8B8B8B8B8B8B88080808080800000"
$"00D8D8D8D8D8D8000000D8D8D8000000B8B8B8B8B8B8B8B8B880808080808080"
$"8080808080808080B8B8B8B8B8B8808080000000D8D8D8000000D8D8D8000000"
$"B8B8B8B8B8B8808080FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF808080B8B8B88080"
$"80000000D8D8D8000000000000FFFFFFB8B8B8808080FFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFFFFFF808080B8B8B8808080000000000000000000FFFFFF"
$"B8B8B8808080FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF808080B8B8"
$"B8808080000000000000000000FFFFFFB8B8B8808080FFFFFFFFFFFFFFFFFF00"
$"0000000000FFFFFFFFFFFF808080B8B8B8808080000000000000000000FFFFFF"
$"B8B8B8808080FFFFFFFFFFFFFFFFFF000000FFFFFFFFFFFFFFFFFF808080B8B8"
$"B8808080000000000000000000FFFFFFB8B8B8808080FFFFFFFFFFFFFFFFFF00"
$"0000FFFFFFFFFFFFFFFFFF808080B8B8B8808080000000000000D8D8D8000000"
$"FFFFFFB8B8B8808080FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF808080B8B8B8B8B8"
$"B8000000D8D8D8000000D8D8D8000000FFFFFFB8B8B8B8B8B880808080808080"
$"8080808080808080B8B8B8B8B8B8B8B8B8000000D8D8D8000000D8D8D8D8D8D8"
$"000000FFFFFFFFFFFFB8B8B8B8B8B8B8B8B8B8B8B8B8B8B8B8B8B8B8B8B80000"
$"00D8D8D8D8D8D8000000D8D8D8D8D8D8D8D8D8000000000000FFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFF000000000000D8D8D8D8D8D8D8D8D8000000D8D8D8D8D8D8"
$"D8D8D8D8D8D8D8D8D8000000000000000000000000000000D8D8D8D8D8D8D8D8"
$"D8D8D8D8D8D8D800000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000804000008040000140000000505"
$"0000A504070085050000A40404000D000000000000000000000063000100A404"
$"0400FFFFFFFF61000100FFFFFFFF0B4D01000100000000000000000000000000"
$"0000000000000000000000"
};

View File

@ -1,8 +1,9 @@
/*
* KeyboardSettings.cpp
* Keyboard mccall@digitalparadise.co.uk
*
*/
** Copyright 2004, the Haiku project. All rights reserved.
** Distributed under the terms of the Haiku License.
**
** Author : mccall@digitalparadise.co.uk, Jérôme Duval
*/
#include <Application.h>
#include <FindDirectory.h>
@ -18,6 +19,12 @@ const char KeyboardSettings::kKeyboardSettingsFile[] = "Keyboard_settings";
KeyboardSettings::KeyboardSettings()
{
get_key_repeat_rate(&fSettings.key_repeat_rate);
get_key_repeat_delay(&fSettings.key_repeat_delay);
fCorner.x = 50;
fCorner.y = 50;
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) == B_OK) {
@ -25,27 +32,16 @@ KeyboardSettings::KeyboardSettings()
BFile file(path.Path(), B_READ_ONLY);
if (file.InitCheck() == B_OK) {
// Now read in the data
if (file.Read(&fSettings, sizeof(kb_settings)) != sizeof(kb_settings)) {
fSettings.key_repeat_delay=200;
fSettings.key_repeat_rate=250000;
}
if (file.Read(&fCorner, sizeof(BPoint)) != sizeof(BPoint)) {
fCorner.x=50;
fCorner.y=50;
};
file.ReadAt(sizeof(kb_settings), &fCorner, sizeof(BPoint));
}
else {
fCorner.x=50;
fCorner.y=50;
fSettings.key_repeat_delay=200;
fSettings.key_repeat_rate=250000;
}
}
else
be_app->PostMessage(ERROR_DETECTED);
} else
be_app->PostMessage(ERROR_DETECTED);
fOriginalSettings = fSettings;
}
KeyboardSettings::~KeyboardSettings()
{
BPath path;
@ -57,27 +53,55 @@ KeyboardSettings::~KeyboardSettings()
BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE);
if (file.InitCheck() == B_OK) {
file.Write(&fSettings, sizeof(kb_settings));
file.Write(&fCorner, sizeof(BPoint));
file.WriteAt(sizeof(kb_settings), &fCorner, sizeof(BPoint));
}
}
void
KeyboardSettings::SetWindowCorner(BPoint corner)
{
fCorner=corner;
fCorner = corner;
}
void
KeyboardSettings::SetKeyboardRepeatRate(int32 rate)
{
fSettings.key_repeat_rate=rate;
set_key_repeat_rate(rate);
fSettings.key_repeat_rate = rate;
}
void
KeyboardSettings::SetKeyboardRepeatDelay(int32 rate)
KeyboardSettings::SetKeyboardRepeatDelay(bigtime_t delay)
{
fSettings.key_repeat_delay=rate;
set_key_repeat_delay(delay);
fSettings.key_repeat_delay = delay;
}
void
KeyboardSettings::Dump()
{
printf("repeat rate: %ld\n", fSettings.key_repeat_rate);
printf("repeat delay: %Ld\n", fSettings.key_repeat_delay);
}
void
KeyboardSettings::Revert()
{
SetKeyboardRepeatDelay(fOriginalSettings.key_repeat_delay);
SetKeyboardRepeatRate(fOriginalSettings.key_repeat_rate);
}
void
KeyboardSettings::Defaults()
{
SetKeyboardRepeatDelay(250000);
SetKeyboardRepeatRate(200);
}

View File

@ -1,3 +1,10 @@
/*
** Copyright 2004, the Haiku project. All rights reserved.
** Distributed under the terms of the Haiku License.
**
** Author : mccall@digitalparadise.co.uk, Jérôme Duval
*/
#ifndef KEYBOARD_SETTINGS_H_
#define KEYBOARD_SETTINGS_H_
@ -13,17 +20,26 @@ public :
KeyboardSettings();
~KeyboardSettings();
void Dump();
void Revert();
void Defaults();
BPoint WindowCorner() const { return fCorner; }
void SetWindowCorner(BPoint corner);
int32 KeyboardRepeatRate() const { return fSettings.key_repeat_rate; }
int32 KeyboardRepeatRate() const
{ return fSettings.key_repeat_rate; }
void SetKeyboardRepeatRate(int32 rate);
int32 KeyboardRepeatDelay() const { return fSettings.key_repeat_delay; }
void SetKeyboardRepeatDelay(int32 rate);
bigtime_t KeyboardRepeatDelay() const
{ return fSettings.key_repeat_delay; }
void SetKeyboardRepeatDelay(bigtime_t delay);
private:
static const char kKeyboardSettingsFile[];
BPoint fCorner;
kb_settings fSettings;
kb_settings fOriginalSettings;
};
#endif

View File

@ -1,73 +1,63 @@
/*
* KeyboardWindow.cpp
* Keyboard mccall@digitalparadise.co.uk
*
*/
#include <Application.h>
#include <TextControl.h>
#include <Message.h>
** Copyright 2004, the Haiku project. All rights reserved.
** Distributed under the terms of the Haiku License.
**
** Author : mccall@digitalparadise.co.uk, Jérôme Duval
*/
#include <Button.h>
#include <Slider.h>
#include <Message.h>
#include <Screen.h>
#include <stdio.h>
#include <Slider.h>
#include <TextControl.h>
#include "KeyboardMessages.h"
#include "KeyboardWindow.h"
#include "KeyboardView.h"
#include "Keyboard.h"
#define KEYBOARD_WINDOW_RIGHT 229
#define KEYBOARD_WINDOW_BOTTTOM 221
KeyboardWindow::KeyboardWindow()
: BWindow(BRect(0,0,KEYBOARD_WINDOW_RIGHT,KEYBOARD_WINDOW_BOTTTOM), "Keyboard", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE )
{
BScreen screen;
BSlider *slider=NULL;
MoveTo(dynamic_cast<KeyboardApplication *>(be_app)->WindowCorner());
: BWindow(BRect(0,0,KEYBOARD_WINDOW_RIGHT,KEYBOARD_WINDOW_BOTTTOM), "Keyboard",
B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE )
{
MoveTo(fSettings.WindowCorner());
// Code to make sure that the window doesn't get drawn off screen...
BScreen screen;
if (!(screen.Frame().right >= Frame().right && screen.Frame().bottom >= Frame().bottom))
MoveTo((screen.Frame().right-Bounds().right)*.5,(screen.Frame().bottom-Bounds().bottom)*.5);
BuildView();
fView = new KeyboardView(Bounds());
AddChild(fView);
slider = (BSlider *)FindView("key_repeat_rate");
if (slider !=NULL) slider->SetValue(dynamic_cast<KeyboardApplication *>(be_app)->KeyboardRepeatRate());
printf("On start repeat rate: %ld\n", dynamic_cast<KeyboardApplication *>(be_app)->KeyboardRepeatRate());
BSlider *slider = (BSlider *)FindView("key_repeat_rate");
if (slider !=NULL)
slider->SetValue(fSettings.KeyboardRepeatRate());
slider = (BSlider *)FindView("delay_until_key_repeat");
if (slider !=NULL) slider->SetValue(dynamic_cast<KeyboardApplication *>(be_app)->KeyboardRepeatDelay());
printf("On start repeat delay: %ld\n", dynamic_cast<KeyboardApplication *>(be_app)->KeyboardRepeatDelay());
if (slider !=NULL)
slider->SetValue(fSettings.KeyboardRepeatDelay());
#ifdef DEBUG
fSettings.Dump();
#endif
Show();
}
void
KeyboardWindow::BuildView()
{
fView = new KeyboardView(Bounds());
}
bool
KeyboardWindow::QuitRequested()
{
BSlider *slider=NULL;
dynamic_cast<KeyboardApplication *>(be_app)->SetWindowCorner(BPoint(Frame().left,Frame().top));
fSettings.SetWindowCorner(Frame().LeftTop());
slider = (BSlider *)FindView("key_repeat_rate");
if (slider !=NULL) dynamic_cast<KeyboardApplication *>(be_app)->SetKeyboardRepeatRate(slider->Value());
printf("On quit repeat rate: %ld\n", dynamic_cast<KeyboardApplication *>(be_app)->KeyboardRepeatRate());
#ifdef DEBUG
fSettings.Dump();
#endif
slider = (BSlider *)FindView("delay_until_key_repeat");
if (slider !=NULL) dynamic_cast<KeyboardApplication *>(be_app)->SetKeyboardRepeatDelay(slider->Value());
printf("On quit repeat delay: %ld\n", dynamic_cast<KeyboardApplication *>(be_app)->KeyboardRepeatDelay());
be_app->PostMessage(B_QUIT_REQUESTED);
return(true);
@ -81,65 +71,73 @@ KeyboardWindow::MessageReceived(BMessage *message)
switch(message->what) {
case BUTTON_DEFAULTS:{
if (set_key_repeat_rate(200)!=B_OK)
be_app->PostMessage(ERROR_DETECTED);
slider = (BSlider *)FindView("key_repeat_rate");
if (slider !=NULL) slider->SetValue(200);
if (set_key_repeat_delay(250000)!=B_OK)
be_app->PostMessage(ERROR_DETECTED);
slider = (BSlider *)FindView("delay_until_key_repeat");
if (slider !=NULL) slider->SetValue(250000);
button = (BButton *)FindView("keyboard_revert");
if (button !=NULL) button->SetEnabled(true);
fSettings.Defaults();
slider = (BSlider *)FindView("key_repeat_rate");
if (slider !=NULL)
slider->SetValue(fSettings.KeyboardRepeatRate());
slider = (BSlider *)FindView("delay_until_key_repeat");
if (slider !=NULL)
slider->SetValue(fSettings.KeyboardRepeatDelay());
button = (BButton *)FindView("keyboard_revert");
if (button !=NULL)
button->SetEnabled(true);
}
break;
case BUTTON_REVERT:{
if (set_key_repeat_rate(dynamic_cast<KeyboardApplication *>(be_app)->KeyboardRepeatRate())!=B_OK)
be_app->PostMessage(ERROR_DETECTED);
slider = (BSlider *)FindView("key_repeat_rate");
if (slider !=NULL) slider->SetValue(dynamic_cast<KeyboardApplication *>(be_app)->KeyboardRepeatRate());
if (set_key_repeat_delay(dynamic_cast<KeyboardApplication *>(be_app)->KeyboardRepeatDelay())!=B_OK)
be_app->PostMessage(ERROR_DETECTED);
slider = (BSlider *)FindView("delay_until_key_repeat");
if (slider !=NULL) slider->SetValue(dynamic_cast<KeyboardApplication *>(be_app)->KeyboardRepeatDelay());
button = (BButton *)FindView("keyboard_revert");
if (button !=NULL) button->SetEnabled(false);
fSettings.Revert();
slider = (BSlider *)FindView("key_repeat_rate");
if (slider !=NULL)
slider->SetValue(fSettings.KeyboardRepeatRate());
slider = (BSlider *)FindView("delay_until_key_repeat");
if (slider !=NULL)
slider->SetValue(fSettings.KeyboardRepeatDelay());
button = (BButton *)FindView("keyboard_revert");
if (button !=NULL)
button->SetEnabled(false);
}
break;
case SLIDER_REPEAT_RATE:{
if (set_key_repeat_rate(message->FindInt32("be:value"))!=B_OK)
be_app->PostMessage(ERROR_DETECTED);
button = (BButton *)FindView("keyboard_revert");
if (button !=NULL) button->SetEnabled(true);
int32 rate;
if (message->FindInt32("be:value", &rate)!=B_OK)
break;
fSettings.SetKeyboardRepeatRate(rate);
button = (BButton *)FindView("keyboard_revert");
if (button !=NULL)
button->SetEnabled(true);
}
break;
case SLIDER_DELAY_RATE:{
bigtime_t rate;
rate=message->FindInt32("be:value");
int32 delay;
if (message->FindInt32("be:value", &delay)!=B_OK)
break;
// 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 (rate < 375000)
rate = 250000;
if ((rate >= 375000)&&(rate < 625000))
rate = 500000;
if ((rate >= 625000)&&(rate < 875000))
rate = 750000;
if (rate >= 875000)
rate = 1000000;
if (delay < 375000)
delay = 250000;
if ((delay >= 375000)&&(delay < 625000))
delay = 500000;
if ((delay >= 625000)&&(delay < 875000))
delay = 750000;
if (delay >= 875000)
delay = 1000000;
if (set_key_repeat_delay(rate)!=B_OK)
be_app->PostMessage(ERROR_DETECTED);
slider = (BSlider *)FindView("delay_until_key_repeat");
if (slider !=NULL) slider->SetValue(rate);
fSettings.SetKeyboardRepeatDelay(delay);
slider = (BSlider *)FindView("delay_until_key_repeat");
if (slider !=NULL)
slider->SetValue(delay);
button = (BButton *)FindView("keyboard_revert");
if (button !=NULL) button->SetEnabled(true);
if (button !=NULL)
button->SetEnabled(true);
}
break;
default:
@ -148,8 +146,3 @@ KeyboardWindow::MessageReceived(BMessage *message)
}
}
KeyboardWindow::~KeyboardWindow()
{
}

View File

@ -1,3 +1,10 @@
/*
** Copyright 2004, the Haiku project. All rights reserved.
** Distributed under the terms of the Haiku License.
**
** Author : mccall@digitalparadise.co.uk, Jérôme Duval
*/
#ifndef KEYBOARD_WINDOW_H
#define KEYBOARD_WINDOW_H
@ -10,15 +17,14 @@ class KeyboardWindow : public BWindow
{
public:
KeyboardWindow();
~KeyboardWindow();
bool QuitRequested();
void MessageReceived(BMessage *message);
void BuildView();
private:
KeyboardView *fView;
KeyboardSettings fSettings;
};
#endif