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 "SettingsView.h"
20 #include <InterfaceDefs.h>
21 #include <LayoutBuilder.h>
23 #include <MenuField.h>
25 #include <PopUpMenu.h>
26 #include <SeparatorView.h>
28 #include <TextControl.h>
29 #include <TranslationUtils.h>
32 #include "MouseConstants.h"
33 #include "MouseSettings.h"
34 #include "MouseView.h"
38 mouse_mode_to_index(mode_mouse mode
)
44 case B_CLICK_TO_FOCUS_MOUSE
:
46 case B_FOCUS_FOLLOWS_MOUSE
:
53 focus_follows_mouse_mode_to_index(mode_focus_follows_mouse mode
)
56 case B_NORMAL_FOCUS_FOLLOWS_MOUSE
:
59 case B_WARP_FOCUS_FOLLOWS_MOUSE
:
61 case B_INSTANT_WARP_FOCUS_FOLLOWS_MOUSE
:
69 #undef B_TRANSLATION_CONTEXT
70 #define B_TRANSLATION_CONTEXT "SettingsView"
72 SettingsView::SettingsView(MouseSettings
& settings
)
76 // Add the "Mouse Type" pop up menu
77 fTypeMenu
= new BPopUpMenu("unknown");
78 fTypeMenu
->AddItem(new BMenuItem(B_TRANSLATE("1-Button"),
79 new BMessage(kMsgMouseType
)));
80 fTypeMenu
->AddItem(new BMenuItem(B_TRANSLATE("2-Button"),
81 new BMessage(kMsgMouseType
)));
82 fTypeMenu
->AddItem(new BMenuItem(B_TRANSLATE("3-Button"),
83 new BMessage(kMsgMouseType
)));
85 BMenuField
* typeField
= new BMenuField(B_TRANSLATE("Mouse type:"),
87 typeField
->SetAlignment(B_ALIGN_LEFT
);
89 // Create the "Double-click speed slider...
90 fClickSpeedSlider
= new BSlider("double_click_speed",
91 B_TRANSLATE("Double-click speed"), new BMessage(kMsgDoubleClickSpeed
),
92 0, 1000, B_HORIZONTAL
);
93 fClickSpeedSlider
->SetHashMarks(B_HASH_MARKS_BOTTOM
);
94 fClickSpeedSlider
->SetHashMarkCount(7);
96 // Create the "Mouse Speed" slider...
97 fMouseSpeedSlider
= new BSlider("mouse_speed", B_TRANSLATE("Mouse speed"),
98 new BMessage(kMsgMouseSpeed
), 0, 1000, B_HORIZONTAL
);
99 fMouseSpeedSlider
->SetHashMarks(B_HASH_MARKS_BOTTOM
);
100 fMouseSpeedSlider
->SetHashMarkCount(7);
102 // Create the "Mouse Acceleration" slider...
103 fAccelerationSlider
= new BSlider("mouse_acceleration",
104 B_TRANSLATE("Mouse acceleration"),
105 new BMessage(kMsgAccelerationFactor
), 0, 1000, B_HORIZONTAL
);
106 fAccelerationSlider
->SetHashMarks(B_HASH_MARKS_BOTTOM
);
107 fAccelerationSlider
->SetHashMarkCount(7);
110 fMouseView
= new MouseView(fSettings
);
112 // Create the "Double-click test area" text box...
113 const char* label
= B_TRANSLATE("Double-click test area");
114 BTextControl
* doubleClickTextControl
= new BTextControl(NULL
,
116 doubleClickTextControl
->SetAlignment(B_ALIGN_LEFT
, B_ALIGN_CENTER
);
117 doubleClickTextControl
->SetExplicitMinSize(
118 BSize(StringWidth(label
), B_SIZE_UNSET
));
120 // Add the "Mouse focus mode" pop up menu
121 fFocusMenu
= new BPopUpMenu(B_TRANSLATE("Click to focus and raise"));
123 const char *focusLabels
[] = {B_TRANSLATE_MARK("Click to focus and raise"),
124 B_TRANSLATE_MARK("Click to focus"),
125 B_TRANSLATE_MARK("Focus follows mouse")};
126 const mode_mouse focusModes
[] = {B_NORMAL_MOUSE
, B_CLICK_TO_FOCUS_MOUSE
,
127 B_FOCUS_FOLLOWS_MOUSE
};
129 for (int i
= 0; i
< 3; i
++) {
130 BMessage
* message
= new BMessage(kMsgMouseFocusMode
);
131 message
->AddInt32("mode", focusModes
[i
]);
133 fFocusMenu
->AddItem(new BMenuItem(B_TRANSLATE_NOCOLLECT(focusLabels
[i
]),
137 BMenuField
* focusField
= new BMenuField(B_TRANSLATE("Focus mode:"),
139 focusField
->SetAlignment(B_ALIGN_LEFT
);
141 // Add the "Focus follows mouse mode" pop up menu
142 fFocusFollowsMouseMenu
= new BPopUpMenu(B_TRANSLATE("Normal"));
144 const char *focusFollowsMouseLabels
[] = {B_TRANSLATE_MARK("Normal"),
145 B_TRANSLATE_MARK("Warp"), B_TRANSLATE_MARK("Instant warp")};
146 const mode_focus_follows_mouse focusFollowsMouseModes
[]
147 = {B_NORMAL_FOCUS_FOLLOWS_MOUSE
, B_WARP_FOCUS_FOLLOWS_MOUSE
,
148 B_INSTANT_WARP_FOCUS_FOLLOWS_MOUSE
};
150 for (int i
= 0; i
< 3; i
++) {
151 BMessage
* message
= new BMessage(kMsgFollowsMouseMode
);
152 message
->AddInt32("mode_focus_follows_mouse",
153 focusFollowsMouseModes
[i
]);
155 fFocusFollowsMouseMenu
->AddItem(new BMenuItem(
156 B_TRANSLATE_NOCOLLECT(focusFollowsMouseLabels
[i
]), message
));
159 BMenuField
* focusFollowsMouseField
= new BMenuField(
160 "Focus follows mouse mode:", fFocusFollowsMouseMenu
);
161 focusFollowsMouseField
->SetAlignment(B_ALIGN_RIGHT
);
163 // Add the "Click-through" check box
164 fAcceptFirstClickBox
= new BCheckBox(B_TRANSLATE("Accept first click"),
165 new BMessage(kMsgAcceptFirstClick
));
174 BLayoutBuilder::Group
<>(this, B_VERTICAL
, B_USE_DEFAULT_SPACING
)
176 .AddGroup(B_HORIZONTAL
, B_USE_DEFAULT_SPACING
)
178 // Vertical block A: mouse type/view/test
179 .AddGroup(B_VERTICAL
, B_USE_DEFAULT_SPACING
)
180 .AddGroup(B_HORIZONTAL
, 0)
186 .AddGroup(B_HORIZONTAL
, 0)
192 .Add(doubleClickTextControl
)
194 .Add(new BSeparatorView(B_VERTICAL
))
196 // Vertical block B: speed settings
197 .AddGroup(B_VERTICAL
, B_USE_DEFAULT_SPACING
, 3)
198 .AddGroup(B_HORIZONTAL
, 0)
199 .Add(fClickSpeedSlider
)
201 .AddGroup(B_HORIZONTAL
, 0)
202 .Add(fMouseSpeedSlider
)
204 .AddGroup(B_HORIZONTAL
, 0)
205 .Add(fAccelerationSlider
)
209 .AddStrut(B_USE_DEFAULT_SPACING
)
211 // Horizontal Block C: focus mode
212 .AddGroup(B_HORIZONTAL
, B_USE_SMALL_SPACING
)
215 .AddGroup(B_VERTICAL
, 0)
216 .Add(fAcceptFirstClickBox
)
220 SetBorder(B_NO_BORDER
);
224 SettingsView::~SettingsView()
231 SettingsView::AttachedToWindow()
233 UpdateFromSettings();
240 SettingsView::SetMouseType(int32 type
)
242 fMouseView
->SetMouseType(type
);
247 SettingsView::MouseMapUpdated()
249 fMouseView
->MouseMapUpdated();
254 SettingsView::UpdateFromSettings()
256 int32 value
= int32(fSettings
.ClickSpeed() / 1000);
257 // slow = 1000000, fast = 0
258 fClickSpeedSlider
->SetValue(value
);
260 value
= int32((log(fSettings
.MouseSpeed() / 8192.0) / log(2)) * 1000 / 6);
261 // slow = 8192, fast = 524287
262 fMouseSpeedSlider
->SetValue(value
);
264 value
= int32(sqrt(fSettings
.AccelerationFactor() / 16384.0) * 1000 / 4);
265 // slow = 0, fast = 262144
266 fAccelerationSlider
->SetValue(value
);
268 BMenuItem
* item
= fTypeMenu
->ItemAt(fSettings
.MouseType() - 1);
270 item
->SetMarked(true);
272 fMouseView
->SetMouseType(fSettings
.MouseType());
274 item
= fFocusMenu
->ItemAt(mouse_mode_to_index(fSettings
.MouseMode()));
276 item
->SetMarked(true);
278 item
= fFocusFollowsMouseMenu
->ItemAt(
279 focus_follows_mouse_mode_to_index(fSettings
.FocusFollowsMouseMode()));
281 item
->SetMarked(true);
283 fFocusFollowsMouseMenu
->SetEnabled(fSettings
.MouseMode()
284 == B_FOCUS_FOLLOWS_MOUSE
);
286 fAcceptFirstClickBox
->SetValue(fSettings
.AcceptFirstClick()
287 ? B_CONTROL_ON
: B_CONTROL_OFF
);
288 fAcceptFirstClickBox
->SetEnabled(fSettings
.MouseMode()
289 != B_FOCUS_FOLLOWS_MOUSE
);