15e9685caSPreetpal Kaur /*
25e9685caSPreetpal Kaur * Copyright 2019, Haiku, Inc.
35e9685caSPreetpal Kaur * Distributed under the terms of the MIT License.
45e9685caSPreetpal Kaur *
55e9685caSPreetpal Kaur * Author:
65e9685caSPreetpal Kaur * Preetpal Kaur <preetpalok123@gmail.com>
75e9685caSPreetpal Kaur */
85e9685caSPreetpal Kaur
95e9685caSPreetpal Kaur
105e9685caSPreetpal Kaur #include "InputTouchpadPrefView.h"
115e9685caSPreetpal Kaur
125e9685caSPreetpal Kaur #include <stdio.h>
135e9685caSPreetpal Kaur
145e9685caSPreetpal Kaur #include <Alert.h>
155e9685caSPreetpal Kaur #include <Box.h>
165e9685caSPreetpal Kaur #include <Catalog.h>
175e9685caSPreetpal Kaur #include <CheckBox.h>
185e9685caSPreetpal Kaur #include <ControlLook.h>
195e9685caSPreetpal Kaur #include <File.h>
205e9685caSPreetpal Kaur #include <FindDirectory.h>
215e9685caSPreetpal Kaur #include <Input.h>
225e9685caSPreetpal Kaur #include <LayoutBuilder.h>
235e9685caSPreetpal Kaur #include <Locale.h>
245e9685caSPreetpal Kaur #include <MenuField.h>
255e9685caSPreetpal Kaur #include <MenuItem.h>
265e9685caSPreetpal Kaur #include <Message.h>
275e9685caSPreetpal Kaur #include <Path.h>
285e9685caSPreetpal Kaur #include <Screen.h>
295e9685caSPreetpal Kaur #include <SeparatorView.h>
305e9685caSPreetpal Kaur #include <SpaceLayoutItem.h>
315e9685caSPreetpal Kaur #include <Window.h>
325e9685caSPreetpal Kaur
335e9685caSPreetpal Kaur #include <keyboard_mouse_driver.h>
345e9685caSPreetpal Kaur
355e9685caSPreetpal Kaur
365e9685caSPreetpal Kaur const uint32 SCROLL_X_DRAG = 'sxdr';
375e9685caSPreetpal Kaur const uint32 SCROLL_Y_DRAG = 'sydr';
385e9685caSPreetpal Kaur
395e9685caSPreetpal Kaur #undef B_TRANSLATION_CONTEXT
405e9685caSPreetpal Kaur #define B_TRANSLATION_CONTEXT "TouchpadPrefView"
415e9685caSPreetpal Kaur
425e9685caSPreetpal Kaur
TouchpadView(BRect frame)435e9685caSPreetpal Kaur TouchpadView::TouchpadView(BRect frame)
445e9685caSPreetpal Kaur :
455e9685caSPreetpal Kaur BView(frame, "TouchpadView", B_FOLLOW_NONE, B_WILL_DRAW)
465e9685caSPreetpal Kaur {
475e9685caSPreetpal Kaur fXTracking = false;
485e9685caSPreetpal Kaur fYTracking = false;
495e9685caSPreetpal Kaur fOffScreenView = NULL;
505e9685caSPreetpal Kaur fOffScreenBitmap = NULL;
515e9685caSPreetpal Kaur
525e9685caSPreetpal Kaur fPrefRect = frame;
535e9685caSPreetpal Kaur fPadRect = fPrefRect;
545e9685caSPreetpal Kaur fPadRect.InsetBy(10, 10);
555e9685caSPreetpal Kaur fXScrollRange = fPadRect.Width();
565e9685caSPreetpal Kaur fYScrollRange = fPadRect.Height();
575e9685caSPreetpal Kaur }
585e9685caSPreetpal Kaur
595e9685caSPreetpal Kaur
~TouchpadView()605e9685caSPreetpal Kaur TouchpadView::~TouchpadView()
615e9685caSPreetpal Kaur {
625e9685caSPreetpal Kaur delete fOffScreenBitmap;
635e9685caSPreetpal Kaur }
645e9685caSPreetpal Kaur
655e9685caSPreetpal Kaur
665e9685caSPreetpal Kaur void
Draw(BRect updateRect)675e9685caSPreetpal Kaur TouchpadView::Draw(BRect updateRect)
685e9685caSPreetpal Kaur {
695e9685caSPreetpal Kaur DrawSliders();
705e9685caSPreetpal Kaur }
715e9685caSPreetpal Kaur
725e9685caSPreetpal Kaur
735e9685caSPreetpal Kaur void
MouseDown(BPoint point)745e9685caSPreetpal Kaur TouchpadView::MouseDown(BPoint point)
755e9685caSPreetpal Kaur {
765e9685caSPreetpal Kaur if (fXScrollDragZone.Contains(point)) {
775e9685caSPreetpal Kaur fXTracking = true;
785e9685caSPreetpal Kaur fOldXScrollRange = fXScrollRange;
795e9685caSPreetpal Kaur SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
805e9685caSPreetpal Kaur }
815e9685caSPreetpal Kaur
825e9685caSPreetpal Kaur if (fYScrollDragZone.Contains(point)) {
835e9685caSPreetpal Kaur fYTracking = true;
845e9685caSPreetpal Kaur fOldYScrollRange = fYScrollRange;
855e9685caSPreetpal Kaur SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
865e9685caSPreetpal Kaur }
875e9685caSPreetpal Kaur }
885e9685caSPreetpal Kaur
895e9685caSPreetpal Kaur
905e9685caSPreetpal Kaur void
MouseUp(BPoint point)915e9685caSPreetpal Kaur TouchpadView::MouseUp(BPoint point)
925e9685caSPreetpal Kaur {
935e9685caSPreetpal Kaur if (!fXTracking && !fYTracking)
945e9685caSPreetpal Kaur return;
955e9685caSPreetpal Kaur
965e9685caSPreetpal Kaur fXTracking = false;
975e9685caSPreetpal Kaur fYTracking = false;
985e9685caSPreetpal Kaur
995e9685caSPreetpal Kaur const float kSoftScrollLimit = 0.7;
1005e9685caSPreetpal Kaur
1015e9685caSPreetpal Kaur int32 result = 0;
1025e9685caSPreetpal Kaur if (GetRightScrollRatio() > kSoftScrollLimit
1035e9685caSPreetpal Kaur || GetBottomScrollRatio() > kSoftScrollLimit) {
1045e9685caSPreetpal Kaur BAlert* alert = new BAlert(B_TRANSLATE("Please confirm"),
10502dabf4bSSaloni B_TRANSLATE(
10602dabf4bSSaloni "The new scroll area is very large and may impede "
1075e9685caSPreetpal Kaur "normal mouse operation. Do you really want to change it?"),
10802dabf4bSSaloni B_TRANSLATE("OK"), B_TRANSLATE("Cancel"), NULL, B_WIDTH_AS_USUAL,
10902dabf4bSSaloni B_WARNING_ALERT);
1105e9685caSPreetpal Kaur alert->SetShortcut(1, B_ESCAPE);
1115e9685caSPreetpal Kaur result = alert->Go();
1125e9685caSPreetpal Kaur }
1135e9685caSPreetpal Kaur
1145e9685caSPreetpal Kaur if (result == 0) {
1155e9685caSPreetpal Kaur BMessage msg(SCROLL_AREA_CHANGED);
1165e9685caSPreetpal Kaur Invoke(&msg);
1175e9685caSPreetpal Kaur } else {
1185e9685caSPreetpal Kaur if (GetRightScrollRatio() > kSoftScrollLimit)
1195e9685caSPreetpal Kaur fXScrollRange = fOldXScrollRange;
1205e9685caSPreetpal Kaur if (GetBottomScrollRatio() > kSoftScrollLimit)
1215e9685caSPreetpal Kaur fYScrollRange = fOldYScrollRange;
1225e9685caSPreetpal Kaur DrawSliders();
1235e9685caSPreetpal Kaur }
1245e9685caSPreetpal Kaur }
1255e9685caSPreetpal Kaur
1265e9685caSPreetpal Kaur
1275e9685caSPreetpal Kaur void
AttachedToWindow()1285e9685caSPreetpal Kaur TouchpadView::AttachedToWindow()
1295e9685caSPreetpal Kaur {
1305e9685caSPreetpal Kaur if (!fOffScreenView)
1315e9685caSPreetpal Kaur fOffScreenView = new BView(Bounds(), "", B_FOLLOW_ALL, B_WILL_DRAW);
1325e9685caSPreetpal Kaur
1335e9685caSPreetpal Kaur if (!fOffScreenBitmap) {
1345e9685caSPreetpal Kaur fOffScreenBitmap = new BBitmap(Bounds(), B_CMAP8, true, false);
1355e9685caSPreetpal Kaur
1365e9685caSPreetpal Kaur if (fOffScreenBitmap && fOffScreenView)
1375e9685caSPreetpal Kaur fOffScreenBitmap->AddChild(fOffScreenView);
1385e9685caSPreetpal Kaur }
1395e9685caSPreetpal Kaur }
1405e9685caSPreetpal Kaur
1415e9685caSPreetpal Kaur
1425e9685caSPreetpal Kaur void
SetValues(float rightRange,float bottomRange)1435e9685caSPreetpal Kaur TouchpadView::SetValues(float rightRange, float bottomRange)
1445e9685caSPreetpal Kaur {
1455e9685caSPreetpal Kaur fXScrollRange = fPadRect.Width() * (1 - rightRange);
1465e9685caSPreetpal Kaur fYScrollRange = fPadRect.Height() * (1 - bottomRange);
1475e9685caSPreetpal Kaur Invalidate();
1485e9685caSPreetpal Kaur }
1495e9685caSPreetpal Kaur
1505e9685caSPreetpal Kaur
1515e9685caSPreetpal Kaur void
GetPreferredSize(float * width,float * height)1525e9685caSPreetpal Kaur TouchpadView::GetPreferredSize(float* width, float* height)
1535e9685caSPreetpal Kaur {
1545e9685caSPreetpal Kaur if (width != NULL)
1555e9685caSPreetpal Kaur *width = fPrefRect.Width();
1565e9685caSPreetpal Kaur if (height != NULL)
1575e9685caSPreetpal Kaur *height = fPrefRect.Height();
1585e9685caSPreetpal Kaur }
1595e9685caSPreetpal Kaur
1605e9685caSPreetpal Kaur
1615e9685caSPreetpal Kaur void
MouseMoved(BPoint point,uint32 transit,const BMessage * message)1625e9685caSPreetpal Kaur TouchpadView::MouseMoved(BPoint point, uint32 transit, const BMessage* message)
1635e9685caSPreetpal Kaur {
1645e9685caSPreetpal Kaur if (fXTracking) {
1655e9685caSPreetpal Kaur if (point.x > fPadRect.right)
1665e9685caSPreetpal Kaur fXScrollRange = fPadRect.Width();
1675e9685caSPreetpal Kaur else if (point.x < fPadRect.left)
1685e9685caSPreetpal Kaur fXScrollRange = 0;
1695e9685caSPreetpal Kaur else
1705e9685caSPreetpal Kaur fXScrollRange = point.x - fPadRect.left;
1715e9685caSPreetpal Kaur
1725e9685caSPreetpal Kaur DrawSliders();
1735e9685caSPreetpal Kaur }
1745e9685caSPreetpal Kaur
1755e9685caSPreetpal Kaur if (fYTracking) {
1765e9685caSPreetpal Kaur if (point.y > fPadRect.bottom)
1775e9685caSPreetpal Kaur fYScrollRange = fPadRect.Height();
1785e9685caSPreetpal Kaur else if (point.y < fPadRect.top)
1795e9685caSPreetpal Kaur fYScrollRange = 0;
1805e9685caSPreetpal Kaur else
1815e9685caSPreetpal Kaur fYScrollRange = point.y - fPadRect.top;
1825e9685caSPreetpal Kaur
1835e9685caSPreetpal Kaur DrawSliders();
1845e9685caSPreetpal Kaur }
1855e9685caSPreetpal Kaur }
1865e9685caSPreetpal Kaur
1875e9685caSPreetpal Kaur
1885e9685caSPreetpal Kaur void
DrawSliders()1895e9685caSPreetpal Kaur TouchpadView::DrawSliders()
1905e9685caSPreetpal Kaur {
1915e9685caSPreetpal Kaur BView* view = fOffScreenView != NULL ? fOffScreenView : this;
1925e9685caSPreetpal Kaur
1935e9685caSPreetpal Kaur if (!LockLooper())
1945e9685caSPreetpal Kaur return;
1955e9685caSPreetpal Kaur
1965e9685caSPreetpal Kaur if (fOffScreenBitmap->Lock()) {
1975e9685caSPreetpal Kaur view->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
1985e9685caSPreetpal Kaur view->FillRect(Bounds());
1995e9685caSPreetpal Kaur view->SetHighColor(100, 100, 100);
2005e9685caSPreetpal Kaur view->FillRoundRect(fPadRect, 4, 4);
2015e9685caSPreetpal Kaur
2025e9685caSPreetpal Kaur int32 dragSize = 3; // half drag size
2035e9685caSPreetpal Kaur
2045e9685caSPreetpal Kaur // scroll areas
2055e9685caSPreetpal Kaur view->SetHighColor(145, 100, 100);
2065e9685caSPreetpal Kaur BRect rightRect(fPadRect.left + fXScrollRange, fPadRect.top,
2075e9685caSPreetpal Kaur fPadRect.right, fPadRect.bottom);
2085e9685caSPreetpal Kaur view->FillRoundRect(rightRect, 4, 4);
2095e9685caSPreetpal Kaur
2105e9685caSPreetpal Kaur BRect bottomRect(fPadRect.left, fPadRect.top + fYScrollRange,
2115e9685caSPreetpal Kaur fPadRect.right, fPadRect.bottom);
2125e9685caSPreetpal Kaur view->FillRoundRect(bottomRect, 4, 4);
2135e9685caSPreetpal Kaur
2145e9685caSPreetpal Kaur // Stroke Rect
2155e9685caSPreetpal Kaur view->SetHighColor(100, 100, 100);
2165e9685caSPreetpal Kaur view->SetPenSize(2);
2175e9685caSPreetpal Kaur view->StrokeRoundRect(fPadRect, 4, 4);
2185e9685caSPreetpal Kaur
2195e9685caSPreetpal Kaur // x scroll range line
2205e9685caSPreetpal Kaur view->SetHighColor(200, 0, 0);
2215e9685caSPreetpal Kaur view->StrokeLine(BPoint(fPadRect.left + fXScrollRange, fPadRect.top),
2225e9685caSPreetpal Kaur BPoint(fPadRect.left + fXScrollRange, fPadRect.bottom));
2235e9685caSPreetpal Kaur
2245e9685caSPreetpal Kaur fXScrollDragZone = BRect(fPadRect.left + fXScrollRange - dragSize,
2255e9685caSPreetpal Kaur fPadRect.top - dragSize, fPadRect.left + fXScrollRange + dragSize,
2265e9685caSPreetpal Kaur fPadRect.bottom + dragSize);
2275e9685caSPreetpal Kaur BRect xscrollDragZone1 = BRect(fPadRect.left + fXScrollRange - dragSize,
2285e9685caSPreetpal Kaur fPadRect.top - dragSize, fPadRect.left + fXScrollRange + dragSize,
2295e9685caSPreetpal Kaur fPadRect.top + dragSize);
2305e9685caSPreetpal Kaur view->FillRect(xscrollDragZone1);
2315e9685caSPreetpal Kaur BRect xscrollDragZone2 = BRect(fPadRect.left + fXScrollRange - dragSize,
2325e9685caSPreetpal Kaur fPadRect.bottom - dragSize,
2335e9685caSPreetpal Kaur fPadRect.left + fXScrollRange + dragSize,
2345e9685caSPreetpal Kaur fPadRect.bottom + dragSize);
2355e9685caSPreetpal Kaur view->FillRect(xscrollDragZone2);
2365e9685caSPreetpal Kaur
2375e9685caSPreetpal Kaur // y scroll range line
2385e9685caSPreetpal Kaur view->StrokeLine(BPoint(fPadRect.left, fPadRect.top + fYScrollRange),
2395e9685caSPreetpal Kaur BPoint(fPadRect.right, fPadRect.top + fYScrollRange));
2405e9685caSPreetpal Kaur
2415e9685caSPreetpal Kaur fYScrollDragZone = BRect(fPadRect.left - dragSize,
24202dabf4bSSaloni fPadRect.top + fYScrollRange - dragSize, fPadRect.right + dragSize,
2435e9685caSPreetpal Kaur fPadRect.top + fYScrollRange + dragSize);
2445e9685caSPreetpal Kaur BRect yscrollDragZone1 = BRect(fPadRect.left - dragSize,
2455e9685caSPreetpal Kaur fPadRect.top + fYScrollRange - dragSize, fPadRect.left + dragSize,
2465e9685caSPreetpal Kaur fPadRect.top + fYScrollRange + dragSize);
2475e9685caSPreetpal Kaur view->FillRect(yscrollDragZone1);
2485e9685caSPreetpal Kaur BRect yscrollDragZone2 = BRect(fPadRect.right - dragSize,
2495e9685caSPreetpal Kaur fPadRect.top + fYScrollRange - dragSize, fPadRect.right + dragSize,
2505e9685caSPreetpal Kaur fPadRect.top + fYScrollRange + dragSize);
2515e9685caSPreetpal Kaur view->FillRect(yscrollDragZone2);
2525e9685caSPreetpal Kaur
2535e9685caSPreetpal Kaur view->Sync();
2545e9685caSPreetpal Kaur fOffScreenBitmap->Unlock();
2555e9685caSPreetpal Kaur DrawBitmap(fOffScreenBitmap, B_ORIGIN);
2565e9685caSPreetpal Kaur }
2575e9685caSPreetpal Kaur
2585e9685caSPreetpal Kaur UnlockLooper();
2595e9685caSPreetpal Kaur }
2605e9685caSPreetpal Kaur
2615e9685caSPreetpal Kaur
2625e9685caSPreetpal Kaur // #pragma mark - TouchpadPrefView
2635e9685caSPreetpal Kaur
2645e9685caSPreetpal Kaur
TouchpadPrefView(BInputDevice * dev)2658272123eSPreetpal Kaur TouchpadPrefView::TouchpadPrefView(BInputDevice* dev)
2665e9685caSPreetpal Kaur :
26713b45a2eSPreetpal Kaur BGroupView(),
26813b45a2eSPreetpal Kaur fTouchpadPref(dev)
2695e9685caSPreetpal Kaur {
2705e9685caSPreetpal Kaur SetupView();
2715e9685caSPreetpal Kaur // set view values
2725e9685caSPreetpal Kaur SetValues(&fTouchpadPref.Settings());
2735e9685caSPreetpal Kaur }
2745e9685caSPreetpal Kaur
2755e9685caSPreetpal Kaur
~TouchpadPrefView()2765e9685caSPreetpal Kaur TouchpadPrefView::~TouchpadPrefView()
2775e9685caSPreetpal Kaur {
2785e9685caSPreetpal Kaur }
2795e9685caSPreetpal Kaur
2805e9685caSPreetpal Kaur
2815e9685caSPreetpal Kaur void
MessageReceived(BMessage * message)2825e9685caSPreetpal Kaur TouchpadPrefView::MessageReceived(BMessage* message)
2835e9685caSPreetpal Kaur {
2845e9685caSPreetpal Kaur touchpad_settings& settings = fTouchpadPref.Settings();
2855e9685caSPreetpal Kaur
2865e9685caSPreetpal Kaur switch (message->what) {
2875e9685caSPreetpal Kaur case SCROLL_AREA_CHANGED:
2885e9685caSPreetpal Kaur settings.scroll_rightrange = fTouchpadView->GetRightScrollRatio();
2895e9685caSPreetpal Kaur settings.scroll_bottomrange = fTouchpadView->GetBottomScrollRatio();
2905e9685caSPreetpal Kaur fTouchpadPref.UpdateSettings();
2915e9685caSPreetpal Kaur break;
2925e9685caSPreetpal Kaur
2935e9685caSPreetpal Kaur case SCROLL_CONTROL_CHANGED:
2945e9685caSPreetpal Kaur settings.scroll_twofinger = fTwoFingerBox->Value() == B_CONTROL_ON;
2955e9685caSPreetpal Kaur settings.scroll_twofinger_horizontal
2965e9685caSPreetpal Kaur = fTwoFingerHorizontalBox->Value() == B_CONTROL_ON;
2975e9685caSPreetpal Kaur settings.scroll_acceleration = fScrollAccelSlider->Value();
2985e9685caSPreetpal Kaur settings.scroll_xstepsize = (20 - fScrollStepXSlider->Value()) * 3;
2995e9685caSPreetpal Kaur settings.scroll_ystepsize = (20 - fScrollStepYSlider->Value()) * 3;
3005e9685caSPreetpal Kaur fTwoFingerHorizontalBox->SetEnabled(settings.scroll_twofinger);
3015e9685caSPreetpal Kaur fTouchpadPref.UpdateSettings();
3025e9685caSPreetpal Kaur break;
3035e9685caSPreetpal Kaur
3045e9685caSPreetpal Kaur case TAP_CONTROL_CHANGED:
3055e9685caSPreetpal Kaur settings.tapgesture_sensibility = fTapSlider->Value();
3065e9685caSPreetpal Kaur fTouchpadPref.UpdateSettings();
3075e9685caSPreetpal Kaur break;
3085e9685caSPreetpal Kaur
30913b45a2eSPreetpal Kaur case PADBLOCK_TIME_CHANGED:
31013b45a2eSPreetpal Kaur settings.padblocker_threshold = fPadBlockerSlider->Value();
31113b45a2eSPreetpal Kaur // The maximum value means "disabled", but in the settings file that
31213b45a2eSPreetpal Kaur // must be stored as 0
31313b45a2eSPreetpal Kaur if (settings.padblocker_threshold == 1000)
31413b45a2eSPreetpal Kaur settings.padblocker_threshold = 0;
31513b45a2eSPreetpal Kaur fRevertButton->SetEnabled(true);
31613b45a2eSPreetpal Kaur fTouchpadPref.UpdateSettings();
31713b45a2eSPreetpal Kaur break;
31813b45a2eSPreetpal Kaur
3195e9685caSPreetpal Kaur case DEFAULT_SETTINGS:
3205e9685caSPreetpal Kaur fTouchpadPref.Defaults();
3215e9685caSPreetpal Kaur fRevertButton->SetEnabled(true);
3225e9685caSPreetpal Kaur fTouchpadPref.UpdateSettings();
3235e9685caSPreetpal Kaur SetValues(&settings);
3245e9685caSPreetpal Kaur break;
3255e9685caSPreetpal Kaur
3265e9685caSPreetpal Kaur case REVERT_SETTINGS:
3275e9685caSPreetpal Kaur fTouchpadPref.Revert();
3285e9685caSPreetpal Kaur fTouchpadPref.UpdateSettings();
3295e9685caSPreetpal Kaur fRevertButton->SetEnabled(false);
3305e9685caSPreetpal Kaur SetValues(&settings);
3315e9685caSPreetpal Kaur break;
3325e9685caSPreetpal Kaur
3335e9685caSPreetpal Kaur default:
3345e9685caSPreetpal Kaur BView::MessageReceived(message);
3355e9685caSPreetpal Kaur }
3365e9685caSPreetpal Kaur }
3375e9685caSPreetpal Kaur
3385e9685caSPreetpal Kaur
3395e9685caSPreetpal Kaur void
AttachedToWindow()3405e9685caSPreetpal Kaur TouchpadPrefView::AttachedToWindow()
3415e9685caSPreetpal Kaur {
3425e9685caSPreetpal Kaur fTouchpadView->SetTarget(this);
3435e9685caSPreetpal Kaur fTwoFingerBox->SetTarget(this);
3445e9685caSPreetpal Kaur fTwoFingerHorizontalBox->SetTarget(this);
3455e9685caSPreetpal Kaur fScrollStepXSlider->SetTarget(this);
3465e9685caSPreetpal Kaur fScrollStepYSlider->SetTarget(this);
3475e9685caSPreetpal Kaur fScrollAccelSlider->SetTarget(this);
34813b45a2eSPreetpal Kaur fPadBlockerSlider->SetTarget(this);
3495e9685caSPreetpal Kaur fTapSlider->SetTarget(this);
3505e9685caSPreetpal Kaur fDefaultButton->SetTarget(this);
3515e9685caSPreetpal Kaur fRevertButton->SetTarget(this);
3525e9685caSPreetpal Kaur BSize size = PreferredSize();
3535e9685caSPreetpal Kaur Window()->ResizeTo(size.width, size.height);
3545e9685caSPreetpal Kaur
3555e9685caSPreetpal Kaur BPoint position = fTouchpadPref.WindowPosition();
3565e9685caSPreetpal Kaur // center window on screen if it had a bad position
3575e9685caSPreetpal Kaur if (position.x < 0 && position.y < 0)
3585e9685caSPreetpal Kaur Window()->CenterOnScreen();
3595e9685caSPreetpal Kaur else
3605e9685caSPreetpal Kaur Window()->MoveTo(position);
3615e9685caSPreetpal Kaur }
3625e9685caSPreetpal Kaur
3635e9685caSPreetpal Kaur
3645e9685caSPreetpal Kaur void
DetachedFromWindow()3655e9685caSPreetpal Kaur TouchpadPrefView::DetachedFromWindow()
3665e9685caSPreetpal Kaur {
3675e9685caSPreetpal Kaur fTouchpadPref.SetWindowPosition(Window()->Frame().LeftTop());
3685e9685caSPreetpal Kaur }
3695e9685caSPreetpal Kaur
3705e9685caSPreetpal Kaur
3715e9685caSPreetpal Kaur void
SetupView()3725e9685caSPreetpal Kaur TouchpadPrefView::SetupView()
3735e9685caSPreetpal Kaur {
3745e9685caSPreetpal Kaur SetLayout(new BGroupLayout(B_VERTICAL));
3755e9685caSPreetpal Kaur BBox* scrollBox = new BBox("Touchpad");
3765e9685caSPreetpal Kaur scrollBox->SetLabel(B_TRANSLATE("Scrolling"));
3775e9685caSPreetpal Kaur
3788272123eSPreetpal Kaur
3795e9685caSPreetpal Kaur fTouchpadView = new TouchpadView(BRect(0, 0, 130, 120));
3805e9685caSPreetpal Kaur fTouchpadView->SetExplicitMaxSize(BSize(130, 120));
3815e9685caSPreetpal Kaur
3825e9685caSPreetpal Kaur // Create the "Mouse Speed" slider...
3835e9685caSPreetpal Kaur fScrollAccelSlider = new BSlider("scroll_accel",
3845e9685caSPreetpal Kaur B_TRANSLATE("Acceleration"),
3855e9685caSPreetpal Kaur new BMessage(SCROLL_CONTROL_CHANGED), 0, 20, B_HORIZONTAL);
3865e9685caSPreetpal Kaur fScrollAccelSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
3875e9685caSPreetpal Kaur fScrollAccelSlider->SetHashMarkCount(7);
38802dabf4bSSaloni fScrollAccelSlider->SetLimitLabels(
38902dabf4bSSaloni B_TRANSLATE("Slow"), B_TRANSLATE("Fast"));
3905e9685caSPreetpal Kaur fScrollAccelSlider->SetExplicitMinSize(BSize(150, B_SIZE_UNSET));
3915e9685caSPreetpal Kaur
39202dabf4bSSaloni fScrollStepXSlider = new BSlider("scroll_stepX", B_TRANSLATE("Horizontal"),
39302dabf4bSSaloni new BMessage(SCROLL_CONTROL_CHANGED), 0, 20, B_HORIZONTAL);
3945e9685caSPreetpal Kaur fScrollStepXSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
3955e9685caSPreetpal Kaur fScrollStepXSlider->SetHashMarkCount(7);
39602dabf4bSSaloni fScrollStepXSlider->SetLimitLabels(
39702dabf4bSSaloni B_TRANSLATE("Slow"), B_TRANSLATE("Fast"));
3985e9685caSPreetpal Kaur
39902dabf4bSSaloni fScrollStepYSlider = new BSlider("scroll_stepY", B_TRANSLATE("Vertical"),
4005e9685caSPreetpal Kaur new BMessage(SCROLL_CONTROL_CHANGED), 0, 20, B_HORIZONTAL);
4015e9685caSPreetpal Kaur fScrollStepYSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
4025e9685caSPreetpal Kaur fScrollStepYSlider->SetHashMarkCount(7);
40302dabf4bSSaloni fScrollStepYSlider->SetLimitLabels(
40402dabf4bSSaloni B_TRANSLATE("Slow"), B_TRANSLATE("Fast"));
4055e9685caSPreetpal Kaur
40602dabf4bSSaloni fPadBlockerSlider
407*1de4fd17SHumdinger = new BSlider("padblocker", B_TRANSLATE("Keyboard lock delay"),
40813b45a2eSPreetpal Kaur new BMessage(PADBLOCK_TIME_CHANGED), 5, 1000, B_HORIZONTAL);
40913b45a2eSPreetpal Kaur fPadBlockerSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
41013b45a2eSPreetpal Kaur fPadBlockerSlider->SetHashMarkCount(10);
41102dabf4bSSaloni fPadBlockerSlider->SetLimitLabels(
41202dabf4bSSaloni B_TRANSLATE("Quick"), B_TRANSLATE("Never"));
41313b45a2eSPreetpal Kaur
4145e9685caSPreetpal Kaur fTwoFingerBox = new BCheckBox(B_TRANSLATE("Two finger scrolling"),
4155e9685caSPreetpal Kaur new BMessage(SCROLL_CONTROL_CHANGED));
41602dabf4bSSaloni fTwoFingerHorizontalBox = new BCheckBox(B_TRANSLATE("Horizontal scrolling"),
4175e9685caSPreetpal Kaur new BMessage(SCROLL_CONTROL_CHANGED));
4185e9685caSPreetpal Kaur
4195e9685caSPreetpal Kaur float spacing = be_control_look->DefaultItemSpacing();
4205e9685caSPreetpal Kaur
4215e9685caSPreetpal Kaur BView* scrollPrefLeftLayout
4225e9685caSPreetpal Kaur = BLayoutBuilder::Group<>(B_VERTICAL, 0)
4235e9685caSPreetpal Kaur .Add(fTouchpadView)
4245e9685caSPreetpal Kaur .AddStrut(spacing)
4255e9685caSPreetpal Kaur .Add(fTwoFingerBox)
4265e9685caSPreetpal Kaur .AddGroup(B_HORIZONTAL, 0)
4275e9685caSPreetpal Kaur .AddStrut(spacing * 2)
4285e9685caSPreetpal Kaur .Add(fTwoFingerHorizontalBox)
4295e9685caSPreetpal Kaur .End()
4305e9685caSPreetpal Kaur .AddGlue()
4315e9685caSPreetpal Kaur .View();
4325e9685caSPreetpal Kaur
4335e9685caSPreetpal Kaur BGroupView* scrollPrefRightLayout = new BGroupView(B_VERTICAL);
4345e9685caSPreetpal Kaur scrollPrefRightLayout->AddChild(fScrollAccelSlider);
4355e9685caSPreetpal Kaur scrollPrefRightLayout->AddChild(fScrollStepXSlider);
4365e9685caSPreetpal Kaur scrollPrefRightLayout->AddChild(fScrollStepYSlider);
4375e9685caSPreetpal Kaur
4385e9685caSPreetpal Kaur BGroupLayout* scrollPrefLayout = new BGroupLayout(B_HORIZONTAL);
4395e9685caSPreetpal Kaur scrollPrefLayout->SetSpacing(spacing);
44002dabf4bSSaloni scrollPrefLayout->SetInsets(
44102dabf4bSSaloni spacing, scrollBox->TopBorderOffset() * 2 + spacing, spacing, spacing);
4425e9685caSPreetpal Kaur scrollBox->SetLayout(scrollPrefLayout);
4435e9685caSPreetpal Kaur
4445e9685caSPreetpal Kaur scrollPrefLayout->AddView(scrollPrefLeftLayout);
44502dabf4bSSaloni scrollPrefLayout->AddItem(
44602dabf4bSSaloni BSpaceLayoutItem::CreateVerticalStrut(spacing * 1.5));
4475e9685caSPreetpal Kaur scrollPrefLayout->AddView(scrollPrefRightLayout);
4485e9685caSPreetpal Kaur
44913b45a2eSPreetpal Kaur fTapSlider = new BSlider("tap_sens", B_TRANSLATE("Tapping sensitivity"),
4505e9685caSPreetpal Kaur new BMessage(TAP_CONTROL_CHANGED), 0, spacing * 2, B_HORIZONTAL);
4515e9685caSPreetpal Kaur fTapSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
4525e9685caSPreetpal Kaur fTapSlider->SetHashMarkCount(7);
4535e9685caSPreetpal Kaur fTapSlider->SetLimitLabels(B_TRANSLATE("Off"), B_TRANSLATE("High"));
4545e9685caSPreetpal Kaur
45502dabf4bSSaloni fDefaultButton
45602dabf4bSSaloni = new BButton(B_TRANSLATE("Defaults"), new BMessage(DEFAULT_SETTINGS));
4575e9685caSPreetpal Kaur
45802dabf4bSSaloni fRevertButton
45902dabf4bSSaloni = new BButton(B_TRANSLATE("Revert"), new BMessage(REVERT_SETTINGS));
4605e9685caSPreetpal Kaur fRevertButton->SetEnabled(false);
4615e9685caSPreetpal Kaur
4625e9685caSPreetpal Kaur
4635e9685caSPreetpal Kaur BLayoutBuilder::Group<>(this, B_VERTICAL)
4645e9685caSPreetpal Kaur .SetInsets(B_USE_WINDOW_SPACING)
4655e9685caSPreetpal Kaur .Add(scrollBox)
46613b45a2eSPreetpal Kaur .Add(fTapSlider)
46713b45a2eSPreetpal Kaur .Add(fPadBlockerSlider)
4685e9685caSPreetpal Kaur .Add(new BSeparatorView(B_HORIZONTAL))
4695e9685caSPreetpal Kaur .AddGroup(B_HORIZONTAL)
4705e9685caSPreetpal Kaur .Add(fDefaultButton)
4715e9685caSPreetpal Kaur .Add(fRevertButton)
4725e9685caSPreetpal Kaur .AddGlue()
4735e9685caSPreetpal Kaur .End()
4745e9685caSPreetpal Kaur .End();
4755e9685caSPreetpal Kaur }
4765e9685caSPreetpal Kaur
4775e9685caSPreetpal Kaur
4785e9685caSPreetpal Kaur void
SetValues(touchpad_settings * settings)4795e9685caSPreetpal Kaur TouchpadPrefView::SetValues(touchpad_settings* settings)
4805e9685caSPreetpal Kaur {
48102dabf4bSSaloni fTouchpadView->SetValues(
48202dabf4bSSaloni settings->scroll_rightrange, settings->scroll_bottomrange);
48302dabf4bSSaloni fTwoFingerBox->SetValue(
48402dabf4bSSaloni settings->scroll_twofinger ? B_CONTROL_ON : B_CONTROL_OFF);
48502dabf4bSSaloni fTwoFingerHorizontalBox->SetValue(
48602dabf4bSSaloni settings->scroll_twofinger_horizontal ? B_CONTROL_ON : B_CONTROL_OFF);
4875e9685caSPreetpal Kaur fTwoFingerHorizontalBox->SetEnabled(settings->scroll_twofinger);
4885e9685caSPreetpal Kaur fScrollStepXSlider->SetValue(20 - settings->scroll_xstepsize / 2);
4895e9685caSPreetpal Kaur fScrollStepYSlider->SetValue(20 - settings->scroll_ystepsize / 2);
4905e9685caSPreetpal Kaur fScrollAccelSlider->SetValue(settings->scroll_acceleration);
4915e9685caSPreetpal Kaur fTapSlider->SetValue(settings->tapgesture_sensibility);
49213b45a2eSPreetpal Kaur fPadBlockerSlider->SetValue(settings->padblocker_threshold);
4935e9685caSPreetpal Kaur }
494