2 * Copyright 2003-2014 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
7 * Axel Dörfler (axeld@pinc-software.de)
8 * Andrew McCall (mccall@digitalparadise.co.uk)
9 * Brecht Machiels (brecht@mos6581.org)
13 #include <Application.h>
18 #include <LayoutBuilder.h>
21 #include <MenuField.h>
25 #include <SeparatorView.h>
28 #include "MouseWindow.h"
29 #include "MouseConstants.h"
30 #include "SettingsView.h"
32 #undef B_TRANSLATION_CONTEXT
33 #define B_TRANSLATION_CONTEXT "MouseWindow"
35 MouseWindow::MouseWindow(BRect _rect
)
37 BWindow(_rect
, B_TRANSLATE_SYSTEM_NAME("Mouse"), B_TITLED_WINDOW
,
38 B_NOT_RESIZABLE
| B_NOT_ZOOMABLE
| B_ASYNCHRONOUS_CONTROLS
39 | B_AUTO_UPDATE_SIZE_LIMITS
)
41 // Add the main settings view
42 fSettingsView
= new SettingsView(fSettings
);
44 // Add the "Default" button
45 fDefaultsButton
= new BButton(B_TRANSLATE("Defaults"),
46 new BMessage(kMsgDefaults
));
47 fDefaultsButton
->SetEnabled(fSettings
.IsDefaultable());
49 // Add the "Revert" button
50 fRevertButton
= new BButton(B_TRANSLATE("Revert"),
51 new BMessage(kMsgRevert
));
52 fRevertButton
->SetEnabled(false);
55 // we are using the pulse rate to scan pressed mouse
56 // buttons and draw the selected imagery
59 BLayoutBuilder::Group
<>(this, B_VERTICAL
)
60 .AddGroup(B_HORIZONTAL
)
61 .SetInsets(B_USE_WINDOW_SPACING
, B_USE_WINDOW_SPACING
,
62 B_USE_WINDOW_SPACING
, 0)
65 .Add(new BSeparatorView(B_HORIZONTAL
))
66 .AddGroup(B_HORIZONTAL
)
67 .SetInsets(B_USE_WINDOW_SPACING
, 0, B_USE_WINDOW_SPACING
,
74 // check if the window is on screen
75 BRect rect
= BScreen().Frame();
76 rect
.InsetBySelf(20, 20);
78 BPoint position
= fSettings
.WindowPosition();
79 BRect windowFrame
= Frame().OffsetToSelf(position
);
80 if (!rect
.Contains(windowFrame
)) {
81 // center window on screen as it doesn't fit on the saved position
82 position
.x
= (rect
.Width() - windowFrame
.Width()) / 2;
83 position
.y
= (rect
.Height() - windowFrame
.Height()) / 2;
94 MouseWindow::QuitRequested()
96 fSettings
.SetWindowPosition(Frame().LeftTop());
97 be_app
->PostMessage(B_QUIT_REQUESTED
);
104 MouseWindow::MessageReceived(BMessage
* message
)
106 switch (message
->what
) {
108 // reverts to default settings
109 fSettings
.Defaults();
110 fSettingsView
->UpdateFromSettings();
112 fDefaultsButton
->SetEnabled(false);
113 fRevertButton
->SetEnabled(fSettings
.IsRevertable());
118 // revert to last settings
120 fSettingsView
->UpdateFromSettings();
122 fDefaultsButton
->SetEnabled(fSettings
.IsDefaultable());
123 fRevertButton
->SetEnabled(false);
130 if (message
->FindInt32("index", &type
) == B_OK
) {
131 fSettings
.SetMouseType(++type
);
132 fSettingsView
->SetMouseType(type
);
133 fDefaultsButton
->SetEnabled(fSettings
.IsDefaultable());
134 fRevertButton
->SetEnabled(fSettings
.IsRevertable());
139 case kMsgMouseFocusMode
:
142 if (message
->FindInt32("mode", &mode
) == B_OK
) {
143 fSettings
.SetMouseMode((mode_mouse
)mode
);
144 fDefaultsButton
->SetEnabled(fSettings
.IsDefaultable());
145 fRevertButton
->SetEnabled(fSettings
.IsRevertable());
146 fSettingsView
->fFocusFollowsMouseMenu
->SetEnabled(
147 mode
== B_FOCUS_FOLLOWS_MOUSE
);
148 fSettingsView
->fAcceptFirstClickBox
->SetEnabled(
149 mode
!= B_FOCUS_FOLLOWS_MOUSE
);
154 case kMsgFollowsMouseMode
:
157 if (message
->FindInt32("mode_focus_follows_mouse", &mode
)
159 fSettings
.SetFocusFollowsMouseMode(
160 (mode_focus_follows_mouse
)mode
);
161 fDefaultsButton
->SetEnabled(fSettings
.IsDefaultable());
162 fRevertButton
->SetEnabled(fSettings
.IsRevertable());
167 case kMsgAcceptFirstClick
:
170 if (message
->FindPointer("source",
171 reinterpret_cast<void**>(&handler
)) == B_OK
) {
172 bool acceptFirstClick
= false;
173 BCheckBox
*acceptFirstClickBox
=
174 dynamic_cast<BCheckBox
*>(handler
);
175 if (acceptFirstClickBox
)
176 acceptFirstClick
= acceptFirstClickBox
->Value()
178 fSettings
.SetAcceptFirstClick(acceptFirstClick
);
179 fDefaultsButton
->SetEnabled(fSettings
.IsDefaultable());
180 fRevertButton
->SetEnabled(fSettings
.IsRevertable());
185 case kMsgDoubleClickSpeed
:
188 if (message
->FindInt32("be:value", &value
) == B_OK
) {
189 // slow = 1000000, fast = 0
190 fSettings
.SetClickSpeed(value
* 1000);
191 fDefaultsButton
->SetEnabled(fSettings
.IsDefaultable());
192 fRevertButton
->SetEnabled(fSettings
.IsRevertable());
200 if (message
->FindInt32("be:value", &value
) == B_OK
) {
201 // slow = 8192, fast = 524287
202 fSettings
.SetMouseSpeed((int32
)pow(2,
203 value
* 6.0 / 1000) * 8192);
204 fDefaultsButton
->SetEnabled(fSettings
.IsDefaultable());
205 fRevertButton
->SetEnabled(fSettings
.IsRevertable());
210 case kMsgAccelerationFactor
:
213 if (message
->FindInt32("be:value", &value
) == B_OK
) {
214 // slow = 0, fast = 262144
215 fSettings
.SetAccelerationFactor((int32
)pow(
216 value
* 4.0 / 1000, 2) * 16384);
217 fDefaultsButton
->SetEnabled(fSettings
.IsDefaultable());
218 fRevertButton
->SetEnabled(fSettings
.IsRevertable());
227 if (message
->FindInt32("index", &index
) == B_OK
228 && message
->FindInt32("button", &button
) == B_OK
) {
229 int32 mapping
= B_PRIMARY_MOUSE_BUTTON
;
232 mapping
= B_SECONDARY_MOUSE_BUTTON
;
235 mapping
= B_TERTIARY_MOUSE_BUTTON
;
239 fSettings
.SetMapping(button
, mapping
);
240 fDefaultsButton
->SetEnabled(fSettings
.IsDefaultable());
241 fRevertButton
->SetEnabled(fSettings
.IsRevertable());
242 fSettingsView
->MouseMapUpdated();
248 BWindow::MessageReceived(message
);