tcp: Fix 64 bit build with debugging features enabled.
[haiku.git] / src / preferences / keyboard / KeyboardWindow.cpp
bloba0fe65ed693efb71f6d828984a4efec5b2081ebd
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 <Slider.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);
49 // Build the layout
50 BLayoutBuilder::Group<>(this, B_VERTICAL)
51 .SetInsets(B_USE_DEFAULT_SPACING)
52 .Add(fSettingsBox)
53 .AddGroup(B_HORIZONTAL)
54 .Add(fDefaultsButton)
55 .Add(fRevertButton)
56 .AddGlue();
58 BSlider* slider = (BSlider* )FindView("key_repeat_rate");
59 if (slider !=NULL)
60 slider->SetValue(fSettings.KeyboardRepeatRate());
62 slider = (BSlider* )FindView("delay_until_key_repeat");
63 if (slider !=NULL)
64 slider->SetValue(fSettings.KeyboardRepeatDelay());
66 fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
68 // center window if it would be off-screen
69 BScreen screen;
70 if (screen.Frame().right < Frame().right
71 || screen.Frame().bottom < Frame().bottom) {
72 CenterOnScreen();
75 #ifdef DEBUG
76 fSettings.Dump();
77 #endif
79 Show();
83 bool
84 KeyboardWindow::QuitRequested()
86 fSettings.SetWindowCorner(Frame().LeftTop());
88 #ifdef DEBUG
89 fSettings.Dump();
90 #endif
92 be_app->PostMessage(B_QUIT_REQUESTED);
93 return true;
97 void
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");
108 if (slider !=NULL)
109 slider->SetValue(fSettings.KeyboardRepeatRate());
111 slider = (BSlider* )FindView("delay_until_key_repeat");
112 if (slider !=NULL)
113 slider->SetValue(fSettings.KeyboardRepeatDelay());
115 fDefaultsButton->SetEnabled(false);
117 fRevertButton->SetEnabled(true);
118 break;
120 case BUTTON_REVERT:
122 fSettings.Revert();
124 slider = (BSlider* )FindView("key_repeat_rate");
125 if (slider !=NULL)
126 slider->SetValue(fSettings.KeyboardRepeatRate());
128 slider = (BSlider* )FindView("delay_until_key_repeat");
129 if (slider !=NULL)
130 slider->SetValue(fSettings.KeyboardRepeatDelay());
132 fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
134 fRevertButton->SetEnabled(false);
135 break;
137 case SLIDER_REPEAT_RATE:
139 int32 rate;
140 if (message->FindInt32("be:value", &rate) != B_OK)
141 break;
142 fSettings.SetKeyboardRepeatRate(rate);
144 fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
146 fRevertButton->SetEnabled(true);
147 break;
149 case SLIDER_DELAY_RATE:
151 int32 delay;
152 if (message->FindInt32("be:value", &delay) != B_OK)
153 break;
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.
158 if (delay < 375000)
159 delay = 250000;
160 if (delay >= 375000 && delay < 625000)
161 delay = 500000;
162 if (delay >= 625000 && delay < 875000)
163 delay = 750000;
164 if (delay >= 875000)
165 delay = 1000000;
167 fSettings.SetKeyboardRepeatDelay(delay);
169 slider = (BSlider* )FindView("delay_until_key_repeat");
170 if (slider != NULL)
171 slider->SetValue(delay);
173 fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
175 fRevertButton->SetEnabled(true);
176 break;
179 default:
180 BWindow::MessageReceived(message);
181 break;