diff --git a/src/preferences/keyboard/Jamfile b/src/preferences/keyboard/Jamfile index 6a6e2276bc..f13f0c45f5 100644 --- a/src/preferences/keyboard/Jamfile +++ b/src/preferences/keyboard/Jamfile @@ -4,7 +4,7 @@ SetSubDirSupportedPlatformsBeOSCompatible ; if $(TARGET_PLATFORM) != haiku { SubDirC++Flags -DCOMPILE_FOR_R5 ; - SubDirC++Flags -fmultiple-symbol-spaces ; +# SubDirC++Flags -fmultiple-symbol-spaces ; } UsePrivateHeaders input ; diff --git a/src/preferences/keyboard/Keyboard.cpp b/src/preferences/keyboard/Keyboard.cpp index 03fb1c0c32..b21e114d7f 100644 --- a/src/preferences/keyboard/Keyboard.cpp +++ b/src/preferences/keyboard/Keyboard.cpp @@ -1,10 +1,12 @@ /* -** 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 + * Copyright 2004-2006, the Haiku project. All rights reserved. + * Distributed under the terms of the Haiku License. + * + * Authors in chronological order: + * mccall@digitalparadise.co.uk + * Jérôme Duval + * Marcus Overhagen */ - #include #include "Keyboard.h" @@ -24,7 +26,6 @@ int main(int, char**) KeyboardApplication::KeyboardApplication() : BApplication("application/x-vnd.Haiku-KeyboardPrefs") { - new KeyboardWindow(); } @@ -32,13 +33,17 @@ void KeyboardApplication::MessageReceived(BMessage *message) { switch(message->what) { - case ERROR_DETECTED: - { - BAlert *errorAlert = new BAlert("Error", "Something has gone wrong!","OK",NULL,NULL,B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT); + case ERROR_DETECTED: { + BAlert *errorAlert = new BAlert("Error", + "Something has gone wrong!", + "OK",NULL,NULL, + B_WIDTH_AS_USUAL, + B_OFFSET_SPACING, + B_WARNING_ALERT); errorAlert->Go(); be_app->PostMessage(B_QUIT_REQUESTED); + break; } - break; default: BApplication::MessageReceived(message); break; @@ -49,5 +54,5 @@ KeyboardApplication::MessageReceived(BMessage *message) void KeyboardApplication::AboutRequested(void) { - (new BAlert("about", "...by Andrew Edward McCall", "Dig Deal"))->Go(); + (new BAlert("about", "Written by Andrew Edward McCall", "OK"))->Go(); } diff --git a/src/preferences/keyboard/Keyboard.h b/src/preferences/keyboard/Keyboard.h index b7dbcd5b32..bf98b9ea58 100644 --- a/src/preferences/keyboard/Keyboard.h +++ b/src/preferences/keyboard/Keyboard.h @@ -1,10 +1,12 @@ /* -** 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 + * Copyright 2004-2006, the Haiku project. All rights reserved. + * Distributed under the terms of the Haiku License. + * + * Authors in chronological order: + * mccall@digitalparadise.co.uk + * Jérôme Duval + * Marcus Overhagen */ - #ifndef KEYBOARD_H #define KEYBOARD_H @@ -13,11 +15,10 @@ class KeyboardApplication : public BApplication { public: - KeyboardApplication(); + KeyboardApplication(); - void MessageReceived(BMessage *message); - - void AboutRequested(void); + void MessageReceived(BMessage *message); + void AboutRequested(void); }; #endif diff --git a/src/preferences/keyboard/KeyboardMessages.h b/src/preferences/keyboard/KeyboardMessages.h index d0f5b988fd..f7b6c5d920 100644 --- a/src/preferences/keyboard/KeyboardMessages.h +++ b/src/preferences/keyboard/KeyboardMessages.h @@ -1,9 +1,12 @@ /* - - KeyboardMessages.h - + * Copyright 2004-2006, the Haiku project. All rights reserved. + * Distributed under the terms of the Haiku License. + * + * Authors in chronological order: + * mccall@digitalparadise.co.uk + * Jérôme Duval + * Marcus Overhagen */ - #ifndef KEYBOARD_MESSAGES_H #define KEYBOARD_MESSAGES_H @@ -14,4 +17,4 @@ const uint32 SLIDER_DELAY_RATE = 'SLdr'; const uint32 ERROR_DETECTED = 'ERor'; -#endif //KEYBOARD_MESSAGES_H +#endif diff --git a/src/preferences/keyboard/KeyboardSettings.cpp b/src/preferences/keyboard/KeyboardSettings.cpp index e081af767f..b1181f23b0 100644 --- a/src/preferences/keyboard/KeyboardSettings.cpp +++ b/src/preferences/keyboard/KeyboardSettings.cpp @@ -1,13 +1,12 @@ /* -** Copyright 2004-2006, the Haiku project. All rights reserved. -** Distributed under the terms of the Haiku License. -** -** Authors in chronological order: -** mccall@digitalparadise.co.uk -** Jérôme Duval -** Marcus Overhagen + * Copyright 2004-2006, the Haiku project. All rights reserved. + * Distributed under the terms of the Haiku License. + * + * Authors in chronological order: + * mccall@digitalparadise.co.uk + * Jérôme Duval + * Marcus Overhagen */ - #include #include #include @@ -33,19 +32,22 @@ KeyboardSettings::KeyboardSettings() BPath path; BFile file; - if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK) - goto err; - if (path.Append(kb_settings_file) < B_OK) - goto err; - if (file.SetTo(path.Path(), B_READ_ONLY) < B_OK) - goto err; - if (file.ReadAt(sizeof(kb_settings), &fCorner, sizeof(fCorner)) != sizeof(fCorner)) - goto err; - - return; -err: fCorner.x = 150; fCorner.y = 100; + + status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path); + if(status == B_OK) { + status = path.Append(kb_settings_file); + if(status == B_OK) { + status = file.SetTo(path.Path(), B_READ_ONLY); + if (status == B_OK) { + if(file.ReadAt(sizeof(kb_settings), &fCorner, sizeof(fCorner)) != sizeof(fCorner)) { + fCorner.x = 150; + fCorner.y = 100; + } + } + } + } } @@ -56,8 +58,10 @@ KeyboardSettings::~KeyboardSettings() if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK) return; + if (path.Append(kb_settings_file) < B_OK) return; + // be careful: don't create the file if it doesn't already exist if (file.SetTo(path.Path(), B_WRITE_ONLY) < B_OK) return; diff --git a/src/preferences/keyboard/KeyboardSettings.h b/src/preferences/keyboard/KeyboardSettings.h index d125e26b20..9ad45f8f2f 100644 --- a/src/preferences/keyboard/KeyboardSettings.h +++ b/src/preferences/keyboard/KeyboardSettings.h @@ -1,10 +1,12 @@ /* -** 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 + * Copyright 2004-2006, the Haiku project. All rights reserved. + * Distributed under the terms of the Haiku License. + * + * Authors in chronological order: + * mccall@digitalparadise.co.uk + * Jérôme Duval + * Marcus Overhagen */ - #ifndef KEYBOARD_SETTINGS_H_ #define KEYBOARD_SETTINGS_H_ diff --git a/src/preferences/keyboard/KeyboardView.cpp b/src/preferences/keyboard/KeyboardView.cpp index 671b8581c3..60b366edaa 100644 --- a/src/preferences/keyboard/KeyboardView.cpp +++ b/src/preferences/keyboard/KeyboardView.cpp @@ -1,7 +1,11 @@ /* - - KeyboardView.cpp - + * Copyright 2004-2006, the Haiku project. All rights reserved. + * Distributed under the terms of the Haiku License. + * + * Authors in chronological order: + * mccall@digitalparadise.co.uk + * Jérôme Duval + * Marcus Overhagen */ #include #include @@ -9,78 +13,120 @@ #include #include #include +#include +#include #include "KeyboardView.h" #include "KeyboardMessages.h" KeyboardView::KeyboardView(BRect rect) - : BBox(rect, "keyboard_view", - B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, - B_PLAIN_BORDER) + : BView(rect, "keyboard_view", B_FOLLOW_LEFT | B_FOLLOW_TOP, + B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP) { - BRect frame; - BButton *button; - BSlider *slider; - BTextControl *textcontrol; + BRect frame; SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); fIconBitmap = BTranslationUtils::GetBitmap("key_bmap"); fClockBitmap = BTranslationUtils::GetBitmap("clock_bmap"); + float labelwidth = StringWidth("Delay until key repeat")+20; + + font_height fontHeight; + be_plain_font->GetHeight(&fontHeight); + + float labelheight = fontHeight.ascent + fontHeight.descent + + fontHeight.leading; + + // Create the "Key repeat rate" slider... + frame.Set(10,10,10 + labelwidth,10 + (labelheight*2) + 20); + fRepeatSlider = new BSlider(frame,"key_repeat_rate", + "Key repeat rate", + new BMessage(SLIDER_REPEAT_RATE), + 20,300,B_BLOCK_THUMB, + B_FOLLOW_LEFT,B_WILL_DRAW); + fRepeatSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); + fRepeatSlider->SetHashMarkCount(5); + fRepeatSlider->SetLimitLabels("Slow","Fast"); + + + // Create the "Delay until key repeat" slider... + frame.OffsetBy(0,frame.Height() + 10); + fDelaySlider = new BSlider(frame,"delay_until_key_repeat", + "Delay until key repeat", + new BMessage(SLIDER_DELAY_RATE),250000,1000000, + B_BLOCK_THUMB,B_FOLLOW_LEFT,B_WILL_DRAW); + fDelaySlider->SetHashMarks(B_HASH_MARKS_BOTTOM); + fDelaySlider->SetHashMarkCount(4); + fDelaySlider->SetLimitLabels("Short","Long"); + + // Create the "Typing test area" text box... + frame.OffsetBy(0,frame.Height() + 15); + frame.right = fDelaySlider->Frame().right + fIconBitmap->Bounds().Width() + + 10; + BTextControl *textcontrol = new BTextControl(frame,"typing_test_area",NULL, + "Typing test area", + new BMessage('TTEA'), + B_FOLLOW_LEFT,B_WILL_DRAW); + textcontrol->SetAlignment(B_ALIGN_LEFT,B_ALIGN_CENTER); + + float width, height; + textcontrol->GetPreferredSize(&width, &height); + textcontrol->ResizeTo(frame.Width(),height); + + // Create the box for the sliders... + frame.left = frame.top = 10; + frame.right = frame.left + fDelaySlider->Frame().right + + fClockBitmap->Bounds().Width() + 20; + frame.bottom = textcontrol->Frame().bottom + 20; + fBox = new BBox(frame,"keyboard_box",B_FOLLOW_LEFT,B_WILL_DRAW, + B_FANCY_BORDER); + AddChild(fBox); + + fBox->AddChild(fRepeatSlider); + fBox->AddChild(fDelaySlider); + fBox->AddChild(textcontrol); + //Add the "Default" button.. - frame.Set(10,187,85,207); - button = new BButton(frame,"keyboard_defaults","Defaults", new BMessage(BUTTON_DEFAULTS)); + frame.left = 10; + frame.top = fBox->Frame().bottom + 10; + frame.right = frame.left + 1; + frame.bottom = frame.top + 1; + BButton *button = new BButton(frame,"keyboard_defaults","Defaults", + new BMessage(BUTTON_DEFAULTS)); + button->ResizeToPreferred(); AddChild(button); // Add the "Revert" button... - frame.Set(92,187,167,207); - button = new BButton(frame,"keyboard_revert","Revert", new BMessage(BUTTON_REVERT)); + frame = button->Frame(); + frame.OffsetBy(frame.Width() + 10, 0); + button = new BButton(frame,"keyboard_revert","Revert", + new BMessage(BUTTON_REVERT)); button->SetEnabled(false); AddChild(button); - - // Create the box for the sliders... - frame=Bounds(); - frame.left=frame.left+11; - frame.top=frame.top+12; - frame.right=frame.right-11; - frame.bottom=frame.bottom-44; - fBox = new BBox(frame,"keyboard_box",B_FOLLOW_LEFT,B_WILL_DRAW,B_FANCY_BORDER); - // Create the "Key repeat rate" slider... - frame.Set(10,10,172,50); - slider = new BSlider(frame,"key_repeat_rate","Key repeat rate", new BMessage(SLIDER_REPEAT_RATE),20,300,B_BLOCK_THUMB,B_FOLLOW_LEFT,B_WILL_DRAW); - slider->SetHashMarks(B_HASH_MARKS_BOTTOM); - slider->SetHashMarkCount(5); - slider->SetLimitLabels("Slow","Fast"); - fBox->AddChild(slider); - - // Create the "Delay until key repeat" slider... - frame.Set(10,65,172,115); - slider = new BSlider(frame,"delay_until_key_repeat","Delay until key repeat", new BMessage(SLIDER_DELAY_RATE),250000,1000000,B_BLOCK_THUMB,B_FOLLOW_LEFT,B_WILL_DRAW); - slider->SetHashMarks(B_HASH_MARKS_BOTTOM); - slider->SetHashMarkCount(4); - slider->SetLimitLabels("Short","Long"); - fBox->AddChild(slider); - - // Create the "Typing test area" text box... - frame=Bounds(); - frame.left=frame.left+10; - frame.top=135; - frame.right=frame.right-34; - frame.bottom=frame.bottom-11; - textcontrol = new BTextControl(frame,"typing_test_area",NULL,"Typing test area", new BMessage('TTEA'),B_FOLLOW_LEFT,B_WILL_DRAW); - textcontrol->SetAlignment(B_ALIGN_LEFT,B_ALIGN_CENTER); - fBox->AddChild(textcontrol); - - AddChild(fBox); - + ResizeTo(fBox->Frame().right + 10, button->Frame().bottom + 10); } -void KeyboardView::Draw(BRect updateFrame) +void +KeyboardView::Draw(BRect updateFrame) { - inherited::Draw(updateFrame); - fBox->DrawBitmap(fIconBitmap,BPoint(178,26)); - fBox->DrawBitmap(fClockBitmap,BPoint(178,83)); + BPoint pt; + pt.x = fRepeatSlider->Frame().right + 10; + pt.y = fRepeatSlider->Frame().bottom - 35 - + (fIconBitmap->Bounds().Height()/3); + + fBox->DrawBitmap(fIconBitmap,pt); + + pt.y = fDelaySlider->Frame().bottom - 35 - + (fIconBitmap->Bounds().Height()/3); + fBox->DrawBitmap(fClockBitmap,pt); } + +void +KeyboardView::AttachedToWindow(void) +{ + Window()->ResizeTo(Bounds().Width(), Bounds().Height()); +} + diff --git a/src/preferences/keyboard/KeyboardView.h b/src/preferences/keyboard/KeyboardView.h index 87df385d3b..4b38fdd484 100644 --- a/src/preferences/keyboard/KeyboardView.h +++ b/src/preferences/keyboard/KeyboardView.h @@ -1,9 +1,12 @@ /* - - KeyboardView.h - + * Copyright 2004-2006, the Haiku project. All rights reserved. + * Distributed under the terms of the Haiku License. + * + * Authors in chronological order: + * mccall@digitalparadise.co.uk + * Jérôme Duval + * Marcus Overhagen */ - #ifndef KEYBOARD_VIEW_H #define KEYBOARD_VIEW_H @@ -14,19 +17,19 @@ #include #include -class KeyboardView : public BBox +class KeyboardView : public BView { public: - typedef BBox inherited; - - KeyboardView(BRect frame); - virtual void Draw(BRect frame); - + KeyboardView(BRect frame); + void Draw(BRect frame); + void AttachedToWindow(void); + private: - BBitmap *fIconBitmap; - BBitmap *fClockBitmap; - BBox *fBox; - + BBitmap *fIconBitmap; + BBitmap *fClockBitmap; + BBox *fBox; + BSlider *fDelaySlider; + BSlider *fRepeatSlider; }; #endif diff --git a/src/preferences/keyboard/KeyboardWindow.cpp b/src/preferences/keyboard/KeyboardWindow.cpp index 763d548dce..e6f2dd0123 100644 --- a/src/preferences/keyboard/KeyboardWindow.cpp +++ b/src/preferences/keyboard/KeyboardWindow.cpp @@ -1,10 +1,12 @@ /* -** 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 + * Copyright 2004-2006, the Haiku project. All rights reserved. + * Distributed under the terms of the Haiku License. + * + * Authors in chronological order: + * mccall@digitalparadise.co.uk + * Jérôme Duval + * Marcus Overhagen */ - #include #include #include @@ -15,12 +17,9 @@ #include "KeyboardWindow.h" #include "KeyboardView.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 ) + : BWindow(BRect(0,0,200,200), "Keyboard", B_TITLED_WINDOW, + B_NOT_RESIZABLE | B_NOT_ZOOMABLE) { MoveTo(fSettings.WindowCorner()); @@ -45,7 +44,6 @@ KeyboardWindow::KeyboardWindow() #endif Show(); - } @@ -144,5 +142,4 @@ KeyboardWindow::MessageReceived(BMessage *message) BWindow::MessageReceived(message); break; } - } diff --git a/src/preferences/keyboard/KeyboardWindow.h b/src/preferences/keyboard/KeyboardWindow.h index cc4fb6480f..a0d4b2e5b5 100644 --- a/src/preferences/keyboard/KeyboardWindow.h +++ b/src/preferences/keyboard/KeyboardWindow.h @@ -1,10 +1,12 @@ /* -** 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 + * Copyright 2004-2006, the Haiku project. All rights reserved. + * Distributed under the terms of the Haiku License. + * + * Authors in chronological order: + * mccall@digitalparadise.co.uk + * Jérôme Duval + * Marcus Overhagen */ - #ifndef KEYBOARD_WINDOW_H #define KEYBOARD_WINDOW_H @@ -16,14 +18,13 @@ class KeyboardWindow : public BWindow { public: - KeyboardWindow(); + KeyboardWindow(); - bool QuitRequested(); - void MessageReceived(BMessage *message); + bool QuitRequested(); + void MessageReceived(BMessage *message); private: - KeyboardView *fView; - + KeyboardView *fView; KeyboardSettings fSettings; };