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>
23 #include <SeparatorView.h>
25 #include <TextControl.h>
27 #undef B_TRANSLATION_CONTEXT
28 #define B_TRANSLATION_CONTEXT "KeyboardWindow"
30 KeyboardWindow::KeyboardWindow()
32 BWindow(BRect(0, 0, 200, 200), B_TRANSLATE_SYSTEM_NAME("Keyboard"),
33 B_TITLED_WINDOW
, B_NOT_RESIZABLE
| B_NOT_ZOOMABLE
34 | B_ASYNCHRONOUS_CONTROLS
| B_AUTO_UPDATE_SIZE_LIMITS
)
36 MoveTo(fSettings
.WindowCorner());
38 // Add the main settings view
39 fSettingsView
= new KeyboardView();
41 // Add the "Default" button..
42 fDefaultsButton
= new BButton(B_TRANSLATE("Defaults"), new BMessage(BUTTON_DEFAULTS
));
44 // Add the "Revert" button...
45 fRevertButton
= new BButton(B_TRANSLATE("Revert"), new BMessage(BUTTON_REVERT
));
46 fRevertButton
->SetEnabled(false);
49 BLayoutBuilder::Group
<>(this, B_VERTICAL
)
50 .AddGroup(B_HORIZONTAL
)
51 .SetInsets(B_USE_WINDOW_SPACING
, B_USE_WINDOW_SPACING
,
52 B_USE_WINDOW_SPACING
, 0)
55 .Add(new BSeparatorView(B_HORIZONTAL
))
56 .AddGroup(B_HORIZONTAL
)
57 .SetInsets(B_USE_WINDOW_SPACING
, 0, B_USE_WINDOW_SPACING
,
63 BSlider
* slider
= (BSlider
* )FindView("key_repeat_rate");
65 slider
->SetValue(fSettings
.KeyboardRepeatRate());
67 slider
= (BSlider
* )FindView("delay_until_key_repeat");
69 slider
->SetValue(fSettings
.KeyboardRepeatDelay());
71 fDefaultsButton
->SetEnabled(fSettings
.IsDefaultable());
73 // center window if it would be off-screen
75 if (screen
.Frame().right
< Frame().right
76 || screen
.Frame().bottom
< Frame().bottom
) {
89 KeyboardWindow::QuitRequested()
91 fSettings
.SetWindowCorner(Frame().LeftTop());
97 be_app
->PostMessage(B_QUIT_REQUESTED
);
103 KeyboardWindow::MessageReceived(BMessage
* message
)
105 BSlider
* slider
= NULL
;
107 switch (message
->what
) {
108 case BUTTON_DEFAULTS
:
110 fSettings
.Defaults();
112 slider
= (BSlider
* )FindView("key_repeat_rate");
114 slider
->SetValue(fSettings
.KeyboardRepeatRate());
116 slider
= (BSlider
* )FindView("delay_until_key_repeat");
118 slider
->SetValue(fSettings
.KeyboardRepeatDelay());
120 fDefaultsButton
->SetEnabled(false);
122 fRevertButton
->SetEnabled(true);
129 slider
= (BSlider
* )FindView("key_repeat_rate");
131 slider
->SetValue(fSettings
.KeyboardRepeatRate());
133 slider
= (BSlider
* )FindView("delay_until_key_repeat");
135 slider
->SetValue(fSettings
.KeyboardRepeatDelay());
137 fDefaultsButton
->SetEnabled(fSettings
.IsDefaultable());
139 fRevertButton
->SetEnabled(false);
142 case SLIDER_REPEAT_RATE
:
145 if (message
->FindInt32("be:value", &rate
) != B_OK
)
147 fSettings
.SetKeyboardRepeatRate(rate
);
149 fDefaultsButton
->SetEnabled(fSettings
.IsDefaultable());
151 fRevertButton
->SetEnabled(true);
154 case SLIDER_DELAY_RATE
:
157 if (message
->FindInt32("be:value", &delay
) != B_OK
)
160 // We need to look at the value from the slider and make it "jump"
161 // to the next notch along. Setting the min and max values of the
162 // slider to 1 and 4 doesn't work like the real Keyboard app.
165 if (delay
>= 375000 && delay
< 625000)
167 if (delay
>= 625000 && delay
< 875000)
172 fSettings
.SetKeyboardRepeatDelay(delay
);
174 slider
= (BSlider
* )FindView("delay_until_key_repeat");
176 slider
->SetValue(delay
);
178 fDefaultsButton
->SetEnabled(fSettings
.IsDefaultable());
180 fRevertButton
->SetEnabled(true);
185 BWindow::MessageReceived(message
);