FreeRDP
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 
11 package com.freerdp.freerdpcore.utils;
12 
13 import android.content.Context;
14 
15 import com.freerdp.freerdpcore.presentation.ApplicationSettingsActivity;
16 
17 public class Mouse
18 {
19 
20  private final static int PTRFLAGS_LBUTTON = 0x1000;
21  private final static int PTRFLAGS_RBUTTON = 0x2000;
22 
23  private final static int PTRFLAGS_DOWN = 0x8000;
24  private final static int PTRFLAGS_MOVE = 0x0800;
25 
26  private final static int PTRFLAGS_WHEEL = 0x0200;
27  private final static int PTRFLAGS_WHEEL_NEGATIVE = 0x0100;
28 
29  public static int getLeftButtonEvent(Context context, boolean down)
30  {
31  if (ApplicationSettingsActivity.getSwapMouseButtons(context))
32  return (PTRFLAGS_RBUTTON | (down ? PTRFLAGS_DOWN : 0));
33  else
34  return (PTRFLAGS_LBUTTON | (down ? PTRFLAGS_DOWN : 0));
35  }
36 
37  public static int getRightButtonEvent(Context context, boolean down)
38  {
39  if (ApplicationSettingsActivity.getSwapMouseButtons(context))
40  return (PTRFLAGS_LBUTTON | (down ? PTRFLAGS_DOWN : 0));
41  else
42  return (PTRFLAGS_RBUTTON | (down ? PTRFLAGS_DOWN : 0));
43  }
44 
45  public static int getMoveEvent()
46  {
47  return PTRFLAGS_MOVE;
48  }
49 
50  public static int getScrollEvent(Context context, boolean down)
51  {
52  int flags = PTRFLAGS_WHEEL;
53 
54  // invert scrolling?
55  if (ApplicationSettingsActivity.getInvertScrolling(context))
56  down = !down;
57 
58  if (down)
59  flags |= (PTRFLAGS_WHEEL_NEGATIVE | 0x0088);
60  else
61  flags |= 0x0078;
62  return flags;
63  }
64 }