FreeRDP
Loading...
Searching...
No Matches
Mouse.java
1/*
2 Android Mouse Input Mapping
3
4 Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
5
6 This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
7 If a copy of the MPL was not distributed with this file, You can obtain one at
8 http://mozilla.org/MPL/2.0/.
9*/
10
11package com.freerdp.freerdpcore.utils;
12
13import android.content.Context;
14
15import com.freerdp.freerdpcore.presentation.ApplicationSettingsActivity;
16
17public class Mouse
18{
19
20 private final static int PTRFLAGS_LBUTTON = 0x1000;
21 private final static int PTRFLAGS_RBUTTON = 0x2000;
22 private final static int PTRFLAGS_MBUTTON = 0x4000;
23
24 private final static int PTRFLAGS_DOWN = 0x8000;
25 private final static int PTRFLAGS_MOVE = 0x0800;
26
27 private final static int PTRFLAGS_WHEEL = 0x0200;
28 private final static int PTRFLAGS_WHEEL_NEGATIVE = 0x0100;
29 private final static int PTRFLAGS_HWHEEL = 0x0400;
30 public final static int WHEEL_DELTA = 0x0078; // 120 rotation units = one notch
31
32 public static int getLeftButtonEvent(Context context, boolean down)
33 {
34 if (ApplicationSettingsActivity.getSwapMouseButtons(context))
35 return (PTRFLAGS_RBUTTON | (down ? PTRFLAGS_DOWN : 0));
36 else
37 return (PTRFLAGS_LBUTTON | (down ? PTRFLAGS_DOWN : 0));
38 }
39
40 public static int getRightButtonEvent(Context context, boolean down)
41 {
42 if (ApplicationSettingsActivity.getSwapMouseButtons(context))
43 return (PTRFLAGS_LBUTTON | (down ? PTRFLAGS_DOWN : 0));
44 else
45 return (PTRFLAGS_RBUTTON | (down ? PTRFLAGS_DOWN : 0));
46 }
47
48 public static int getMiddleButtonEvent(boolean down)
49 {
50 return (PTRFLAGS_MBUTTON | (down ? PTRFLAGS_DOWN : 0));
51 }
52
53 public static int getMoveEvent()
54 {
55 return PTRFLAGS_MOVE;
56 }
57
58 public static int getScrollEvent(Context context, boolean down)
59 {
60 return getScrollEvent(context, down ? -WHEEL_DELTA : WHEEL_DELTA);
61 }
62
63 // amount: signed wheel rotation units (positive = scroll up, negative = scroll down)
64 public static int getScrollEvent(Context context, int amount)
65 {
66 if (ApplicationSettingsActivity.getInvertScrolling(context))
67 amount = -amount;
68 return wheelEvent(PTRFLAGS_WHEEL, amount);
69 }
70
71 public static int getHScrollEvent(Context context, boolean right)
72 {
73 return getHScrollEvent(context, right ? WHEEL_DELTA : -WHEEL_DELTA);
74 }
75
76 public static int getHScrollEvent(Context context, int amount)
77 {
78 if (ApplicationSettingsActivity.getInvertScrolling(context))
79 amount = -amount;
80 return wheelEvent(PTRFLAGS_HWHEEL, amount);
81 }
82
83 private static int wheelEvent(int wheelFlag, int amount)
84 {
85 int flags = wheelFlag;
86 if (amount < 0)
87 flags |= PTRFLAGS_WHEEL_NEGATIVE;
88 return flags | (amount & 0xFF);
89 }
90}