2 * Copyright 2004-2007, Haiku. All rights reserved.
3 * Distributed under the terms of the Haiku License.
6 * Andrew McCall, mccall@digitalparadise.co.uk
12 #include "KeyboardMessages.h"
13 #include "KeyboardView.h"
14 #include "KeyboardWindow.h"
19 #include <LayoutBuilder.h>
24 #include <TextControl.h>
26 #undef B_TRANSLATION_CONTEXT
27 #define B_TRANSLATION_CONTEXT "KeyboardWindow"
29 KeyboardWindow::KeyboardWindow()
31 BWindow(BRect(0, 0, 200, 200), B_TRANSLATE_SYSTEM_NAME("Keyboard"),
32 B_TITLED_WINDOW
, B_NOT_RESIZABLE
| B_NOT_ZOOMABLE
33 | B_ASYNCHRONOUS_CONTROLS
| B_AUTO_UPDATE_SIZE_LIMITS
)
35 MoveTo(fSettings
.WindowCorner());
37 // Add the main settings view
38 fSettingsView
= new KeyboardView();
39 BBox
* fSettingsBox
= new BBox("keyboard_box");
40 fSettingsBox
->AddChild(fSettingsView
);
42 // Add the "Default" button..
43 fDefaultsButton
= new BButton(B_TRANSLATE("Defaults"), new BMessage(BUTTON_DEFAULTS
));
45 // Add the "Revert" button...
46 fRevertButton
= new BButton(B_TRANSLATE("Revert"), new BMessage(BUTTON_REVERT
));
47 fRevertButton
->SetEnabled(false);
50 BLayoutBuilder::Group
<>(this, B_VERTICAL
)
51 .SetInsets(B_USE_DEFAULT_SPACING
)
53 .AddGroup(B_HORIZONTAL
)
58 BSlider
* slider
= (BSlider
* )FindView("key_repeat_rate");
60 slider
->SetValue(fSettings
.KeyboardRepeatRate());
62 slider
= (BSlider
* )FindView("delay_until_key_repeat");
64 slider
->SetValue(fSettings
.KeyboardRepeatDelay());
66 fDefaultsButton
->SetEnabled(fSettings
.IsDefaultable());
68 // center window if it would be off-screen
70 if (screen
.Frame().right
< Frame().right
71 || screen
.Frame().bottom
< Frame().bottom
) {
84 KeyboardWindow::QuitRequested()
86 fSettings
.SetWindowCorner(Frame().LeftTop());
92 be_app
->PostMessage(B_QUIT_REQUESTED
);
98 KeyboardWindow::MessageReceived(BMessage
* message
)
100 BSlider
* slider
= NULL
;
102 switch (message
->what
) {
103 case BUTTON_DEFAULTS
:
105 fSettings
.Defaults();
107 slider
= (BSlider
* )FindView("key_repeat_rate");
109 slider
->SetValue(fSettings
.KeyboardRepeatRate());
111 slider
= (BSlider
* )FindView("delay_until_key_repeat");
113 slider
->SetValue(fSettings
.KeyboardRepeatDelay());
115 fDefaultsButton
->SetEnabled(false);
117 fRevertButton
->SetEnabled(true);
124 slider
= (BSlider
* )FindView("key_repeat_rate");
126 slider
->SetValue(fSettings
.KeyboardRepeatRate());
128 slider
= (BSlider
* )FindView("delay_until_key_repeat");
130 slider
->SetValue(fSettings
.KeyboardRepeatDelay());
132 fDefaultsButton
->SetEnabled(fSettings
.IsDefaultable());
134 fRevertButton
->SetEnabled(false);
137 case SLIDER_REPEAT_RATE
:
140 if (message
->FindInt32("be:value", &rate
) != B_OK
)
142 fSettings
.SetKeyboardRepeatRate(rate
);
144 fDefaultsButton
->SetEnabled(fSettings
.IsDefaultable());
146 fRevertButton
->SetEnabled(true);
149 case SLIDER_DELAY_RATE
:
152 if (message
->FindInt32("be:value", &delay
) != B_OK
)
155 // We need to look at the value from the slider and make it "jump"
156 // to the next notch along. Setting the min and max values of the
157 // slider to 1 and 4 doesn't work like the real Keyboard app.
160 if (delay
>= 375000 && delay
< 625000)
162 if (delay
>= 625000 && delay
< 875000)
167 fSettings
.SetKeyboardRepeatDelay(delay
);
169 slider
= (BSlider
* )FindView("delay_until_key_repeat");
171 slider
->SetValue(delay
);
173 fDefaultsButton
->SetEnabled(fSettings
.IsDefaultable());
175 fRevertButton
->SetEnabled(true);
180 BWindow::MessageReceived(message
);