tcp: Fix 64 bit build with debugging features enabled.
[haiku.git] / src / preferences / mouse / MouseWindow.cpp
blob06e7e5a317206f9d1087e925c15f76eb230ceea8
1 /*
2 * Copyright 2003-2014 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Jérôme Duval,
7 * Axel Dörfler (axeld@pinc-software.de)
8 * Andrew McCall (mccall@digitalparadise.co.uk)
9 * Brecht Machiels (brecht@mos6581.org)
12 #include <Alert.h>
13 #include <Application.h>
14 #include <Button.h>
15 #include <Catalog.h>
16 #include <CheckBox.h>
17 #include <Debug.h>
18 #include <LayoutBuilder.h>
19 #include <Locale.h>
20 #include <Menu.h>
21 #include <MenuField.h>
22 #include <MenuItem.h>
23 #include <Message.h>
24 #include <Screen.h>
25 #include <Slider.h>
27 #include "MouseWindow.h"
28 #include "MouseConstants.h"
29 #include "SettingsView.h"
31 #undef B_TRANSLATION_CONTEXT
32 #define B_TRANSLATION_CONTEXT "MouseWindow"
34 MouseWindow::MouseWindow(BRect _rect)
36 BWindow(_rect, B_TRANSLATE_SYSTEM_NAME("Mouse"), B_TITLED_WINDOW,
37 B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS
38 | B_AUTO_UPDATE_SIZE_LIMITS)
40 // Add the main settings view
41 fSettingsView = new SettingsView(fSettings);
42 fSettingsBox = new BBox("main box");
43 fSettingsBox->AddChild(fSettingsView);
45 // Add the "Default" button
46 fDefaultsButton = new BButton(B_TRANSLATE("Defaults"),
47 new BMessage(kMsgDefaults));
48 fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
50 // Add the "Revert" button
51 fRevertButton = new BButton(B_TRANSLATE("Revert"),
52 new BMessage(kMsgRevert));
53 fRevertButton->SetEnabled(false);
55 SetPulseRate(100000);
56 // we are using the pulse rate to scan pressed mouse
57 // buttons and draw the selected imagery
59 // Build the layout
60 BLayoutBuilder::Group<>(this, B_VERTICAL)
61 .SetInsets(B_USE_DEFAULT_SPACING)
62 .Add(fSettingsBox)
63 .AddGroup(B_HORIZONTAL)
64 .Add(fDefaultsButton)
65 .Add(fRevertButton)
66 .AddGlue();
68 // check if the window is on screen
69 BRect rect = BScreen().Frame();
70 rect.InsetBySelf(20, 20);
72 BPoint position = fSettings.WindowPosition();
73 BRect windowFrame = Frame().OffsetToSelf(position);
74 if (!rect.Contains(windowFrame)) {
75 // center window on screen as it doesn't fit on the saved position
76 position.x = (rect.Width() - windowFrame.Width()) / 2;
77 position.y = (rect.Height() - windowFrame.Height()) / 2;
78 if (position.x < 0)
79 position.x = 0;
80 if (position.y < 0)
81 position.y = 15;
83 MoveTo(position);
87 bool
88 MouseWindow::QuitRequested()
90 fSettings.SetWindowPosition(Frame().LeftTop());
91 be_app->PostMessage(B_QUIT_REQUESTED);
93 return true;
97 void
98 MouseWindow::MessageReceived(BMessage* message)
100 switch (message->what) {
101 case kMsgDefaults: {
102 // reverts to default settings
103 fSettings.Defaults();
104 fSettingsView->UpdateFromSettings();
106 fDefaultsButton->SetEnabled(false);
107 fRevertButton->SetEnabled(fSettings.IsRevertable());
108 break;
111 case kMsgRevert: {
112 // revert to last settings
113 fSettings.Revert();
114 fSettingsView->UpdateFromSettings();
116 fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
117 fRevertButton->SetEnabled(false);
118 break;
121 case kMsgMouseType:
123 int32 type;
124 if (message->FindInt32("index", &type) == B_OK) {
125 fSettings.SetMouseType(++type);
126 fSettingsView->SetMouseType(type);
127 fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
128 fRevertButton->SetEnabled(fSettings.IsRevertable());
130 break;
133 case kMsgMouseFocusMode:
135 int32 mode;
136 if (message->FindInt32("mode", &mode) == B_OK) {
137 fSettings.SetMouseMode((mode_mouse)mode);
138 fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
139 fRevertButton->SetEnabled(fSettings.IsRevertable());
140 fSettingsView->fFocusFollowsMouseMenu->SetEnabled(
141 mode == B_FOCUS_FOLLOWS_MOUSE);
142 fSettingsView->fAcceptFirstClickBox->SetEnabled(
143 mode != B_FOCUS_FOLLOWS_MOUSE);
145 break;
148 case kMsgFollowsMouseMode:
150 int32 mode;
151 if (message->FindInt32("mode_focus_follows_mouse", &mode)
152 == B_OK) {
153 fSettings.SetFocusFollowsMouseMode(
154 (mode_focus_follows_mouse)mode);
155 fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
156 fRevertButton->SetEnabled(fSettings.IsRevertable());
158 break;
161 case kMsgAcceptFirstClick:
163 BHandler *handler;
164 if (message->FindPointer("source",
165 reinterpret_cast<void**>(&handler)) == B_OK) {
166 bool acceptFirstClick = false;
167 BCheckBox *acceptFirstClickBox =
168 dynamic_cast<BCheckBox*>(handler);
169 if (acceptFirstClickBox)
170 acceptFirstClick = acceptFirstClickBox->Value()
171 == B_CONTROL_ON;
172 fSettings.SetAcceptFirstClick(acceptFirstClick);
173 fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
174 fRevertButton->SetEnabled(fSettings.IsRevertable());
176 break;
179 case kMsgDoubleClickSpeed:
181 int32 value;
182 if (message->FindInt32("be:value", &value) == B_OK) {
183 // slow = 1000000, fast = 0
184 fSettings.SetClickSpeed(value * 1000);
185 fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
186 fRevertButton->SetEnabled(fSettings.IsRevertable());
188 break;
191 case kMsgMouseSpeed:
193 int32 value;
194 if (message->FindInt32("be:value", &value) == B_OK) {
195 // slow = 8192, fast = 524287
196 fSettings.SetMouseSpeed((int32)pow(2,
197 value * 6.0 / 1000) * 8192);
198 fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
199 fRevertButton->SetEnabled(fSettings.IsRevertable());
201 break;
204 case kMsgAccelerationFactor:
206 int32 value;
207 if (message->FindInt32("be:value", &value) == B_OK) {
208 // slow = 0, fast = 262144
209 fSettings.SetAccelerationFactor((int32)pow(
210 value * 4.0 / 1000, 2) * 16384);
211 fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
212 fRevertButton->SetEnabled(fSettings.IsRevertable());
214 break;
217 case kMsgMouseMap:
219 int32 index;
220 int32 button;
221 if (message->FindInt32("index", &index) == B_OK
222 && message->FindInt32("button", &button) == B_OK) {
223 int32 mapping = B_PRIMARY_MOUSE_BUTTON;
224 switch (index) {
225 case 1:
226 mapping = B_SECONDARY_MOUSE_BUTTON;
227 break;
228 case 2:
229 mapping = B_TERTIARY_MOUSE_BUTTON;
230 break;
233 fSettings.SetMapping(button, mapping);
234 fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
235 fRevertButton->SetEnabled(fSettings.IsRevertable());
236 fSettingsView->MouseMapUpdated();
238 break;
241 default:
242 BWindow::MessageReceived(message);
243 break;