RemoteDrawingEngine: Reduce RP_READ_BITMAP result timeout.
[haiku.git] / src / preferences / keyboard / KeyboardWindow.cpp
blob3014fbfede63b0e03a729bdca41e94990d3c8433
1 /*
2 * Copyright 2004-2007, Haiku. All rights reserved.
3 * Distributed under the terms of the Haiku License.
5 * Authors:
6 * Andrew McCall, mccall@digitalparadise.co.uk
7 * Jérôme Duval
8 * Marcus Overhagen
9 */
12 #include "KeyboardMessages.h"
13 #include "KeyboardView.h"
14 #include "KeyboardWindow.h"
16 #include <Box.h>
17 #include <Button.h>
18 #include <Catalog.h>
19 #include <LayoutBuilder.h>
20 #include <Locale.h>
21 #include <Message.h>
22 #include <Screen.h>
23 #include <SeparatorView.h>
24 #include <Slider.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);
48 // Build the layout
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)
53 .Add(fSettingsView)
54 .End()
55 .Add(new BSeparatorView(B_HORIZONTAL))
56 .AddGroup(B_HORIZONTAL)
57 .SetInsets(B_USE_WINDOW_SPACING, 0, B_USE_WINDOW_SPACING,
58 B_USE_WINDOW_SPACING)
59 .Add(fDefaultsButton)
60 .Add(fRevertButton)
61 .End();
63 BSlider* slider = (BSlider* )FindView("key_repeat_rate");
64 if (slider !=NULL)
65 slider->SetValue(fSettings.KeyboardRepeatRate());
67 slider = (BSlider* )FindView("delay_until_key_repeat");
68 if (slider !=NULL)
69 slider->SetValue(fSettings.KeyboardRepeatDelay());
71 fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
73 // center window if it would be off-screen
74 BScreen screen;
75 if (screen.Frame().right < Frame().right
76 || screen.Frame().bottom < Frame().bottom) {
77 CenterOnScreen();
80 #ifdef DEBUG
81 fSettings.Dump();
82 #endif
84 Show();
88 bool
89 KeyboardWindow::QuitRequested()
91 fSettings.SetWindowCorner(Frame().LeftTop());
93 #ifdef DEBUG
94 fSettings.Dump();
95 #endif
97 be_app->PostMessage(B_QUIT_REQUESTED);
98 return true;
102 void
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");
113 if (slider !=NULL)
114 slider->SetValue(fSettings.KeyboardRepeatRate());
116 slider = (BSlider* )FindView("delay_until_key_repeat");
117 if (slider !=NULL)
118 slider->SetValue(fSettings.KeyboardRepeatDelay());
120 fDefaultsButton->SetEnabled(false);
122 fRevertButton->SetEnabled(true);
123 break;
125 case BUTTON_REVERT:
127 fSettings.Revert();
129 slider = (BSlider* )FindView("key_repeat_rate");
130 if (slider !=NULL)
131 slider->SetValue(fSettings.KeyboardRepeatRate());
133 slider = (BSlider* )FindView("delay_until_key_repeat");
134 if (slider !=NULL)
135 slider->SetValue(fSettings.KeyboardRepeatDelay());
137 fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
139 fRevertButton->SetEnabled(false);
140 break;
142 case SLIDER_REPEAT_RATE:
144 int32 rate;
145 if (message->FindInt32("be:value", &rate) != B_OK)
146 break;
147 fSettings.SetKeyboardRepeatRate(rate);
149 fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
151 fRevertButton->SetEnabled(true);
152 break;
154 case SLIDER_DELAY_RATE:
156 int32 delay;
157 if (message->FindInt32("be:value", &delay) != B_OK)
158 break;
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.
163 if (delay < 375000)
164 delay = 250000;
165 if (delay >= 375000 && delay < 625000)
166 delay = 500000;
167 if (delay >= 625000 && delay < 875000)
168 delay = 750000;
169 if (delay >= 875000)
170 delay = 1000000;
172 fSettings.SetKeyboardRepeatDelay(delay);
174 slider = (BSlider* )FindView("delay_until_key_repeat");
175 if (slider != NULL)
176 slider->SetValue(delay);
178 fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
180 fRevertButton->SetEnabled(true);
181 break;
184 default:
185 BWindow::MessageReceived(message);
186 break;