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 <GroupLayout.h>
21 #include <GroupLayoutBuilder.h>
22 #include <InterfaceDefs.h>
24 #include <MenuField.h>
26 #include <PopUpMenu.h>
27 #include <SeparatorView.h>
29 #include <TextControl.h>
30 #include <TranslationUtils.h>
33 #include "MouseConstants.h"
34 #include "MouseSettings.h"
35 #include "MouseView.h"
39 mouse_mode_to_index(mode_mouse mode
)
45 case B_CLICK_TO_FOCUS_MOUSE
:
47 case B_FOCUS_FOLLOWS_MOUSE
:
54 focus_follows_mouse_mode_to_index(mode_focus_follows_mouse mode
)
57 case B_NORMAL_FOCUS_FOLLOWS_MOUSE
:
60 case B_WARP_FOCUS_FOLLOWS_MOUSE
:
62 case B_INSTANT_WARP_FOCUS_FOLLOWS_MOUSE
:
70 #undef B_TRANSLATION_CONTEXT
71 #define B_TRANSLATION_CONTEXT "SettingsView"
73 SettingsView::SettingsView(MouseSettings
& settings
)
77 // Add the "Mouse Type" pop up menu
78 fTypeMenu
= new BPopUpMenu("unknown");
79 fTypeMenu
->AddItem(new BMenuItem(B_TRANSLATE("1-Button"),
80 new BMessage(kMsgMouseType
)));
81 fTypeMenu
->AddItem(new BMenuItem(B_TRANSLATE("2-Button"),
82 new BMessage(kMsgMouseType
)));
83 fTypeMenu
->AddItem(new BMenuItem(B_TRANSLATE("3-Button"),
84 new BMessage(kMsgMouseType
)));
86 BMenuField
* typeField
= new BMenuField(B_TRANSLATE("Mouse type:"),
88 typeField
->SetAlignment(B_ALIGN_LEFT
);
90 // Create the "Double-click speed slider...
91 fClickSpeedSlider
= new BSlider("double_click_speed",
92 B_TRANSLATE("Double-click speed"), new BMessage(kMsgDoubleClickSpeed
),
93 0, 1000, B_HORIZONTAL
);
94 fClickSpeedSlider
->SetHashMarks(B_HASH_MARKS_BOTTOM
);
95 fClickSpeedSlider
->SetHashMarkCount(7);
97 // Create the "Mouse Speed" slider...
98 fMouseSpeedSlider
= new BSlider("mouse_speed", B_TRANSLATE("Mouse speed"),
99 new BMessage(kMsgMouseSpeed
), 0, 1000, B_HORIZONTAL
);
100 fMouseSpeedSlider
->SetHashMarks(B_HASH_MARKS_BOTTOM
);
101 fMouseSpeedSlider
->SetHashMarkCount(7);
103 // Create the "Mouse Acceleration" slider...
104 fAccelerationSlider
= new BSlider("mouse_acceleration",
105 B_TRANSLATE("Mouse acceleration"),
106 new BMessage(kMsgAccelerationFactor
), 0, 1000, B_HORIZONTAL
);
107 fAccelerationSlider
->SetHashMarks(B_HASH_MARKS_BOTTOM
);
108 fAccelerationSlider
->SetHashMarkCount(7);
111 fMouseView
= new MouseView(fSettings
);
113 // Create the "Double-click test area" text box...
114 const char* label
= B_TRANSLATE("Double-click test area");
115 BTextControl
* doubleClickTextControl
= new BTextControl(NULL
,
117 doubleClickTextControl
->SetAlignment(B_ALIGN_LEFT
, B_ALIGN_CENTER
);
118 doubleClickTextControl
->SetExplicitMinSize(
119 BSize(StringWidth(label
), B_SIZE_UNSET
));
121 // Add the "Mouse focus mode" pop up menu
122 fFocusMenu
= new BPopUpMenu(B_TRANSLATE("Click to focus and raise"));
124 const char *focusLabels
[] = {B_TRANSLATE_MARK("Click to focus and raise"),
125 B_TRANSLATE_MARK("Click to focus"),
126 B_TRANSLATE_MARK("Focus follows mouse")};
127 const mode_mouse focusModes
[] = {B_NORMAL_MOUSE
, B_CLICK_TO_FOCUS_MOUSE
,
128 B_FOCUS_FOLLOWS_MOUSE
};
130 for (int i
= 0; i
< 3; i
++) {
131 BMessage
* message
= new BMessage(kMsgMouseFocusMode
);
132 message
->AddInt32("mode", focusModes
[i
]);
134 fFocusMenu
->AddItem(new BMenuItem(B_TRANSLATE_NOCOLLECT(focusLabels
[i
]),
138 BMenuField
* focusField
= new BMenuField(B_TRANSLATE("Focus mode:"),
140 focusField
->SetAlignment(B_ALIGN_RIGHT
);
142 // Add the "Focus follows mouse mode" pop up menu
143 fFocusFollowsMouseMenu
= new BPopUpMenu(B_TRANSLATE("Normal"));
145 const char *focusFollowsMouseLabels
[] = {B_TRANSLATE_MARK("Normal"),
146 B_TRANSLATE_MARK("Warp"), B_TRANSLATE_MARK("Instant warp")};
147 const mode_focus_follows_mouse focusFollowsMouseModes
[]
148 = {B_NORMAL_FOCUS_FOLLOWS_MOUSE
, B_WARP_FOCUS_FOLLOWS_MOUSE
,
149 B_INSTANT_WARP_FOCUS_FOLLOWS_MOUSE
};
151 for (int i
= 0; i
< 3; i
++) {
152 BMessage
* message
= new BMessage(kMsgFollowsMouseMode
);
153 message
->AddInt32("mode_focus_follows_mouse",
154 focusFollowsMouseModes
[i
]);
156 fFocusFollowsMouseMenu
->AddItem(new BMenuItem(
157 B_TRANSLATE_NOCOLLECT(focusFollowsMouseLabels
[i
]), message
));
160 BMenuField
* focusFollowsMouseField
= new BMenuField(
161 "Focus follows mouse mode:", fFocusFollowsMouseMenu
);
162 focusFollowsMouseField
->SetAlignment(B_ALIGN_RIGHT
);
164 // Add the "Click-through" check box
165 fAcceptFirstClickBox
= new BCheckBox(B_TRANSLATE("Accept first click"),
166 new BMessage(kMsgAcceptFirstClick
));
169 // This one is a vertical line for B_HORIZONTAL
170 BSeparatorView
* hdivider
= new BSeparatorView(B_VERTICAL
, B_FANCY_BORDER
);
172 // This one is a horizontal line for B_VERTICAL
173 BSeparatorView
* vdivider
= new BSeparatorView(B_HORIZONTAL
, B_FANCY_BORDER
);
176 SetLayout(new BGroupLayout(B_VERTICAL
));
183 AddChild(BGroupLayoutBuilder(B_VERTICAL
, B_USE_SMALL_SPACING
)
186 .AddGroup(B_HORIZONTAL
, B_USE_SMALL_SPACING
)
188 // Vertical block A: mouse type/view/test
189 .AddGroup(B_VERTICAL
, 10)
190 .AddGroup(B_HORIZONTAL
, 0)
197 .Add(BGroupLayoutBuilder(B_HORIZONTAL
, 0)
203 .Add(doubleClickTextControl
)
208 // Vertical block B: speed settings
209 .AddGroup(B_VERTICAL
, B_USE_DEFAULT_SPACING
, 3)
210 .Add(BGroupLayoutBuilder(B_HORIZONTAL
, 0)
211 .Add(fClickSpeedSlider
)
213 .Add(BGroupLayoutBuilder(B_HORIZONTAL
, 0)
214 .Add(fMouseSpeedSlider
)
216 .Add(BGroupLayoutBuilder(B_HORIZONTAL
, 0)
217 .Add(fAccelerationSlider
)
224 // Horizontal Block C: focus mode
225 .AddGroup(B_HORIZONTAL
, B_USE_SMALL_SPACING
)
228 .AddGroup(B_VERTICAL
, 0)
229 .Add(fAcceptFirstClickBox
)
232 .SetInsets(B_USE_SMALL_SPACING
, B_USE_SMALL_SPACING
,
233 B_USE_SMALL_SPACING
, B_USE_SMALL_SPACING
)
238 SettingsView::~SettingsView()
245 SettingsView::AttachedToWindow()
247 UpdateFromSettings();
254 SettingsView::SetMouseType(int32 type
)
256 fMouseView
->SetMouseType(type
);
261 SettingsView::MouseMapUpdated()
263 fMouseView
->MouseMapUpdated();
268 SettingsView::UpdateFromSettings()
270 int32 value
= int32(fSettings
.ClickSpeed() / 1000);
271 // slow = 1000000, fast = 0
272 fClickSpeedSlider
->SetValue(value
);
274 value
= int32((log(fSettings
.MouseSpeed() / 8192.0) / log(2)) * 1000 / 6);
275 // slow = 8192, fast = 524287
276 fMouseSpeedSlider
->SetValue(value
);
278 value
= int32(sqrt(fSettings
.AccelerationFactor() / 16384.0) * 1000 / 4);
279 // slow = 0, fast = 262144
280 fAccelerationSlider
->SetValue(value
);
282 BMenuItem
* item
= fTypeMenu
->ItemAt(fSettings
.MouseType() - 1);
284 item
->SetMarked(true);
286 fMouseView
->SetMouseType(fSettings
.MouseType());
288 item
= fFocusMenu
->ItemAt(mouse_mode_to_index(fSettings
.MouseMode()));
290 item
->SetMarked(true);
292 item
= fFocusFollowsMouseMenu
->ItemAt(
293 focus_follows_mouse_mode_to_index(fSettings
.FocusFollowsMouseMode()));
295 item
->SetMarked(true);
297 fFocusFollowsMouseMenu
->SetEnabled(fSettings
.MouseMode()
298 == B_FOCUS_FOLLOWS_MOUSE
);
300 fAcceptFirstClickBox
->SetValue(fSettings
.AcceptFirstClick()
301 ? B_CONTROL_ON
: B_CONTROL_OFF
);
302 fAcceptFirstClickBox
->SetEnabled(fSettings
.MouseMode()
303 != B_FOCUS_FOLLOWS_MOUSE
);